Where do I get response in Citrus payment integration in Android - android

I have integrated citrus payment gateway in an android app..I am not getting where do I get the response..if the the transaction is successfull or failed.
Here is my code..the problem is whenever the transaction is completed or succesfull the citrus pay library display a screen with appropriate message and when I click back then I get the result in onActivityResult...I want the result immediately after the transaction is completed..Thanks
I am following steps from here : http://www.citruspay.com/DevelopersGuide/android/plugandplay.html
if (res.equalsIgnoreCase("true")) {
setupCitrusConfigs();
CitrusFlowManager.startShoppingFlow(CheckOut.this,
User_Email, Txt_Phone.getText().toString(), String.valueOf(Amt_Payable));
}
private void setupCitrusConfigs() {
CitrusFlowManager.initCitrusConfig("kkkkkkk-signup",
"dfdffgfdgfdgffdgdfgdfgdfgdfgfdg", "fgfgfdgfdg-signin",
"fgfdgdfgfdgfgfdgfgdfffd", getResources().getColor(R.color.white),
CheckOut.this, Environment.SANDBOX, "vvvvvvvvd", sandboxBillGeneratorURL,
returnUrlLoadMoney);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
Log.d("CheckOut","request code " + requestCode + " resultcode " + resultCode);
if(requestCode == Constants.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) {
// You will get data here if transaction flow is started through pay options other than wallet
TransactionResponse transactionResponse = data.getParcelableExtra(Constants
.INTENT_EXTRA_TRANSACTION_RESPONSE);
// You will get data here if transaction flow is started through wallet
ResultModel resultModel = data.getParcelableExtra(ResultFragment.ARG_RESULT);
// Check which object is non-null
if(transactionResponse != null && transactionResponse.getJsonResponse() != null) {
try {
JSONObject json = new JSONObject(transactionResponse.getJsonResponse());
String Status = json.getString("TxStatus");
if(Status.equalsIgnoreCase("SUCCESS")){
db.EmptyCart();
Intent i = new Intent(CheckOut.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Log.e("Trans", "Transaction Successfull " + Status);
}else {
Log.e("Trans","Transaction Failed "+Status);
}
} catch (JSONException e1) {
e1.printStackTrace();
}
// Decide what to do with this data
Log.d(TAG, "transaction response" + transactionResponse.getJsonResponse());
} else if(resultModel != null && resultModel.getTransactionResponse() != null){
// Decide what to do with this data
try {
JSONObject json = new JSONObject(resultModel.getTransactionResponse().getJsonResponse());
String Status = json.getString("TxStatus");
if(Status.equalsIgnoreCase("SUCCESS")){
db.EmptyCart();
Intent i = new Intent(CheckOut.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Log.e("Trans", "Transaction Successfull " + Status);
}else {
Log.e("Trans","Transaction Failed "+Status);
}
} catch (JSONException e1) {
e1.printStackTrace();
}
} else {
Log.d(TAG, "Both objects are null!");
}
}
}

Pay using Debit Card
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
DebitCardOption debitCardOption = new DebitCardOption("Card Holder Name", "4111111111111111", "123", Month.getMonth("12"), Year.getYear("18"));
Amount amount = new Amount("5");
// Init PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, debitCardOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});
Pay using Credit Card
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
CreditCardOption creditCardOption = new CreditCardOption("Card Holder Name", "4111111111111111", "123", Month.getMonth("12"), Year.getYear("18"));
Amount amount = new Amount("5");
// Init PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, creditCardOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});
Pay using Net Banking Option
CitrusClient citrusClient = CitrusClient.getInstance(context); // Activity Context
// No need to call init on CitrusClient if already done.
NetbankingOption netbankingOption = new NetbankingOption("ICICI Bank","CID001");
// Init Net Banking PaymentType
PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(amount, BILL_URL, netbankingOption, new CitrusUser("developercitrus#gmail.com","9876543210"));
citrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() {
#Override
public void success(TransactionResponse transactionResponse) { }
#Override
public void error(CitrusError error) { }
});

Related

How to upload multiple image from gallery in android?

I want to upload multiple image from gallery to server but getting only one image not multiple.
following is the code for it
FirstFragment.java
private void orderRequest() {
final OrderRequestModel model = basicInfiFragment.getData();
model.setSs(steelFragment.getProductInfo());
model.setAluminium(aluminiumFragment.getProductInfo());
SimpleMultiPartRequest orderRequest = new SimpleMultiPartRequest(Request.Method.POST,
Constance.baseURL + Constance.orderURL, new com.android.volley.Response.Listener<String>() {
#Override
public void onResponse(String response) {
DialogUtil.hideProgrss();
ProductModel mResponse = new Gson().fromJson(response, ProductModel.class);
if (mResponse.getStatus().equalsIgnoreCase(Constance.success)) {
Toast.makeText(getContext(), mResponse.getMessage(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), MainActivity.class);
getContext().startActivity(intent);
getActivity().finish();
} else {
SnackUtil.mackText(mBinding.layoutRoot, mResponse.getMessage(), true);
}
L.e(response);
}
}, new com.android.volley.Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
L.e(error.toString());
DialogUtil.hideProgrss();
DialogUtil.someThingWentWrong(getContext());
}
});
Map<String, String> headerMap = new HashMap<>();
headerMap.put("token", SP.getString(SP.TOKEN));
for (ImageDetails imageDetails : model.getImageList()) {
orderRequest.addStringParam("json", new Gson().toJson(model));
orderRequest.addFile("siteImages",imageDetails.getPath());
orderRequest.addMultipartParam(imageDetails.getName(), getActivity().
getContentResolver().getType(imageDetails.getURI()), imageDetails.getPath());
orderRequest.setHeaders(headerMap);
}
DialogUtil.showProgress(getContext());
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(orderRequest);
}
i tried a lot but it is uploading only one image please help me out of these getting stuck since last three days..
SecondFragment.java
public OrderRequestModel getData() {
OrderRequestModel model = new OrderRequestModel();
try {
model.setImageList(imageDetails);
} catch (Exception e) {
SnackUtil.mackText(mBinding.layoutRoot, getString(R.string.some_things_went_wrong), true);
L.e("date parse Error : " + e.getMessage());
}
return model;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 122:
if (data != null) {
if (resultCode == Activity.RESULT_OK) {
Bitmap image = (Bitmap) data.getExtras().get("data");
String strData = String.valueOf(data.getData());
L.e("Camera : " + strData);
if (image != null) {
ImageDetails imgDetails = new ImageDetails();
imgDetails.setName(MyUtil.getFilename(Uri.parse(strData), getActivity()));
imgDetails.setBitmap(image);
imgDetails.setName("image" + new Random().nextInt(1000));
imageDetails.add(imgDetails);
}
}
adapterImages.notifyDataSetChanged();
}
break;
case 144:
if (data != null) {
if (resultCode == Activity.RESULT_OK) {
String strData = data.getDataString();
Uri[] resultFileChooser = null;
try {
if (data.getClipData() == null) {
L.e("data Clicp is Null");
}
resultFileChooser = new Uri[data.getClipData().getItemCount()];
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
ImageDetails details = new ImageDetails();
details.setPath(getPath(data.getClipData().getItemAt(i).getUri()));
details.setURI(data.getClipData().getItemAt(i).getUri());
details.setName(MyUtil.getFilename(data.getClipData().getItemAt(i).getUri(), getActivity()));
imageDetails.add(details);
L.e("Uri : " + details.getPath());
}
} catch (NullPointerException e) {
if (strData != null) {
resultFileChooser = new Uri[]{Uri.parse(strData)};
ImageDetails imgDetails = new ImageDetails();
imgDetails.setName(MyUtil.getFilename(Uri.parse(strData), getActivity()));
imgDetails.setPath(getPath(Uri.parse(strData)));
imgDetails.setURI(Uri.parse(strData));
imageDetails.add(imgDetails);
L.e("Uri : " + imgDetails.getPath());
}
}
}
adapterImages.notifyDataSetChanged();
}
break;
}
}
this is the code which i am trying i paste my onActivity code and multipart code also.
you may want to enable multi-selection while selection and then syncing with the server.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);
you will receive multiple Uri in your onActivity from there use to get file objects and then sync with the server.

