【发布时间】:2017-01-02 06:46:01
【问题描述】:
我已经在PaymentActivity 中使用PayPalPayment.PAYMENT_INTENT_AUTHORIZE 意图授权了Paypal 金额,现在我有authorizationId 但现在如何获取这笔金额?
代码开始PaymentActivity
PayPalPayment thingToBuy = getStuffToBuy(PayPalPayment.PAYMENT_INTENT_AUTHORIZE);
/*
* See getStuffToBuy(..) for examples of some available payment options.
*/
Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
// send the same configuration for restart resiliency
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
onActivityResult
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
ProofOfPayment proof = confirm.getProofOfPayment();
PayPalPayment payment = confirm.getPayment();
payment.enablePayPalShippingAddressesRetrieval(true);
JSONObject object = proof.toJSONObject();
String authID = "";
try {
authID = object.getString("authorization_id");
} catch (JSONException e) {
e.printStackTrace();
}
if (confirm != null) {
try {
Log.i(TAG, confirm.toJSONObject().toString(4));
Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
/**
* TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
* or consent completion.
* See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
* for more details.
*
* For sample mobile backend interactions, see
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
displayResultText(authID);
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(
TAG,
"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}
现在我在 authId 中有授权 ID,现在我想获取这个金额。我可以在我的应用程序中执行此操作而无需任何服务器端工作吗?
【问题讨论】:
-
您是使用一次性付款还是未来付款
-
我正在使用singlePayment
-
您是否收到任何 id 以响应 "id":"PAY-564191241M8701234KL57LXI" 并且您也有访问令牌
-
是的,我得到了 id 和授权 ID,但没有访问令牌