2

我已经使用 Paypal Sandbox 环境成功测试了我的 android 应用程序。我即将发布我的应用程序,所以想将贝宝配置更改为“生产”

为此,我为生产更改了以下内容:

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";

现在,当我尝试使用我的另一个贝宝帐户付款时,我收到错误消息:

登录失败

系统错误。请稍后再试。

使用具有生产设置的模拟器也会发生同样的事情。

我的问题是我是否必须进行任何其他更改才能从沙盒迁移到生产环境?

谢谢

更新 1

  1. 以上所有设置均适用于“生产”环境。
  2. 使用直接付款
4

3 回答 3

0

这是我的代码,它工作正常。声明这些常量是类范围。注意:开发人员 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.");
    }
}
于 2014-02-08T17:35:05.567 回答
0

无需将 PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT 用于直播。

于 2013-11-12T11:22:14.017 回答
0

当我在 onCreate 之前命名字符串时,我注意到从我的应用程序中使用贝宝的问题,所以我所做的是..

//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 之前摆脱所有这些 paypal 字符串,就在他们准备好付款时,有 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.");
            }}
于 2013-09-27T09:08:37.710 回答