Android paypal account: How can i check if the user is already a member

I have an app where users can subscribe to membership by paying with their Paypal account. How can I get back a confirmation stating if the user has paid for the subscription or not? Please help me with some code or edit my code. How can i know if a user has already subscribed to membership or has not subscribed? Here is my code.
public class MainActivity extends Activity {
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID = "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
//Intent intent = new Intent(this, PayPalService.class);
//intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
//startService(intent);
findViewById(R.id.order).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
thingToBuy = new PayPalPayment(new BigDecimal("1"), "USD",
"HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(MainActivity.this,
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
});
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(MainActivity.this,
PayPalFuturePaymentActivity.class);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println("Responseeee" + confirm);
Log.i("paymentExample", confirm.toJSONObject().toString());
System.out.println(confirm.toJSONObject().toString(4));
System.out.println(confirm.getPayment().toJSONObject()
.toString(4));
Toast.makeText(getApplicationContext(), "Order placed"+confirm.toString(),
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.e("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.e("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.e("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.e("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration
.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: "
+ correlationId);
// TODO: Send correlationId and transaction details to your server for
// processing with
// PayPal...
Toast.makeText(getApplicationContext(),
"App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
#Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
}

Android payapal integration

this is my first question on stackoverflow.hope i can find my solutuon .i am integrating paypal in android.my device is showing "payment of this marchent are not allowed(invalid client id).here is my code
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;
// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID ="my client id";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Rajeev Lochan Sharma")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_afcl);
final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startService(intent);
ButterKnife.inject(this);
_request3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// signup();
new Test().execute(_names.getText().toString(), _placeofbirth.getText().toString(), _timeofbirth.getText().toString()
);
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"quote", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(AfcRequest1Activity.this,
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
});
}
public void onBackPressed() {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit")
.setMessage("Are you sure you want to exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("No", null).show();
}
private class Test extends AsyncTask {
protected void onPreExecute() {
super.onPreExecute();
//here you can some progress dialog or some view
}
#Override
protected String doInBackground(String... Params) {
String res = "";
try {
byte[] result = null;
String str = "";
HttpClient client;
HttpPost post;
ArrayList<NameValuePair> nameValuePair;
HashMap<String, String> mData;
Iterator<String> it;
HttpResponse response;
StatusLine statusLine;
//here is url api call url
post = new HttpPost("http://astro360horoscope.com/backend/api/form_amc_afc.php");
nameValuePair = new ArrayList<NameValuePair>();
mData = new HashMap<String, String>();
mData.put("username", Params[0]);
mData.put("placeofbirth", Params[1]);
mData.put("timeofbirth", Params[2]);
//for now nothing is there
it = mData.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
nameValuePair.add(new BasicNameValuePair(key, mData.get(key)));
}
post.setEntity(new UrlEncodedFormEntity(nameValuePair, "utf-8"));
client = new DefaultHttpClient();
response = client.execute(post);
statusLine = response.getStatusLine();
result = EntityUtils.toByteArray(response.getEntity());
str = new String(result, "utf-8");
if (statusLine.getStatusCode() == HttpURLConnection.HTTP_OK) {
//here we get the response if all is correct
res = str;
} else {
res = str;
return res;
}
} catch (Exception e1) {
res = "error:" + e1.getMessage().toString();
e1.printStackTrace();
}
return res;
}
protected void onPostExecute(String response) {
super.onPostExecute(response);
}
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(AfcRequest1Activity.this,
PayPalFuturePaymentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toJSONObject().toString(4));
System.out.println(confirm.getPayment().toJSONObject()
.toString(4));
Toast.makeText(getApplicationContext(), "Order placed",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration
.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: "
+ correlationId);
// TODO: Send correlationId and transaction details to your server for
// processing with
// PayPal...
Toast.makeText(getApplicationContext(),
"App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
#Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}

Android Fabric Twitter share listener

I use Fabric SDK to send tweets from my application.
I build a share dialog and send tweet from activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwitterAuthConfig authConfig = new TwitterAuthConfig(CONSUMER_KEY, CONSUMER_SECRET);
Fabric.with(this, new TwitterCore(authConfig), new TweetComposer());
Bundle bundle = getIntent().getExtras().getBundle(SHARE_DATA);
String description = bundle.getString(SHARE_DESCRIPTION);
String title = bundle.getString(SHARE_TITLE);
String picture = bundle.getString(SHARE_PICTURE_LINK);
String link = bundle.getString(SHARE_LINK);
TweetComposer.Builder builder = null;
try {
InputStream in = new java.net.URL(picture).openStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
Uri yourUri = getImageUri(this,bitmap);
builder = new TweetComposer.Builder(this)
.text(title + "\n" + description)
.url(new URL(link))
.image(yourUri);
//??? IS THERE ANY LISTENER ???
builder.show();
} catch (IOException e1) {
e1.printStackTrace();
}
}
I want to know status of sharing, like an success or not, but i can't find any listener for this action. I missed something?
Instead of use builder.show(), you should use builder.createIntent() :
Intent intent = new TweetComposer.Builder(getActivity())
.text("TEXT")
.url("URL")
.createIntent();
startActivityForResult(intent, TWEET_COMPOSER_REQUEST_CODE);
To get the result feedback in onActivityResult() :
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == TWEET_COMPOSER_REQUEST_CODE) {
if(resultCode == Activity.RESULT_OK) {
onTwitterSuccess();
} else if(resultCode == Activity.RESULT_CANCELED) {
onTwitterCancel();
}
}
}
use below method to twitt via rest service and pass media id as null.i m successfully posting tweets from my app
public void postToTwitter(ArrayList<String>mediaIds) {
String message;
if(Validator.isNotNull(preferences.getFbShareMessage())){
message=preferences.getFbShareMessage()+" "+com.aimdek.healthwel.network.Request.HOST_URL + "/user-history/" + userHistory.getUserId() + "/" + userHistory.getId();
}
else {
message = getString(R.string.google_status, HWUtil.getFullName(preferences.getUserInfo().getFirstName(), preferences.getUserInfo().getLastName()), userHistory.getSportName(), HWUtil.secondToTime(userHistory.getDuration()))+" "+com.aimdek.healthwel.network.Request.HOST_URL + "/user-history/" + userHistory.getUserId() + "/" + userHistory.getId();
}
String mediaId;
if (Validator.isNotNull(mediaIds) && mediaIds.size() > 0) {
mediaId="";
for (int i = 0; i < mediaIds.size(); i++) {
if (i == 0) {
mediaId = mediaIds.get(i);
} else {
mediaId += "," + mediaIds.get(i);
}
}
}
else {
mediaId=null;
}
StatusesService statusesService = twitterApiClient.getStatusesService();
statusesService.update(message, null, null, null, null, null, null, null, mediaId, new Callback<Tweet>() {
#Override
public void success(Result<Tweet> result) {
dismissProgressDialog();
if(Validator.isNotNull(preferences.getImagePath()) && !preferences.getImagePath().isEmpty()) {
preferences.getImagePath().clear();
}
com.aimdek.healthwel.network.Request.getRequest().sendRequest(com.aimdek.healthwel.network.Request.SHARE_USER_HISTORY, TwitterIntegration.this, TwitterIntegration.this, RequestParameterBuilder.buildMapForShareUserHistory(userHistory.getId(), TwitterIntegration.this));
}
#Override
public void failure(TwitterException exception) {
if(Validator.isNotNull(preferences.getImagePath()) && !preferences.getImagePath().isEmpty()) {
preferences.getImagePath().clear();
}
dismissProgressDialog();
finish();
HWUtil.showToast(TwitterIntegration.this,exception.getMessage());
}
});
}

