贝宝中的INVALID_RESOURCE_ID

时间:2017-06-22 07:02:29

标签: java android paypal

我通过PayPal原生Android手机sdk付款。以下是成功回复

{"response":{"state":"approved","id":"PAY-someID","create_time":"2017-06-21T18:01:33Z","intent":"sale"},"client":{"platform":"Android","paypal_sdk_version":"2.15.3","product_name":"PayPal-Android-SDK","environment":"sandbox"},"response_type":"payment"} 

但是当后端想要用支付ID验证,即PAY-someID时,每次都会像下面一样抛出错误json

[debug] application - verifyPayment mitemreqCppverifpmtrequest(PAY-someID)
[debug] application - verifpmtrequest case mendpointt https://api.sandbox.paypal.com/v1/payments/payment/PAY-someID
[debug] application - tx.get.body{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"someID"}

下面是android代码

private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;

    private static PayPalConfiguration config = new PayPalConfiguration()
                .environment(CONFIG_ENVIRONMENT)
                .clientId(CONFIG_CLIENT_ID)
                // The following are only used in PayPalFuturePaymentActivity.
                .merchantName("Example Merchant")
                .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
                .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
  PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
        Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

        startActivityForResult(intent, REQUEST_CODE_PAYMENT);

        return new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",
                paymentIntent);


 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PAYMENT) {
            if (resultCode == Activity.RESULT_OK) {
                PaymentConfirmation confirm =
                        data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                if (confirm != null) {
                    try {
                        Log.i(TAG, confirm.toJSONObject().toString(4));
}
}
}

问题类似于以下

https://github.com/paypal/PayPal-Android-SDK/issues/330

不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

试试这个,这是我的Google PlayStore应用程序的代码。

PayPalConfiguration config = new PayPalConfiguration().environment(PayPalConfiguration.ENVIRONMENT_SANDBOX).clientId("Your id");

Intent intent = new Intent(context, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);

PayPalPayment payment = new PayPalPayment(new BigDecimal(charge), "USD", eventName, PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(activity, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 1089);

不要忘记在OnDestroy()中停止服务。

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

同时停止OnActivityResult内部的服务当您执行所有任务时。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && requestCode == 1089) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (confirm != null)
        {
            try
            {
                // Your code after successful response.                    
            } catch (JSONException e) {
                Log.error(getClass().getName(), e);
            }
        }
        stopService(new Intent(this, PayPalService.class));
    } else if (resultCode == Activity.RESULT_CANCELED) {
        //
    } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
        //
    }
}