简体   繁体   中英

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. 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? 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. Then i debug my app and see, that amount which i set to PayPalPayment have large percision. So i set my percision to 2 decimal place and paying with credit card works OK.

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); payment = new PayPalPayment(ttlPrice, "EUR", "description");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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