beam-community / stripity-stripe

An Elixir Library for Stripe
Other
985 stars 353 forks source link

Error when trying to create customer with coupon code #580

Closed overture8 closed 4 years ago

overture8 commented 4 years ago

When I try to create a customer with the following...

Stripe.Customer.create(%{
   "email" => "myemail@email.com",
   "coupon" => "IDXXXXXX"
})

I get the error below. I've checked the Stripe API and it says coupon can be passed through (https://stripe.com/docs/api/customers/create). I've tried retrieving and passing the actual Coupon object as well - it ends up with the same error.

protocol Enumerable not implemented for %Stripe.Customer{address: nil, balance: 0, created: 
1582144447, currency: nil, default_source: nil, deleted: nil, delinquent: false, description: nil, 
discount: %Stripe.Discount{coupon: %Stripe.Coupon{amount_off: nil, created: 1582138028, 
currency: nil, deleted: nil, duration: "repeating", duration_in_months: 3, id: "IDXXXXXX", livemode: 
false, max_redemptions: nil, metadata: %{}, name: "Beta Coupon", object: "coupon", percent_off: 
50.0, redeem_by: 1582538400, times_redeemed: 3, valid: true}, customer: "cus_XXX", deleted: nil, 
end: 1589920447, object: "discount", start: 1582144447, subscription: nil}, email: 
"myemail@email.com", id: "cus_XXX", invoice_prefix: "0A0000X0", invoice_settings: 
%{custom_fields: nil, default_payment_method: nil, footer: nil}, livemode: false, metadata: %{}, 
name: nil, object: "customer", payment_method: nil, phone: nil, preferred_locales: [], shipping: nil, 
sources: %Stripe.List{data: [], has_more: false, object: "list", total_count: 0, url: "/v1/customers
/cus_XXX/sources"}, subscriptions: %Stripe.List{data: [], has_more: false, object: "list", 
total_count: 0, url: "/v1/customers/cus_XXX/subscriptions"}, tax_exempt: "none", tax_ids: 
%Stripe.List{data: [], has_more: false, object: "list", total_count: 0, url: "/v1/customers/cus_XXX
/tax_ids"}, tax_info: nil, tax_info_verification: nil} of type Stripe.Customer (a struct). This protocol is 
implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, 
DBConnection.Stream, DBConnection.PrepareStream, Timex.Interval, Floki.HTMLTree, HashSet, 
Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, 
File.Stream, IO.Stream
overture8 commented 4 years ago

Sorry, it's working exactly as expected - I was just being stupid. The error was not happening at the time of customer creation but at the point I was trying to create a Stripe.Session. I was passing the customer object to Stripe.Session.create rathern than the customer.id.