Android Paypal集成:沙盒到生产 [英] Android Paypal Integration: Sandbox to Production

查看:677
本文介绍了Android Paypal集成:沙盒到生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Paypal Sandbox环境成功测试了我的android应用.我即将发布我的应用,因此想将Paypal配置更改为'PRODUCTION'

I've tested my android app successfully using Paypal Sandbox environment. I am about to release my app, so want to change the paypal configuration to 'PRODUCTION'

为此,我将以下内容用于生产:

To do this, I've changed the following for 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帐户进行付款时,出现了错误:

Now when I try to make a payment using my another paypal account, I am getting error:

登录失败

系统错误.请稍后再试.

System error. Please try again later.

使用具有生产设置的仿真器也会发生同样的事情.

Same thing happens using the emulator with production settings.

我的问题是,我是否需要做其他更改才能从沙箱迁移到生产环境?

My question is do I have to make any other changes to move from sandbox to production env?

谢谢

更新1

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

推荐答案

这是我的代码,可以正常工作. 声明这些常量是类范围.注意:在开发人员Paypal中,应用程序页面中有两个客户端ID.您必须点击显示"链接才能看到它,其中一个位于测试凭据"中,另一个位于实时凭据"中.如果要发布应用程序,请选择实时凭据"的客户端ID.

This is my code which is working fine. Declare these constants is class scope. NOTE: There are two client ids in page of your application in developer Paypal. One in "Test credentials" and The other under "Live credentials" that you should click on "show" link in order to see it. Select client id of "Live credentials" if you want to release your application.

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

然后在onCreate()中定义服务:

Then define service in 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);
}

当用户点击按钮时,将运行以下方法:

When user hit a button following method will run:

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():

and this is 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.");
    }
}

这篇关于Android Paypal集成:沙盒到生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