PiggyPot / gocardless

Elixir wrapper for the GoCardless API
7 stars 1 forks source link

Package crashes if a creditor is required #10

Open tosbourn opened 7 years ago

tosbourn commented 7 years ago

When creating items like Mandates which require a creditor to be set if your account has multiple creditors the package will crash when one isn't set.

Here is a sample call and the output

Sample Call

params = %{
  mandates: %{
    scheme: "bacs",
    links: %{
      customer_bank_account: "BA00000000",
    }
  }
}
Gocardless.Client.create_mandate(params)

Output

** (exit) exited in: GenServer.call(Gocardless.Client, {:create_mandate, %{mandates: %{links: %{customer_bank_account: "BA00000000"}, scheme: "bacs"}}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
iex(1)> [error] GenServer Gocardless.Client terminating
** (KeyError) key :body not found in: %HTTPotion.ErrorResponse{message: "req_timedout"}
    (gocardless) lib/gocardless/utils/comms.ex:31: Gocardless.Utils.Comms.decode_json/1
    (gocardless) lib/gocardless/client.ex:10: Gocardless.Client.handle_call/3
    (stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:665: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.273.0>): {:create_mandate, %{mandates: %{links: %{customer_bank_account: "BA0001V89MDYMQ"}, scheme: "bacs"}}}
State: %{}
Client #PID<0.273.0> is alive
    (iex) lib/iex/evaluator.ex:59: IEx.Evaluator.loop/3
    (iex) lib/iex/evaluator.ex:21: IEx.Evaluator.init/4
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

Adding a creditor in the links section fixes the issue.

overture8 commented 7 years ago

@tosbourn How did you get around this for testing staging? Just delete all the creditors except for one?

tosbourn commented 7 years ago

@overture8 basically yeah – I ended up just always sending a creditor and working out which one was the valid one for our purposes.

From memory you can't easily tell which creditor is which from the GoCardless dashboard, which is a shame.