aviabird / gringotts

A complete payment library for Elixir and Phoenix Framework
https://hexdocs.pm/gringotts/Gringotts.html
MIT License
481 stars 53 forks source link

Stripe Gateway: "Must provide source or customer." #183

Open danieljaouen opened 4 years ago

danieljaouen commented 4 years ago

I am trying to use the Stripe gateway. However, I am seeing an error that I cannot resolve:

no case clause matching: %{"error" => %{"code" => "parameter_missing", "doc_url" => "https://stripe.com/docs/error-codes/parameter-missing", "message" => "Must provide source or customer.", "type" => "invalid_request_error"}}

It seems to revolve around this Must provide source or customer. error.

Any help?

danieljaouen commented 4 years ago

I've gotten a bit further with this issue. Apparently Gringotts.store returns a map containing an id for a customer, but it doesn't save the card it was called with (the cards entry in the returned map has %{"count" => 0}.

The error I see now is: Cannot charge a customer that has no active card

As far as I can tell, Gringotts.store is storing neither the credit card nor the address I'm feeding into it. Is this a bug?

danieljaouen commented 4 years ago

Ideally, Gringotts.store would store both the credit card (as the customer's default) and the address in a new customer, and Gringotts.unstore would fetch the customer_id, the credit card, and the address (perhaps in a map?), and then subsequently delete the customer via Stripe's API.

Then Gringotts.authorize and Gringotts.capture would just take an additional [customer: customer_id] in the opts list.