遵循此 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): }
据说国家已批准,但在沙盒控制台中未扣除金额,并且未添加商业帐户金额,没有得到帮助我的问题。