Stripe Checkout: Using saved Source vs a new token to create a Charge - stripe-payments

I'm using Stripe Checkout. In all the documentation I can find, Stripe recommends saving Customer information (including a default Source) during my first transaction with that customer, and using that default Source later when I want to create subsequent Charges. However, if a customer uses a different credit card during a subsequent Checkout transaction, it would be a mistake to charge the default Source.
So, it seems like I should always just use the token from stripe.js when making subsequent changes, and that I should create a new source for the customer whenever I detect the them using a card that's different from the default source.
However, in my testing it appears as though every token I get from stripe.js represents a unique card, even if I've used the same credit card number, expiration, and CVC. If I were to create a new card for each Checkout token and save it to the customer record, I'd potentially end up with mounds of duplicate card records for each customer.
Am I overlooking a way to associate stripe.js tokens with customers in a way that doesn't generate duplicates? Or am I going about this incorrectly?

Whenever you collect card details in Checkout, Stripe will create a new token for that card even if they use the same card details. The Token resource has the fingerprint property though.
That property is a unique identifier for a given card number in your account. This means that if I sign up today with my card and then I come back tomorrow with the same card under a different email address you'd see the same exact fingerprint on both Token or Card objects. The idea then would be to keep track of all the card fingerprints you see in your database to detect a returning customer. Whenever a customer adds a new card you'd first look if you've seen that card fingerprint before in your database and decide to create the customer or return an error based on this.
Separately, you should not offer Checkout for a customer that already has a saved card. Instead you should show them the card(s) available for example by showing the card brand and last 4 digits. And then the customer can either pay with one of those cards or add a new one.
You can add more than one card to a customer or replace the default one. You can also decide which card to charge by passing both the customer id in customer and the card id in source. This is all covered in details in Stripe's documentation here.

Related

Stripe: how can I block a specific credit card number?

We would like to block a payment from specific card number. But it seems like we have no way to determine if it's the same card number or not using Stripe API. The closest I can see is Saving Cards which can return customer.id. But from testing, customer.id is different each time even if credit card number is the same. So is there any way that we can block credit card number using Stripe API?
If you have access to write Radar rules within your Stripe account, you can write a rule to block a card if the card fingerprint matches whatever card you are looking to block. The card fingerprint is unique to a specific card so this would weed out any charges made using that specific card. The rule looks like:
Block if :card_fingerprint: = 'hr23f4S8u1aOxh5R'
This would be added by navigating to the Radar section of your Dashboard, then to the Rules tab. There will then be an Add Rule button.
The card fingerprint can be found either in your Dashboard in the card details section of a payment, or via the API by running the retrieve charge API call which returns the card fingerprint along with a whole host of additional info.
You can find that API call here:
https://stripe.com/docs/api#retrieve_charge

Custom schedule payments with Stripe

I want to handle the following use cases with Stripe:
Charge a customer on a regular schedule where the interval between charges is not a single number, e.g. charge on Tuesdays and Thursdays.
Charge the same customer at one off instances, e.g. they are regularly charged on Tuesdays and Thursdays but for this particular week, Saturday also.
Can I fulfill these use cases with Stripe without needing to generate a new token each time (i.e. take the payer's card details each time)?
You don't need a new card token each time. Card tokens are created client-side, for example via Elements. They allow you to collect card details securely client-side and then simply send the card token id (tok_1234) to your server to charge the card.
When using a token, you have two options. First, you can charge the card once using the Create Charge API. Otherwise, if you want the ability to charge the card more than once, you would save the card on a customer. This is covered in details in the documentation.
Once a card is saved on a customer, you can use the Create Charge API to charge that card. You would pass the customer id (cus_123) in the customer parameter and if you want a specific card you would also pass the card id (card_abc) in the source parameter.
You can try to charge the card as needed on days where you expect a payment. It's up to the cardholder's bank to decide if they want to let the charge go through or not.

Prevent multiple stripe trials by card details

We are looking to offer a free trial of our product with payments powered by Stripe Subscriptions.
However, what I'm not sure about is whether it is possible to prevent a user from having multiple emails by limiting it to one trial by card, similar to how sites like Netflix operate.
You can definitely do this though you have to build the logic yourself. The idea is that you can detect duplicate cards and automatically block ones you've seen before if they try to access the trial.
Stripe returns the fingerprint property on Cards. That property is a unique identifier for a given card number in your account.
This means that if I sign up today with my card and then I come back tomorrow with the same card under a different email address you'd see the same exact fingerprint on both tokens or card objects.
The idea then would be to keep track of all the card fingerprints you see in your database to detect a returning customer. Whenever a customer adds a new card you'd first look if you've seen that card fingerprint before in your database and decide to create the customer or return an error based on this.

Add a card to a user using a card id in stripe

There was a bug in our system for a few days which meant we were taking payments on Stripe but weren't joining the card to the new customer. We need the card to be attached to the customer so that we can charge them again.
Knowing only the card information from the first charge (ie card_123) is it possible for me to add the card to the customer?
From what I see, I need a token to be able to do this and to generate a token I need the raw card data.
If you created the charge directly with a card token in the source parameter, then it's not possible to retrieve the card data afterwards and attach it to a customer object.
You will have to ask your customers to provide their card information again, generate a new token, and attach this token to customer objects.

save card to customer with Stripe.js

How do I save a card to a customer with Stripe.js?
I don't want to change them at this point. I just want to save the credit card info to their stripe account so I can use it later.
It seems like I'd need to use createToken from Stipe.js. But my understanding is that this is a one time use token. I want to save the credit card info for later use.
This seems to be a similar question: Stripe Payment: Save token and customer and make payment later from token
but the solution isn't clear. I'm not sure if it means for the customer I need to save card=token and everything will work fine.
Though the question is an old one and solution of this problem is now pretty straightforward in the current Stripe API, I'm just answering for those who accidentally reached or will reach here without reading the Official Stripe Doc properly(like me) searching for this question.
To make a stripe payment You first need to make a call to the Stripe API(Using Stripe's Checkout widget, Elements or Mobile SDKs) with the User's card information. As a response, you will get a token. Then you can charge your customer immediately using Stripe's Charge API. This is for just one-time payment. You will find an example here.
If you want to save customer's information for later payment, you need to create a 'Customer' first using Stripe's API and then using that customer's ID (returned as a response from the previous API call) you can charge this customer. Example here.
I just described the process briefly to show the idea at a glance. But you should really need to read this quickstart guide in Stripe's documentation. This explains the process very well.
I just want to save the credit card info to their stripe account so I
can use it later.
Then that's exactly what you can do!
If you're already passing the token back into your server-side code, you just need to update that server-side code to retrieve the customer and create the card on that customer record using the token.
Not knowing what language you're using I can't provide relevant sample code, but the Stripe API reference has functional examples for Ruby, Python, PHP, Java, and Node.js.
Note that if the customer has any outstanding invoices, this card will be used the next time they attempt to settleā€”so while simply adding the card won't create a charge by itself, it's possible the card may still be billed.
A key point that the prior answers seems to dance around but do not explicitly state is that you can't simply save the credit card (token) in Stripe. Stripe's API's don't save credit cards per se, however, they can save a customer and attached to the customer you can save one more credit cards (or payment sources). So a credit card (or payment source) is not a stand alone entity in the Stripe storage system, it's a child entity of a Customer.

Resources