【问题标题】:Android Paypal Integration: Sandbox to ProductionAndroid Paypal 集成:沙盒到生产
【发布时间】:2013-10-02 18:56:35
【问题描述】:

我已经使用 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. 使用直接付款

【问题讨论】:

  • 这个客户端 ID 是产品还是沙盒?什么类型的付款,直接或预先批准?您需要提供更多信息
  • 好的,我已经更新了问题
  • 付款人好像无法登录。请确保用户和密码正确。您使用的是哪个版本的 sdk?
  • 用户名和密码正确。我通过登录贝宝网站再次检查。我正在使用最新的 Paypal(1.2) Android(2.3 和 4.0) SDK。
  • 但这有关系吗?它适用于沙盒..

标签: java android paypal


【解决方案1】:

当我在 onCreate 之前命名字符串时,我注意到在我的应用中使用 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 之前删除所有那些 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.");
            }}

【讨论】:

  • 如果修改后的答案不起作用,则必须是贝宝用户名或电子邮件本身,或者您的应用程序网站的贝宝开发人员中没有“接受付款”。
  • 我也确定您只是出于安全原因在 stackoverflow 上发布了这样的代码,但是“我的生产客户 ID”应该是您的实际 ID 名称。如果你已经涵盖了,请忽略我刚才所说的。
  • 我的设置为“实时”,而不是沙盒或无网络。
【解决方案2】:

无需启用 PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT。

【讨论】:

    【解决方案3】:

    这是我运行良好的代码。 声明这些常量是类范围。注意:开发人员 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.");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-29
      • 2013-09-21
      • 2020-09-04
      • 1970-01-01
      • 2015-03-28
      • 2013-07-15
      • 1970-01-01
      • 2016-03-06
      • 2014-06-12
      相关资源
      最近更新 更多