贝宝中的 INVALID_RESOURCE_ID
Posted
技术标签:
【中文标题】贝宝中的 INVALID_RESOURCE_ID【英文标题】:INVALID_RESOURCE_ID in paypal 【发布时间】:2017-11-25 07:35:57 【问题描述】:我已经通过 PayPal 原生 android mobile 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"
下面是安卓代码
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
不知道如何解决这个问题。
【问题讨论】:
您使用的是哪个贝宝版本? 最新的'com.paypal.sdk:paypal-android-sdk:2.15.3' 好吧。 startService() 的代码在哪里? 看我的回答可能对你有帮助。 【参考方案1】:试试这个,这是我的 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)
//
【讨论】:
好的,我正在尝试。但我没有得到的是我从示例 PayPal GitHub 中选择了代码。所以它应该可以工作。虽然我会检查代码并恢复。 很抱歉从服务器得到相同的响应。 请验证您的贝宝沙盒帐户。配置是否正确。 我在上面的代码中使用了这个版本。编译'com.paypal.sdk:paypal-android-sdk:2.15.1' 换低版本试试看。以上是关于贝宝中的 INVALID_RESOURCE_ID的主要内容,如果未能解决你的问题,请参考以下文章