【问题标题】:Payment to this merchant is not allowed (invalid clientid)不允许向该商家付款(客户 ID 无效)
【发布时间】:2019-06-05 20:48:13
【问题描述】:

我以沙盒模式将 Paypal 集成到我的 Android 应用程序中,一切正常。现在我切换到实时模式并在我的应用程序中更改了客户端 ID。

现在,当我尝试进行测试购买时会显示此错误:

“不允许向该商家付款(无效的客户 ID)”

我不知道该怎么办。我将每个地方的客户端 ID 从沙盒 ID 更改为实时 ID。

单击按钮时初始化 Paypal 的类:

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

我的配置类:

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

我的 Paymentdetails 类:

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

感谢任何帮助。非常感谢。

【问题讨论】:

    标签: java android paypal


    【解决方案1】:

    除非明确设置为“实时”,否则授权默认为沙盒。它需要在 PayPalConfiguration 中设置,用于创建 oAuth 令牌,以及创建用于调用 PayPal 服务的 APIContext。

    我在实时环境中遇到了同样的错误,尽管它在沙盒中工作。因此,您很可能遗漏了什么。

    【讨论】:

    • 非常感谢您的评论。我更改了这行代码: private static PayPalConfiguration config = new PayPalConfiguration() .environment(PayPalConfiguration.ENVIRONMENT_SANDBOX) .clientId(Config.PAYPAL_CLIENT_ID);到私有静态 PayPalConfiguration config = new PayPalConfiguration() .environment(PayPalConfiguration.ENVIRONMENT_PRODUCTION) .clientId(Config.PAYPAL_CLIENT_ID);但它仍然没有工作。你是如何解决这个问题的?
    • 我使用的是 .Net REST API,但 java REST API 应该类似。
    • OAuthTokenCredential 接受 PayPalConfiguration 作为参数。 APIContext 构造函数在其构造函数中接受此令牌,Config 也在 APIContext 的属性中设置link'Example'
    猜你喜欢
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 2015-04-24
    • 2015-03-01
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多