Raj*_*Raj 1 android paypal paypal-sandbox android-fragments
您好我正在尝试将Paypal AndroidSDK与我的Android应用程序集成.我按照paypal集成文档,并尝试按照说明进行集成.但是当我按下购买按钮屏幕时,导航到下面显示的paypal屏幕.

但是当使用PaymentConfirmation结果完成付款流程后,当我按下购买按钮而不是RESULT_OK时,onActivityResult回调将立即返回结果为0(RESULT_CANCELED).
以下是我的代码段.
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.");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我的Activity,initPaymentService()方法调用来自onCreate.我的按钮位于片段中,活动继承自v4支持库中的FragmentActivity.
请让我知道我做错了什么,为什么立即调用onActivityResult而不是通过确认信息完成付款流程.
如果您知道我的问题的解决方案,请告诉我.任何帮助将不胜感激.
最后我找到了解决方案.
PayPal androidSDK集成不起作用如果Current(我放置Buy按钮)活动的android:launchMode ="singleInstance".当我将launchMode移除到该活动时,其工作正常.
| 归档时间: |
|
| 查看次数: |
1519 次 |
| 最近记录: |