2013-11-27 85 views
1

您好,我正在嘗試整合Paypal AndroidSDK與我的android應用程序。我遵循了paypal集成文檔,並嘗試按照說明進行集成。但是當我按購買按鈕屏幕導航到下面顯示的貝寶屏幕。 enter image description herepaypal 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與確認信息。

請讓我知道,如果你知道我的問題的解決方案。 任何幫助將不勝感激。

+0

您是否找到解決方案好友? – YuDroid

回答

5

最後我找到了解決方案。

貝寶androidSDK整合不是如果當前的工作(其中i放置購買按鈕)活動的機器人:launchMode = 「singleInstance」。當我刪除launchMode該活動工作正常。

+0

非常感謝。我尋找狼。關於我的環境,我用「SingleTop」代替。 – metamagicson

+0

raj如果您發現解決方案,請幫助我也計劃將支付帳戶與Android應用程序進行在線業務集成。來自印度的商業賬戶。可以整合細節並獲得客戶ID和祕密。 – Harsha

+0

請按照https://developer.paypal.com/docs/integration/mobile/mobile-sdk-overview/ – Raj