Android Paypal Integration: Sandbox To Production
Solution 1:
I've noticed problems using paypal from my app when I name the String before onCreate so what I did was..
//When you want to initiate payment...publicvoidonBuyPressed(View pressed) {
PayPalPaymentthingToBuy=newPayPalPayment(newBigDecimal(valuez), "USD", iu);
PaymentActivity.ENVIRONMENT_LIVE);//etc
I dont know if "PRODUCTION" or "LIVE" makes a difference but give it a try.
I'm going to add more hope this helps this is what i did
get rid of all those paypal strings before onCreate and just when they get ready to pay have textbox with onClick is onBuyPressed...
publicvoidonBuyPressed(View pressed) {
TextViewinptP=(TextView)findViewById(R.id.WHATHEYAREBUYING);
Stringiu=inptP.getText().toString();
TextViewinptt=(TextView)findViewById(R.id.WHATITCOST);
Stringit=inptt.getText().toString();
try{
doublevaluez=Double.parseDouble(it);
if(valuez> 0)
{
PayPalPaymentthingToBuy=newPayPalPayment(newBigDecimal(valuez), "USD", iu);
Intentintent=newIntent(this, PaymentActivity.class);
TextViewid=(TextView)findViewById(R.id.MYPAYPALID);
Stringuname= id.getText().toString();
TextViewiz=(TextView)findViewById(R.id.MYPAYPALEMAIL);
Stringinsane= iz.getText().toString();
TextViewname=(TextView)findViewById(R.id.MYCUSTOMERSNAME);
Stringcustname= name.getText().toString();
Timenow=newTime();
now.setToNow();
// comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_LIVE);
// it's important to repeat the clientId here so that the SDK has it if Android restarts your// app midway through the payment UI flow.
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, uname);
// Provide a payerId that uniquely identifies a user within the scope of your system,// such as an email address or user ID.
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, custname);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, insane);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
else{
Toast.makeText(getApplicationContext(), "You haven't entered anything.",
Toast.LENGTH_LONG).show();
}} catch (NumberFormatException e) {
}}
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmationconfirm= data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
//THINGS YOU WANT IT TO WHEN THE PAYMENT IS FINISHED GO BETWEEN HERE//AND HEREif (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification.// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/// for more details.
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
elseif (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
}
elseif (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
}}
Solution 2:
No need to put PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT for live.
Solution 3:
This is my code which is working fine. Declare these constants is class scope. NOTE: There are two client ids in page of your application in developer Paypal. One in "Test credentials" and The other under "Live credentials" that you should click on "show" link in order to see it. Select client id of "Live credentials" if you want to release your application.
privatestaticfinalStringPAYPAL_CLIENT_ID="YOUR-CLIENT-IT";
privatestaticfinalStringPAYPAL_RECEIVER_EMAIL="YOUR-EMAIL";
Then define service in onCreate():
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// start Paypal serviceIntentintent=newIntent(this, PayPalService.class);
// live: don't put any environment extra// sandbox: use PaymentActivity.ENVIRONMENT_SANDBOX
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, PAYPAL_CLIENT_ID);
startService(intent);
}
When user hit a button following method will run:
privatevoidopenDonateBtnPressed(BigDecimal donation) {
PayPalPaymentpayment=newPayPalPayment(donation, "USD", "Donation");
Intentintent=newIntent(this, PaymentActivity.class);
// comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);
// it's important to repeat the clientId here so that the SDK has it if Android restarts your// app midway through the payment UI flow.
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, PAYPAL_CLIENT_ID);
// Provide a payerId that uniquely identifies a user within the scope of your system,// such as an email address or user ID.
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "<someuser@somedomain.com>");
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, PAYPAL_RECEIVER_EMAIL);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);
}
and this is onActivityResult():
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmationconfirm= data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Toast.makeText(RateTheAppActivity.this, R.string.rate_donation_received, Toast.LENGTH_LONG).show();
Log.d(TAG, confirm.toJSONObject().toString(4));
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
}
elseif (resultCode == Activity.RESULT_CANCELED) {
Log.d(TAG, "The user canceled.");
}
elseif (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.e(TAG, "An invalid payment was submitted. Please see the docs.");
}
}
Post a Comment for "Android Paypal Integration: Sandbox To Production"