我注意到Paypal Android SDK自v2.5.0以来添加了添加custom
或添加invoice
到 PaypalPayment的选项。我现在可以向 PaypalPayment 添加一个项目以及一个自定义值,如下所示:
PayPalPayment payment = new PayPalPayment(new BigDecimal("1.75"), "USD", "sample item",
PayPalPayment.PAYMENT_INTENT_SALE);
payment.custom("my custom value");
但是,他们的文档中没有提到如何在onActivityResult
. 这是我的代码:
@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 {
//How do I get `custom` from `confirm` object here???
Log.e(TAG, confirm.toJSONObject().toString(4));
Log.e(TAG, confirm.getPayment().toJSONObject()
.toString(4));
String paymentId = confirm.toJSONObject()
.getJSONObject("response").getString("id");
String payment_client = confirm.getPayment()
.toJSONObject().toString();
Log.e(TAG, "paymentId: " + paymentId
+ ", payment_json: " + payment_client);
//Payment verification logic
} catch (JSONException e) {
Log.e(TAG, "Meow! Coders ye be warned: ",e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.e(TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.e(TAG,"Invalid Payment");
}
}
}
即使我使用发票编号而不是自定义,似乎也没有任何方法可以从PaymentConfirmation对象中检索,也没有它的方法PaypalPayment