【发布时间】:2013-12-13 15:22:24
【问题描述】:
您好,我正在尝试将 Paypal AndroidSDK 与我的 android 应用程序集成。我遵循了贝宝集成文档并尝试按照说明进行集成。但是当我按下 购买 按钮屏幕导航到下面显示的贝宝屏幕。
但是当我在完成后按下购买按钮而不是 RESULT_OK 时,onActivityResult 回调将立即以 resultCode 作为 0(RESULT_CANCELED)带有PaymentConfirmation结果的付款流程。
以下是我的代码 sn-p。
public void initPaymentService() {
try {
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
// intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
} catch (Exception e) {
}
}
public void onBuyPressed(String amount) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("1.75"), "USD", "hipster jeans");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
// It's important to repeat the clientId here so that the SDK has it if Android restarts your
// app midway through the payment UI flow.
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "AL7neK4uQk1xTc-YsELHpTAvdkjscvGNJDGHhashc8BLL8nkaTesRWkHOczSmqMkKT"); // **Clientid** from **developer.paypal.com**
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "testpaypal@gmail.com");
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("PaypalTestActivity", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
} catch (JSONException e) {
Log.e("PaypalTestActivity", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("PaypalTestActivity", "The user canceled the Transaction.");
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("PaypalTestActivity", "An invalid payment was submitted. Please see the docs.");
}
}
initPaymentService() 方法调用来自 onCreate 如果我的 Activity。 我的按钮在一个片段中,并且活动是从 v4 支持库中的 FragmentActivity 继承的。
请让我知道我做错了什么,为什么会立即调用 onActivityResult 而不是 onCompletion 支付过程的确认信息。
如果您知道我的问题的解决方案,请告诉我。 任何帮助将不胜感激。
【问题讨论】:
-
哥们找到解决方案了吗?
标签: android android-fragments paypal paypal-sandbox