Payment to this merchant is not allowed in android while integrating paypal

I am using sandbox account and following the tutorial http://androiddevelopmentanddiscussion.blogspot.com/2014/05/paypal-integration-in-android.html
I have given the client id which i have achieved by logging into sandbox account from my selling tools->api access
Here is my code:
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID = "";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName(" ")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
}
public void onBuyPressed(View pressed) {
// PAYMENT_INTENT_SALE will cause the payment to complete immediately.
// Change PAYMENT_INTENT_SALE to PAYMENT_INTENT_AUTHORIZE to only authorize payment and
// capture funds later.
if(pressed.getId() == R.id.button1){
thingToBuy = new PayPalPayment(new BigDecimal("8"), "USD", "Painting 1", PayPalPayment.PAYMENT_INTENT_SALE);
}else if(pressed.getId() == R.id.button2){
thingToBuy = new PayPalPayment(new BigDecimal("4"), "USD", "Painting 2", PayPalPayment.PAYMENT_INTENT_SALE);
}
Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(MainActivity.this, PayPalFuturePaymentActivity.class);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i(TAG, confirm.toJSONObject().toString(4));
Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
Toast.makeText(
getApplicationContext(),
"PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG)
.show();
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(TAG,"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth =
data.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject().toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(
getApplicationContext(),
"Future Payment code received from PayPal", Toast.LENGTH_LONG)
.show();
} catch (JSONException e) {
Log.e("FuturePaymentExample", "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(
"FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: " + correlationId);
// TODO: Send correlationId and transaction details to your server for processing with
// PayPal...
Toast.makeText(
getApplicationContext(), "App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
#Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
Here is the log message:
01-12 06:32:04.143: E/paypal.sdk(1778): request failure with http statusCode:401,exception:org.apache.http.client.HttpResponseException: Unauthorized
01-12 06:32:04.143: E/paypal.sdk(1778): request failed with server response:{"error":"invalid_client","error_description":"The client credentials are invalid"}
01-12 06:32:04.143: E/PayPalService(1778): invalid_client
I am new in this topic so explanation would be nice.
Use your sandbox credential (Client id) here.
private static final String CONFIG_CLIENT_ID = "";
Or follow below links:
Paypal integration using SDK
Paypal integration using gradle integration

Categories

Resources