在android中的paypal沙盒帐户中汇款时出错

时间:2013-10-23 07:44:22

标签: android paypal

Following this paypal android example此处在沙盒中创建了企业帐户和个人帐户,尝试进行交易,但未从个人帐户检测到金额而未在商家帐户中添加金额。这是我的代码。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    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);
}

public void onBuyPressed(View pressed) {
    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, "credential-from-developer.paypal.com");
    intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "your-customer-id-in-your-system");
    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("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.");
    }
}

日志:

  10-23 01:06:05.979: I/paymentExample(10959): {
10-23 01:06:05.979: I/paymentExample(10959):     "payment": {
10-23 01:06:05.979: I/paymentExample(10959):         "short_description": "hipster jeans",
10-23 01:06:05.979: I/paymentExample(10959):         "amount": "1.75",
10-23 01:06:05.979: I/paymentExample(10959):         "currency_code": "USD"
10-23 01:06:05.979: I/paymentExample(10959):     },
10-23 01:06:05.979: I/paymentExample(10959):     "client": {
10-23 01:06:05.979: I/paymentExample(10959):         "platform": "Android",
10-23 01:06:05.979: I/paymentExample(10959):         "paypal_sdk_version": "1.2.1",
10-23 01:06:05.979: I/paymentExample(10959):         "product_name": "PayPal Android SDK; ",
10-23 01:06:05.979: I/paymentExample(10959):         "environment": "mock"
10-23 01:06:05.979: I/paymentExample(10959):     },
10-23 01:06:05.979: I/paymentExample(10959):     "proof_of_payment": {
10-23 01:06:05.979: I/paymentExample(10959):         "rest_api": {
10-23 01:06:05.979: I/paymentExample(10959):             "state": "approved",
10-23 01:06:05.979: I/paymentExample(10959):             "payment_id": "API-PAYMENT-ID-1843"
10-23 01:06:05.979: I/paymentExample(10959):         }
10-23 01:06:05.979: I/paymentExample(10959):     }
10-23 01:06:05.979: I/paymentExample(10959): }

说是州批准但是沙箱控制台的金额没有扣除,并且没有添加商业帐户金额,没有得到什么问题对我有帮助。

2 个答案:

答案 0 :(得分:1)

您的EXTRA_PAYPAL_ENVIRONMENT设置为ENVIRONMENT_NO_NETWORK。如果您想使用测试帐户或ENVIRONMENT_SANDBOX使用真钱(请记住使用正确的ID和邮件),请尝试使用ENVIRONMENT_PRODUCTION

顺便说一下,我认为你应该隐藏你的CONFIG_CLIENT_IDCONFIG_RECEIVER_EMAIL,因为这是你的私人信息。

答案 1 :(得分:1)

onBuyPressed方法中,您已使用

intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);

然后再用同样的方法,你就是这样用的:

intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "credential-from-developer.paypal.com");

将其替换为实际的CLIENT_ID。它会解决你的问题。