您好,我正在嘗試整合Paypal AndroidSDK與我的android應用程序。我遵循了paypal集成文檔,並嘗試按照說明進行集成。但是當我按購買按鈕屏幕導航到下面顯示的貝寶屏幕。 paypal android SDK與我的應用程序集成不起作用
但onActivityResult回電與resultCode爲馬上當我與PaymentConfirmation結果完成支付過程後按下購買按鈕,而不是RESULT_OK的到來爲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, "[email protected]");
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如果我的活性的影響。 我的按鈕位於一個片段中,活動從v4支持庫中的FragmentActivity繼承。
請讓我知道我在做什麼錯了,爲什麼onActivityResult立即被調用,而不是付款過程的onCompletion與確認信息。
請讓我知道,如果你知道我的問題的解決方案。 任何幫助將不勝感激。
您是否找到解決方案好友? – YuDroid