[英]Invalid Sandbox Credit Card # for Paypal
我已經下載了適用於Android的Paypal SDK,並將我的代碼與示例項目進行了比較,除了在Paypal之后我發送給Activity的意圖外,它們是相同的。 問題是我遇到了一個奇怪的錯誤。 一旦我單擊按鈕,並添加抄送詳細信息並按費用...,貝寶說我輸入的信用卡無效。 這僅在我嘗試發送自己的多余內容時發生。 當我突然刪除多余的意圖時,同一張沙盒信用卡就可以通過了。 這是因為Paypal僅接受某些變量(可能是Floats)並且不喜歡字符串嗎? 或者,也許我的代碼中有一個簡單的缺陷?
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.");
}
我也有同樣的問題。 當我嘗試使用PayPal付款時可以,但是當我嘗試使用信用卡付款時出現錯誤,表明信用卡數據不正確。 然后我調試我的應用程序,然后看到我設置為PayPalPayment的金額具有較大的精度。 因此,我將精度設置為小數點后2位,並使用信用卡付款即可。
這是示例,我如何設置金額:
ttlPrice = new BigDecimal(totalPrice, MathContext.DECIMAL32).setScale(2);
payment = new PayPalPayment(ttlPrice, "EUR", "description");
ttlPrice = new BigDecimal(totalPrice,MathContext.DECIMAL32).setScale(2); Payment = new PayPalPayment(ttlPrice,“ EUR”,“ description”);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.