Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full access to response error object #206

Closed
agentscamp5 opened this issue May 12, 2021 · 5 comments · Fixed by #273
Closed

Full access to response error object #206

agentscamp5 opened this issue May 12, 2021 · 5 comments · Fixed by #273
Labels
enhancement New feature or request P3

Comments

@agentscamp5
Copy link
Collaborator

Our company uses Stripe's Radar for Fraud Teams to block certain types of cards from being used for things like setupIntents and paymentIntents (e.g. we are only letting debit cards be used right now, would reject a credit card). Right now in this package if we get an error, we are only provided the localizedDescription of the error object, but I can see from Stripe's API logs that the error object contains way more information. The error message for a card failing by Radar is very generic "Your card was declined", and if we had access to the full error object we could look into it and give more detailed messaging like "We do not accept credit cards".

A feature to have access to the complete response/error object that is returned from the Stripe API for unsuccessful requests would be very helpful.

@thorsten-stripe thorsten-stripe added enhancement New feature or request P1 Address these issues second labels May 14, 2021
@thorsten-stripe thorsten-stripe added this to Inbound backlog in React Native V1 backlog May 14, 2021
@arekkubaczkowski arekkubaczkowski moved this from Inbound backlog to In progress in React Native V1 backlog May 18, 2021
@thorsten-stripe thorsten-stripe added P3 and removed P1 Address these issues second labels May 18, 2021
@thorsten-stripe thorsten-stripe moved this from In progress to Inbound backlog in React Native V1 backlog May 18, 2021
@thorsten-stripe thorsten-stripe moved this from Inbound backlog to In progress in React Native V1 backlog May 25, 2021
@agentscamp5
Copy link
Collaborator Author

agentscamp5 commented May 26, 2021

@arekkubaczkowski looking at your MR, what I meant by the ticket was that the API error response looks like
{
"error": {
"code": "card_declined",
"decline_code": "generic_decline",
"doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card was declined.",
"payment_method": {
"id": "someId",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": "12312",
"state": null
},
"email": "testEmail,
"name": null,
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": null
},
"country": "US",
"exp_month": 12,
"exp_year": 2031,
"funding": "prepaid",
"generated_from": null,
"last4": "4242",
...

And we would like to access the paymentMethod field form the error because Stripe Radar failures dont give us info like "this failed because the funding type was prepaid, and we want to be able to tell the user that

@thorsten-stripe
Copy link
Contributor

@agentscamp5 the SDKs do not return that level of information, but in the case of an error you can use retrievePaymentIntent to specifically retrieve it:

Code:

const { error, paymentIntent } = await confirmPayment(clientSecret, {
      type: 'Card',
      billingDetails,
    });

    if (error) {
      console.log(JSON.stringify(error, null, 2));
      const { paymentIntent } = await retrievePaymentIntent(clientSecret);
      console.log(JSON.stringify(paymentIntent, null, 2));
      Alert.alert(`Error code: ${error.code}`, error.message);
      console.log('Payment confirmation error', error.message);
    } else if (paymentIntent) {
      Alert.alert(
        'Success',
        `The payment was confirmed successfully! currency: ${paymentIntent.currency}`
      );
      console.log('Success from promise', paymentIntent);
    }

Result:

// error
{
  "stripeErrorCode": "card_declined",
  "message": "Your card was declined.",
  "declineCode": "generic_decline",
  "type": null,
  "localizedMessage": "Your card was declined.",
  "code": "Failed"
}

// paymentIntent.lastPaymentError
{
    "type": "Card",
    "message": "Your card was declined.",
    "code": "card_declined",
    "paymentMethod": {
      "livemode": false,
      "Card": {
        "last4": "0002",
        "expMonth": 12,
        "funding": "credit",
        "country": "US",
        "expYear": 2022,
        "brand": "Visa"
      },
      "Sofort": {
        "country": null
      },
      "Upi": {
        "vpa": null
      },
      "BacsDebit": {
        "sortCode": null,
        "last4": null,
        "fingerprint": null
      },
      "SepaDebit": {
        "fingerprint": null,
        "last4": null,
        "country": null,
        "bankCode": null
      },
      "billingDetails": {
        "name": null,
        "address": {
          "state": null,
          "country": "US",
          "line2": "Texas",
          "line1": "1459  Circle Drive",
          "postalCode": "77063",
          "city": "Houston"
        },
        "phone": "+48888000888",
        "email": "email@stripe.com"
      },
      "Ideal": {
        "bankIdentifierCode": null,
        "bankName": null
      },
      "id": "pm_1IvisVG7gfqYEkPO3vcbJZi4",
      "type": "Card",
      "AuBecsDebit": {
        "last4": null,
        "fingerprint": null,
        "bsbNumber": null
      },
      "Fpx": {
        "bank": null,
        "accountHolderType": null
      },
      "customerId": null
    }
  }

@agentscamp5
Copy link
Collaborator Author

@thorsten-stripe THANKS!!!!

@agentscamp5
Copy link
Collaborator Author

@thorsten-stripe would that work for setupIntents as well? We would similarly want to retrieve a setupIntent that failed

@thorsten-stripe thorsten-stripe moved this from In progress to Done in React Native V1 backlog Jun 1, 2021
@thorsten-stripe
Copy link
Contributor

retrieveSetupIntent is currently not implemented. I've added an issue to track that: #294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P3
Development

Successfully merging a pull request may close this issue.

2 participants