Multiple PayPal merchants within an Android app?

dahaoenf
Contributor
Contributor
Hey guys,
 

I have some trouble with an App including a Payment via the PayPal SDK (using version 2.15.3 atm). Below you find some example code: It consists of an activity with two buttons. Each button initiates a PayPal payment. Depending on which button you click, the merchant changes by using a different clientID. So far that works. BUT: upon reentering the activity, it's not possible to change the merchant! (Once a payment is finished you'll be redirected to the MainActivity. Same if you cancel the payment process, no matter at which step.) Only after restarting the app it's possible to choose a merchant again.


Example 1: I start the app, choose merchant/clientID 1, make my payment, return to the MainActivity. Now I choose merchant/clientID 2, make my payment. But BOTH payments end up at merchant 1.

 

Example 2: I start the app, choose merchant/clientID 2, start the payment process, cancel it (no matter at which step), return to the MainActivity. Now I choose merchant/clientID 1, make my payment. But the payment ends up at merchant 2.

 

In the end the user thinks he paid merchant X, but his money ends up at merchant Y.


I checked the intent, but the config-extra seems to be correct. Also i tried to work with "stopService" and the "savedInstanceState", but that didn't change anything. Also the problem still occurs with paypal sdk version 2.16.

 

Do you have any suggestions/experience concerning this problem? Thanks!

 

Cheers, dahaoenf

 


MainActivity.java:

package com.example.paypal_client_testapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import java.math.BigDecimal;

public class MainActivity extends AppCompatActivity {

    private static final int PAYPAL_REQUEST_CODE = 1234;
    public static final String CLIENT_ID_1 = "abcdefghijklmnopqrstuvw_xyzabcdefghijklmnopqrstuvwxyzabcdefghij_klmnopqrstuvwxy1";
    public static final String CLIENT_ID_2 = "abcdefghijklmnopqrstuvw_xyzabcdefghijklmnopqrstuvwxyzabcdefghij_klmnopqrstuvwxy2";

    @Override
    protected void onDestroy(){
stopService
(new Intent(this, PayPalService.class)); super.onDestroy(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button button1 = findViewById(R.id.button1); Button button2 = findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
processPayment(CLIENT_ID_1); } });
button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
processPayment(CLIENT_ID_2); } }); } private void processPayment(String CLIENT_ID) { int amount = 1; PayPalConfiguration config = new PayPalConfiguration() .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX) .clientId(CLIENT_ID); PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(amount), "EUR","myPayment",PayPalPayment.PAYMENT_INTENT_SALE); Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT,payPalPayment);
startService(intent);
startActivityForResult(intent,PAYPAL_REQUEST_CODE); } }
Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.