簡體   English   中英

Android Paypal集成:沙盒到生產

[英]Android Paypal Integration: Sandbox to Production

我已經使用Paypal Sandbox環境成功測試了我的android應用。 我即將發布我的應用,因此要將Paypal配置更改為“ PRODUCTION”

為此,我將以下更改用於生產:

private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_PRODUCTION;
private static final String CONFIG_CLIENT_ID = "my client id for production";
private static final String CONFIG_RECEIVER_EMAIL = "live-id@gmail.com";

現在,當我嘗試使用另一個Paypal帳戶進行付款時,出現錯誤:

登錄失敗

系統錯誤。 請稍后再試。

使用具有生產設置的仿真器也會發生相同的情況。

我的問題是,我是否必須進行其他更改才能從沙箱遷移到生產環境?

謝謝

更新1

  1. 以上所有設置均適用於“生產”環境。
  2. 使用直接付款

當我在onCreate之前命名String時,我注意到從我的應用程序中使用Paypal會出現問題,所以我做了。

//When you want to initiate payment...
public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);
PaymentActivity.ENVIRONMENT_LIVE);//etc

我不知道“制作”或“現場”有什么不同,但請嘗試一下。

我將增加更多希望,這將有助於我做到這一點

在onCreate之前刪除所有這些貝寶字符串,而當他們准備付款時,使用onClick的文本框為onBuyPressed ...

public void onBuyPressed(View pressed) {
            TextView inptP =(TextView)findViewById(R.id.WHATHEYAREBUYING);
            String iu =inptP.getText().toString();

            TextView inptt =(TextView)findViewById(R.id.WHATITCOST);
            String it =inptt.getText().toString();


            try{

            double valuez =Double.parseDouble(it); 
            if(valuez> 0)
            {
            PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);

            Intent intent = new Intent(this, PaymentActivity.class);

            TextView id =(TextView)findViewById(R.id.MYPAYPALID);
            String uname = id.getText().toString();

            TextView iz =(TextView)findViewById(R.id.MYPAYPALEMAIL);
            String insane = iz.getText().toString();


            TextView name =(TextView)findViewById(R.id.MYCUSTOMERSNAME);
            String custname = name.getText().toString();


            Time now = new Time();
            now.setToNow();


            // comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
            intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_LIVE);

            // 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, uname);

            // Provide a payerId that uniquely identifies a user within the scope of your system,
            // such as an email address or user ID.

            intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, custname);
            intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, insane);
            intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

            startActivityForResult(intent, 0);
            }
            else{

               Toast.makeText(getApplicationContext(), "You haven't entered anything.",
                       Toast.LENGTH_LONG).show();
                }} catch (NumberFormatException e) {

                }}




        @Override
        protected void onActivityResult (int requestCode, int resultCode, Intent data) {
            if (resultCode == Activity.RESULT_OK) {
                PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

           //THINGS YOU WANT IT TO WHEN THE PAYMENT IS FINISHED GO BETWEEN HERE

//AND HERE

             if (confirm != null) {
                    try {
                        Log.i("paymentExample", 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("paymentExample", "an extremely unlikely failure occurred: ", e);
                    }
                }
            }
            else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i("paymentExample", "The user canceled.");
            }
            else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
                Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
            }}

無需實時啟用PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT。

這是我的代碼,可以正常工作。 聲明這些常量是類范圍。 注意:在開發人員Paypal中,應用程序頁面中有兩個客戶端ID。 一個在“測試憑據”中,另一個在“實時憑據”下,您應該單擊“顯示”鏈接才能看到它。 如果要發布應用程序,請選擇“實時憑據”的客戶端ID。

private static final String PAYPAL_CLIENT_ID = "YOUR-CLIENT-IT";
private static final String PAYPAL_RECEIVER_EMAIL = "YOUR-EMAIL";

然后在onCreate()中定義服務:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // start Paypal service
    Intent intent = new Intent(this, PayPalService.class);
    // live: don't put any environment extra
    // sandbox: use PaymentActivity.ENVIRONMENT_SANDBOX
    intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, PAYPAL_CLIENT_ID);
    startService(intent);
}

當用戶點擊按鈕時,將運行以下方法:

private void openDonateBtnPressed(BigDecimal donation) {
        PayPalPayment payment = new PayPalPayment(donation, "USD", "Donation");

        Intent intent = new Intent(this, PaymentActivity.class);

        // comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
        intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);

        // 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, PAYPAL_CLIENT_ID);

        // Provide a payerId that uniquely identifies a user within the scope of your system,
        // such as an email address or user ID.
        intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "<someuser@somedomain.com>");

        intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, PAYPAL_RECEIVER_EMAIL);
        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

        startActivityForResult(intent, 0);
    }

這是onActivityResult():

@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 {
                Toast.makeText(RateTheAppActivity.this, R.string.rate_donation_received, Toast.LENGTH_LONG).show();

                Log.d(TAG, confirm.toJSONObject().toString(4));

            } catch (JSONException e) {
                Log.e(TAG, "an extremely unlikely failure occurred: ", e);
            }
        }
    }
    else if (resultCode == Activity.RESULT_CANCELED) {
        Log.d(TAG, "The user canceled.");
    }
    else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
        Log.e(TAG, "An invalid payment was submitted. Please see the docs.");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM