0

遵循此 paypal android 示例,此处在沙盒中创建了企业帐户和个人帐户,尝试进行交易,但未从个人帐户中检测到金额,也未添加到企业帐户中。这是我的代码。

@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): }

据说国家已批准,但在沙盒控制台中未扣除金额,并且未添加商业帐户金额,没有得到帮助我的问题。

4

2 回答 2

1

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

顺便说一句,我认为你应该隐藏你的CONFIG_CLIENT_IDCONFIG_RECEIVER_EMAIL从帖子中,因为它是你的私人信息。

于 2013-10-23T07:51:48.520 回答
1

在您的onBuyPressed方法中,您使用了

intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);

然后再次以相同的方法,您使用的是这样的:

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

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

于 2014-01-01T06:35:02.460 回答