Payment to this merchant is not allowed (invalid clientid)

Viewed 2017

I integrated Paypal in my android app in sandbox mode and everything worked perfectly fine. Now I switched to live mode and changed the client ID in my app as well.

Now this error is displayed when I tried to make a test purchase:

"Payment to this merchant is not allowed (invalid clientid)"

I don't know what to do. I changed the client id in every place from the sandbox id to the live id.

My class where Paypal is initialized when click on a button:

public class EssenActivity extends AppCompatActivity {

  private static final String TAG = "Log Essen Activity";
  private String kochuiD, preis, preis_ohne_euro, AnfragePortionenS, ungefahreAnkunftS, preisRe;
  private EditText anzahlPortionen;
  private TextView ungefähreAnkunft;
  private Button essenBesätigenBtn;
  private FirebaseFirestore firebaseFirestore;
  private TextView preisRechner;
  private FirebaseAuth mAuth;
  public static final int PAYPAL_REQUEST_CODE = 7171;
  private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
        .clientId(Config.PAYPAL_CLIENT_ID);
  private String amount, amountOhneEuro;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_essen);


    essenBesätigenBtn = findViewById(R.id.essenBestätigen);
    essenBesätigenBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           processPayment();
        }
    }
  }


  private void processPayment() {
    amount = preisRechner.getText().toString();
    amountOhneEuro = amount.replace("€", "");
    PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(String.valueOf(amountOhneEuro)), "EUR",
            "Bezahle das Essen", PayPalPayment.PAYMENT_INTENT_SALE);
    Intent intent = new Intent(EssenActivity.this, PaymentActivity.class);
    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payPalPayment);
    startActivityForResult(intent, PAYPAL_REQUEST_CODE);
  }

  @Override
  //
  public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == PAYPAL_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            PaymentConfirmation confirmation = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirmation != null) {
                try {
                    String paymentDetails = confirmation.toJSONObject().toString(4);
                    startActivity(new Intent(EssenActivity.this, PaymentDetails.class)
                            .putExtra("PaymentDetails", paymentDetails)
                            .putExtra("PaymentAmount", amountOhneEuro)
                            .putExtra("Koch Uid", kochuiD)
                    );
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.d(TAG, "onActivityResult: wurde gecancelt");
        }
    } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
        Toast.makeText(EssenActivity.this, "Ungültig", Toast.LENGTH_SHORT).show();

  }

  @Override
  public void onDestroy() {
    EssenActivity.this.stopService(new Intent(EssenActivity.this, PayPalService.class));
    super.onDestroy();
  }
}

My Config class:

public class Config {
  public static final String PAYPAL_CLIENT_ID ="MY CLIENT ID";
}

My Paymentdetails class:

public class PaymentDetails extends AppCompatActivity {

  private static final String TAG = "PAYMENT";
  private TextView txtid, txtAmount, txtStatus;
  private FirebaseFirestore firebaseFirestore;
  private FirebaseAuth mAuth;
  private DocumentReference docIdRef;
  private String kochUid;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment_details);

    txtid = findViewById(R.id.txtId);
    txtAmount = findViewById(R.id.txtAmount);
    txtStatus = findViewById(R.id.txtStatus);

    Intent intent = getIntent();

    try {
        JSONObject jsonObject = new JSONObject(intent.getStringExtra("PaymentDetails"));
        showDetails(jsonObject.getJSONObject("response"), intent.getStringExtra("PaymentAmount"));

    } catch (JSONException e) {
        e.printStackTrace();
    }
  }

  private void showDetails(JSONObject response, String paymentAmount) {
    try {

        firebaseFirestore = FirebaseFirestore.getInstance();
        mAuth = FirebaseAuth.getInstance();
        String uid = mAuth.getCurrentUser().getUid();

        if (response.getString("state").equals("approved")) {
            DocumentReference documentReference = firebaseFirestore.collection("essen_aktiv_anfrage").document(uid);

            Map<String, String> anfrageMap = new HashMap<>();
            anfrageMap.put("Id", response.getString("id"));
            anfrageMap.put("Status", response.getString("state"));
            anfrageMap.put("Betrag", paymentAmount + "€");
            //NEU
            anfrageMap.put("Anfrage User", uid);
            anfrageMap.put("Koch Uid", kochUid);


            documentReference.set(anfrageMap, SetOptions.merge())
                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            Intent intent = new Intent(PaymentDetails.this, MainActivity.class);
                            intent.putExtra("Bezahlung war erfolgreich", "approved");
                            Toast.makeText(PaymentDetails.this, "Bezahlung war erfolgreich", Toast.LENGTH_SHORT).show();
                            startActivity(intent);
                        }
                    });
        } else{
            Toast.makeText(PaymentDetails.this, "Bezahlung war nicht erfolgreich", Toast.LENGTH_SHORT).show();
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
  }
}

Any help is appreciated. Thank you very much.

2 Answers

Authorization defaults to sandbox unless explicitly set to "live". It needs to be set within the PayPalConfiguration which is used in creation of the oAuth token, and the creation of the APIContext which is used to call the PayPal service.

I had been getting the same error within a live environment, despite it working in sandbox. It is therefore likely that you have missed something.

Change ENVIRONMENT_SANDBOX to ENVIRONMENT_PRODUCTION

Related