我正在构建一个 Android 应用程序,用户通过 PayPal 支付预订费用。这只是从用户到企业的一次性简单付款,仅此而已。
我从这里获得了 SDK https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index
我选择了 Mobile Payment Libraries 而不是 Mobile Express Checkout Library,你认为我选对了吗?MPL 允许我动态创建一个 paypal 支付按钮,并且布局完美。
我遵循了 SDK 附带的指南,它的标题是“Mobile Payments Library Developer Guide and Reference – Android OS Edition”
主要问题是当我测试按钮时,我点击它在沙箱中进行测试支付,它要求我登录,我尝试通过我的个人帐户登录它总是失败,我也尝试过朋友的帐户登录,仍然总是失败。
这是我使用的部分代码:
paypalObject = PayPal.initWithAppID(getApplicationContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX); // SANDBOX
CheckoutButton launchPayPalButton = paypalObject.getCheckoutButton(M_PaymentOptions.this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.bottomMargin = 10;
launchPayPalButton.setLayoutParams(params);
launchPayPalButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
PayPalPayment newPayment = new PayPalPayment();
newPayment.setSubtotal(BigDecimal.valueOf(10.f));
newPayment.setCurrencyType("GBP");
newPayment.setRecipient("private@private.co.uk"); // changed the email deliberately for privacy reasons
newPayment.setMerchantName("My Company");
Intent paypalIntent = PayPal.getInstance().checkout(newPayment, M_PaymentOptions.this);
M_PaymentOptions.this.startActivityForResult(paypalIntent, 1);
}
});
((RelativeLayout) findViewById(R.id.m_RelativeLayout)).addView(launchPayPalButton);