taekni taekni - 1 year ago 148
PHP Question

stripe api checking for existing card

I'm sure I'm missing something obvious here, but I can't get my head around how to check for an existing card against a customer.

I'm using the stripe connect api within an laravel app to manage payments on behalf of others, and the basic process is as follows:

  • a stripe
    is created via
    and submitted with the payment form

  • if the customer exists in the local database, I grab their
    , otherwise a new customer is created using the token as the source/card

  • a
    is then created using the retrieved or new customer

Currently, if the customer returns and uses a different card, as the charge only includes a customer, not source, it'll be charged against their default card regardless.

What I'd like to do is:

  • create a stripe

  • check
    against local database etc

  • check
    fingerprint against customer's cards

  • if necessary, create new
    on customer's record

  • create charge using both

Simply put: I can't see where in the process a persistent
is generated; both those used in the
response, and when created in the stripe dashboard, appear to be unique, meaning every charge creates a brand-new card object in stripe.

I know I can retrieve a list of cards stored against a customer's account - but where do I get the initial
from to search against?

I've seen a question that touches on this here - Can I check whether stripe a card is already existed before going to create new one? - but I don't know Ruby, so can't make head nor tail of it.


Simpler version - is there a way to get the
as described in the stripe docs here - https://stripe.com/docs/api/php#card_object - without having to first create a card object ?

Answer Source

So the idea here would be to use the fingerprint on the Card object or the Token object and not the id itself as those would be different if you add the same card multiple times.

When you get a new card token you can retrieve it through the Retrieve Token API and look for the fingerprint in the card hash.

You would keep a list of known fingerprints in your database associated with a specific customer and/or card so that you can detect duplicate cards.

NOTE: make sure you are using the secret keys to get those information. otherwise if you are using the publishable key, you might not get the fingerprint value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download