Android Paypal Integration: production sandbox

I have successfully tested the Android app using Sandbox Sandbox. I'm going to release my application, so I want to change the PayPal configuration to "PRODUCTION"

To do this, I modified the following to create:

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 other PayPal account, I get an error message:

Login failed

System error. Please try again later.

The same thing happens with an emulator with performance settings.

My question is, should I make any other changes to transition from the sandbox to the production environment?

thank

UPDATE 1

  • All of the above settings are for the production environment.
  • Using direct payment
+2
3

paypal , String onCreate, .

//When you want to initiate payment...
public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);
PaymentActivity.ENVIRONMENT_LIVE);//etc

, "" "", .

, , ,

PayPal onCreate, , onClick 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 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.");
            }}
0

PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT live.

0

, . - . . Paypal . "Test credentials" "Live credentials", "", . " ", .

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

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);
}

, :

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 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);
    }

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.");
    }
}
0

Source: https://habr.com/ru/post/1682531/


All Articles