Mike.Sheen wrote:I especially liked that you create a customer in Stripe and create cards for customers also in Stripe, so you don't ever store the customer card details in Jiwa. This is the way.
You can still do this, but it's a little more involved than just creating a card for a customer.
You used to be able to pass in the JSON for a customer with embedded card details and/or add a new card to a customer:
- Code: Select all
{
"email": "[email protected]",
"source": {
"object": "card",
"cvc": "***",
"exp_month": "12",
"exp_year": "2027",
"number": "************0008"
}
}
This is no longer possible, you get this this back from Stripe:
- Code: Select all
{
"error": {
"message": "Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing.",
"type": "invalid_request_error"
}
}
Now, you need to create a "payment method" (which to be fair, in Australia includes BECS debit), for which you get a payment method 'id'. You then, in a separate transaction, attach that payment method id to a customer.
The Stripe developer page helpfully provides all the raw API data in a log for analysis (roughly):
- Code: Select all
POST /v1/customers
{
"email": "[email protected]"
}
--------------------
Response body
{
"id": "cus_L44O8GxGWoae5j",
"object": "customer",
...
==============
POST /v1/payment_methods
{
"card": {
"cvc": "***",
"exp_month": "12",
"exp_year": "2027",
"number": "************0008"
},
"type": "card"
}
--------------------
Response body
{
"id": "pm_1KNwhyBWzF2Y28hVhqoKS1Y2",
"object": "payment_method",
...
==============
POST /v1/payment_methods/pm_1KNwhyBWzF2Y28hVhqoKS1Y2/attach
{
"customer": "cus_L44O8GxGWoae5j"
}
--------------------
Response body
{
"id": "pm_1KNwhyBWzF2Y28hVhqoKS1Y2",
"object": "payment_method",
...
"card": {
...
"country": "NZ",
"exp_month": 12,
"exp_year": 2027,
...
"last4": "0008",
...
},
...
"customer": "cus_L44O8GxGWoae5j",
...
"type": "card"
}
==============
Now I'm trying to work out how to charge them...