Paypal的沙盒信用卡无效
我已经下载了用于android的Paypal SDK,并将我的代码与示例项目进行了比较,除了我在Paypal之后向活动发送的附加意图之外,它们是相同的。问题是我犯了一个奇怪的错误。一旦我点击按钮,添加cc详细信息并按下charge…贝宝说我输入的信用卡无效。这只发生在我尝试发送我自己额外的东西时。当我突然取消我的额外意图时,同样的沙盒信用卡也顺利通过了。这是因为paypal只接受某些变量,可能是浮动的,不喜欢字符串吗?或者,也许我的代码中有一个简单的缺陷Paypal的沙盒信用卡无效,paypal,paypal-sandbox,Paypal,Paypal Sandbox,我已经下载了用于android的Paypal SDK,并将我的代码与示例项目进行了比较,除了我在Paypal之后向活动发送的附加意图之外,它们是相同的。问题是我犯了一个奇怪的错误。一旦我点击按钮,添加cc详细信息并按下charge…贝宝说我输入的信用卡无效。这只发生在我尝试发送我自己额外的东西时。当我突然取消我的额外意图时,同样的沙盒信用卡也顺利通过了。这是因为paypal只接受某些变量,可能是浮动的,不喜欢字符串吗?或者,也许我的代码中有一个简单的缺陷 public void onBuyPre
public void onBuyPressed(View pressed) {
TextView inputx =(TextView)findViewById(R.id.super);
String ix =inputx.getText().toString();
TextView inputP =(TextView)findViewById(R.id.input);
String ip =inputP.getText().toString();
try{
double valuey =Double.parseDouble(ip);
if(valuey>0)
{
PayPalPayment payment = new PayPalPayment(new BigDecimal(valuey), "USD", ix );
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_SANDBOX);
// 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, "AZetc,etc,etc..the Id is NOT the issue");
// 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, "");
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL,"myprivateemail@yahoo.com");
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
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);
if (confirm != null) {
final TextView x =(TextView)findViewById(R.id.custname);
String onex = x.getText().toString();
final TextView nov =(TextView)findViewById(R.id.secret);
String dec = nov.getText().toString();
final TextView feb =(TextView)findViewById(R.id.secretname);
String jan = feb.getText().toString();
final TextView xx =(TextView)findViewById(R.id.inputPrice);
String twox = xx.getText().toString();
final TextView xxx =(TextView)findViewById(R.id.help);
String threex = xxx.getText().toString();
Intent intent= new Intent(SuperActivity2.this,SuperCheckActivity.class)
.putExtra("secret",dec)
.putExtra("secretname",jan)
.putExtra("date",threex)
.putExtra("inputPrice",twox)
.putExtra("customername",onex)
.putStringArrayListExtra("list", listItems);
startActivity(intent);
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.");
}
我也有同样的问题。当我尝试用贝宝支付时,一切正常,但当我尝试用信用卡支付时,我得到了错误,信用卡的数据不正确。 然后我调试我的应用程序,看到我设置为PayPalPayment的金额有很大的洞察力。所以我把我的感知设置为小数点后2位,用信用卡支付就行了 以下是我如何设置金额的示例:
ttlPrice = new BigDecimal(totalPrice, MathContext.DECIMAL32).setScale(2);
payment = new PayPalPayment(ttlPrice, "EUR", "description");
ttlPrice=新的BigDecimal(totalPrice,MathContext.DECIMAL32)。设置刻度(2);
付款=新付款(TTL价格、“欧元”、“说明”) 请修正你的答案,给出一些解释,并将其格式化。