简体   繁体   中英

Android Paypal Integration: Sandbox to Production

I've tested my android app successfully using Paypal Sandbox environment. I am about to release my app, so want to change the paypal configuration to 'PRODUCTION'

To do this, I've changed the following for production:

private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_PRODUCTION;
private static final String CONFIG_CLIENT_ID = "my client id for production";
private static final String CONFIG_RECEIVER_EMAIL = "live-id@gmail.com";

Now when I try to make a payment using my another paypal account, I am getting error:

Login Failed

System error. Please try again later.

Same thing happens using the emulator with production settings.

My question is do I have to make any other changes to move from sandbox to production env?

Thanks

UPDATE 1

  1. All the above settings are for the 'production' environment.
  2. Using direct payment

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...
public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(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...

public void onBuyPressed(View pressed) {
            TextView inptP =(TextView)findViewById(R.id.WHATHEYAREBUYING);
            String iu =inptP.getText().toString();

            TextView inptt =(TextView)findViewById(R.id.WHATITCOST);
            String it =inptt.getText().toString();


            try{

            double valuez =Double.parseDouble(it); 
            if(valuez> 0)
            {
            PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);

            Intent intent = new Intent(this, PaymentActivity.class);

            TextView id =(TextView)findViewById(R.id.MYPAYPALID);
            String uname = id.getText().toString();

            TextView iz =(TextView)findViewById(R.id.MYPAYPALEMAIL);
            String insane = iz.getText().toString();


            TextView name =(TextView)findViewById(R.id.MYCUSTOMERSNAME);
            String custname = name.getText().toString();


            Time now = new Time();
            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) {

                }}




        @Override
        protected void onActivityResult (int requestCode, int resultCode, Intent data) {
            if (resultCode == Activity.RESULT_OK) {
                PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

           //THINGS YOU WANT IT TO WHEN THE PAYMENT IS FINISHED GO BETWEEN HERE

//AND HERE

             if (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);
                    }
                }
            }
            else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i("paymentExample", "The user canceled.");
            }
            else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
                Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
            }}

无需实时启用PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT。

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.

private static final String PAYPAL_CLIENT_ID = "YOUR-CLIENT-IT";
private static final String PAYPAL_RECEIVER_EMAIL = "YOUR-EMAIL";

Then define service in onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // start Paypal service
    Intent intent = new Intent(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:

private void openDonateBtnPressed(BigDecimal donation) {
        PayPalPayment payment = new PayPalPayment(donation, "USD", "Donation");

        Intent intent = new Intent(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():

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        PaymentConfirmation confirm = 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);
            }
        }
    }
    else if (resultCode == Activity.RESULT_CANCELED) {
        Log.d(TAG, "The user canceled.");
    }
    else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
        Log.e(TAG, "An invalid payment was submitted. Please see the docs.");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM