简体   繁体   English

Paypal的无效沙盒信用卡号码

[英]Invalid Sandbox Credit Card # for Paypal

I've downloaded the Paypal SDK for android and have compared my code with the Example Project and they are identical except for the added intents I send to the Activity after paypal. 我已经下载了适用于Android的Paypal SDK,并将我的代码与示例项目进行了比较,除了在Paypal之后我发送给Activity的意图外,它们是相同的。 The problem is I'm getting a weird error. 问题是我遇到了一个奇怪的错误。 Once I click the button, and add cc details and press charge...paypal says the credit card I'm entering is invalid. 一旦我单击按钮,并添加抄送详细信息并按费用...,贝宝说我输入的信用卡无效。 This only happens when I try to send my own extra stuff through. 这仅在我尝试发送自己的多余内容时发生。 When I remove my extra intents suddenly the same sandbox credit card goes through just fine. 当我突然删除多余的意图时,同一张沙盒信用卡就可以通过了。 Is this because paypal only accept certain variables, maybe Floats and doesn't like strings? 这是因为Paypal仅接受某些变量(可能是Floats)并且不喜欢字符串吗? Or, maybe there is a simple flaw in my code? 或者,也许我的代码中有一个简单的缺陷?

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.");


 }

I have the same problem. 我也有同样的问题。 When i try to pay with PayPal goes OK, but when i try to pay with Credit Card i get the error, that data for credit card are incorrect. 当我尝试使用PayPal付款时可以,但是当我尝试使用信用卡付款时出现错误,表明信用卡数据不正确。 Then i debug my app and see, that amount which i set to PayPalPayment have large percision. 然后我调试我的应用程序,然后看到我设置为PayPalPayment的金额具有较大的精度。 So i set my percision to 2 decimal place and paying with credit card works OK. 因此,我将精度设置为小数点后2位,并使用信用卡付款即可。

Here is example, how i set amount: 这是示例,我如何设置金额:

ttlPrice = new BigDecimal(totalPrice, MathContext.DECIMAL32).setScale(2);
payment = new PayPalPayment(ttlPrice, "EUR", "description");

ttlPrice = new BigDecimal(totalPrice, MathContext.DECIMAL32).setScale(2); ttlPrice = new BigDecimal(totalPrice,MathContext.DECIMAL32).setScale(2); payment = new PayPalPayment(ttlPrice, "EUR", "description"); Payment = new PayPalPayment(ttlPrice,“ EUR”,“ description”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM