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.
Related
I am working on an application where payments are handled by stripe. Customers are from 2 different countries.
stripe.js is used on the client side. stripe-php library is used on the back-end to charge the customer after stripe.js posts to the back-end page.
Is there a way to detect the country of the card the customer is using so that I can use the corresponding currency in the back-end call charging the customer?
Thanks
You can get a card's country of issue from a Stripe token response that comes from Stripe.js or Checkout. In addition to the token id this includes a card object with the properties like the card brand and country.
When you call stripe.createToken take a look at the token object in the response, e.g. result.token.card.country
The token object also contains a "client_ip" property that can be helpful for deciding if you want to process a charge given a particular IP address / locale derived from that. https://stripe.com/docs/api#token_object
Beyond trying to determine locale from card data or ip address, you could simply ask the user which currency they would like to be billed in, giving some additional flexiblity
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.
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.
I want to make sure the card the customer has entered is actually a valid card. Stripe.js only validates its format, it doesn't ask for an authorization from the card issuer. But it seems Stripe requires you to create the customer to authorize the card, but this is a bit silly since the logical flow should be this:
Validate form input via stripe.js, and obtain token if format is valid
Authorize token via backend API (PHP/Ruby etc)
If authorized, create card + customer using token, add subscription/charge customer
If NOT authorized, return to form with appropriate error, and do not create the customer/charge.
How do you actually achieve this in Stripe? Is there a dedicated Stripe\Card::authorize($token) method or something similar that can be used?
When you save a card to a customer Stripe does a $0/$1 authorization on the card. You can pass the card when you create the customer, and the customer would only get created if the authorization succeeds. In addition, you can specify the plan and card when creating the customer, the customer and subscription would only get created if the card is valid AND the charge for the first period of the subscription goes through.
the scenario you describe is covered here:
https://stripe.com/docs/charges#auth-and-capture
api is here (also available in php/java/go/node/curl)
https://stripe.com/docs/api/ruby#create_charge
During Stripe OAuth, I'm trying to create myself as a customer for my users such that I can pay them with my own credit card.
I've gotten 2 error messages when using Stripe's CreateCustomer API call:
When manually entering my card info as a "dictionary" (in PHP, i.e., array).
OAuth based requests must use card tokens from Stripe.js, but card details were directly provided.
When generating a card token first and feeding that instead into CreateCustomer()
Your card was declined.
Is creating myself as a customer for other Stripe users not possible?