mattsta / stripe-erlang

Erlang interface to the stripe.com API
27 stars 23 forks source link

Error in shell testing #18

Closed mudyc closed 7 years ago

mudyc commented 7 years ago

4> rr(stripe). [stripe_bank_account,stripe_card,stripe_charge, stripe_coupon,stripe_customer,stripe_discount,stripe_error, stripe_event,stripe_invoiceitem,stripe_list,stripe_plan, stripe_recipient,stripe_subscription,stripe_token, stripe_transfer] 5> #stripe_token{id = Token} = stripe:token_create("4242424242424242", 12, 2021, 123, [], [], [], [], [], []).

However I can run it like this:

Token = stripe:token_create("4242424242424242", 12, 2021, 123, [], [], [], [], [], []).

stripe_token{id = <<"tok_19VEzV2eZvKYlo2CTbqtxQy0">>,

          used = false,livemode = false,type = undefined,
          bank_account = <<"Not Returned by API">>,
          card = #stripe_card{name = null,last4 = <<"4242">>,
                              exp_year = 2021,exp_month = 12,brand = <<"Visa">>,
                              cvc_check = unchecked,address_line1_check = null,
                              address_zip_check = null,country = <<"US">>}}

But then:

io:format("~p", [Token#stripe_token.id]).

  • 251: record stripe_bank_account undefined
mudyc commented 7 years ago

http://erlang.org/doc/reference_manual/typespec.html Before Erlang/OTP 19, for fields without initial values, the singleton type 'undefined' was added to all declared types.

mattsta commented 7 years ago

How do you cause the error? Erlang's type system isn't enforced anywhere at runtime, so it can't complain about bad types. If records are undefined, that's some other problem since all records for stripe-erlang are defined in the same stripe.hrl header include.

You can run the built-in tests with rebar eunit too.

Works fine for me in a 19.2 shell.

8> rr(stripe).
[stripe_bank_account,stripe_card,stripe_charge,
 stripe_coupon,stripe_customer,stripe_discount,stripe_error,
 stripe_event,stripe_invoiceitem,stripe_list,stripe_plan,
 stripe_recipient,stripe_subscription,stripe_token,
 stripe_transfer]
9> #stripe_token{}.
#stripe_token{id = undefined,used = undefined,
              livemode = undefined,type = undefined,
              bank_account = undefined,card = undefined}
10>  #stripe_token{id = Token} = stripe:token_create("4242424242424242", 12, 2021, 123, [], [], [], [], [], []).
#stripe_token{id = <<"tok_19VMdA2eZvKYlo2Cp2Ios1AD">>,
              used = false,livemode = false,type = undefined,
              bank_account = <<"Not Returned by API">>,
              card = #stripe_card{name = null,last4 = <<"4242">>,
                                  exp_year = 2021,exp_month = 12,brand = <<"Visa">>,
                                  cvc_check = unchecked,address_line1_check = null,
                                  address_zip_check = null,country = <<"US">>}}
mudyc commented 7 years ago

Well I added stripe-erlang as dependency to my mad (rebar replacement) project and started playing around. It says "Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] Eshell V8.0"

9> #stripe_token{}.

And I added the 'undefined' to type definition but it didn't help either. 251 refers to stripe.hrl where stripe_token has stripe_bank_account.

mattsta commented 7 years ago

But, stripe_bank_account is defined in the same stripe.hrl before stripe_token, so how can it not exist? Sounds like a configuration or environment problem, not really a project problem. Your system must be (somehow?) selectively including records instead of importing the entire header at once?

mudyc commented 7 years ago

I upgraded from 19.0 to 19.1 and this started to work!