简体   繁体   中英

Testing - set declined card to a customer

I want to update a customer with a declined card for testing purposes.

But if I do:

Stripe.customers.update(stripeCustomer.id, {
    source: 'tok_chargeDeclined', // Token provided by stripe of a declined card
});

I get an exception:

Exception while invoking method 'stripe.test' { Error: Your card was declined.

What I am missing?

When you attach a card to a customer(for example with that update call), Stripe makes a temporary $0 charge against the card, to validate it and ensure you can charge the customer successfully later. This is mentioned at https://stripe.com/docs/saving-cards#saving-credit-card-details-for-later .

When you attach tok_chargeDeclined , this charge is declined and the card is not added to the customer. To test the case where a card can be successfully added to a customer, but declined later(ie if it later expires or has no funds), you can use the tok_chargeCustomerFail card from https://stripe.com/docs/testing#cards-responses

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