Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove customer from params typespec in CustomerBalanceTransaction.create #662

Merged

Conversation

ascandella
Copy link
Contributor

@ascandella ascandella commented Apr 28, 2021

Prior to this PR, the only valid way to use this function would return a dialyzer error.

It's invalid to pass the customer ID as both part of the URL (which
this function does) and in the body. Doing so leads to a Stripe
error:

iex(1)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD", customer: "cus_JO4D6sa5xl4Uk7"})
{:error,
 %Stripe.Error{
   code: :invalid_request_error,
   extra: %{
     http_status: 400,
     param: :customer,
     raw_error: %{
       "message" => "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
       "param" => "customer",
       "type" => "invalid_request_error"
     }
   },
   message: "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
   request_id: nil,
   source: :stripe,
   user_message: nil
 }}

Whereas passing it as the first (required) positional argument works
fine:

iex(2)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD"})
{:ok,
 %Stripe.CustomerBalanceTransaction{
   amount: -100,
   created: 1619635421,
   credit_note: nil,
   currency: "usd",
   customer: "cus_JO4D6sa5xl4Uk7",
   description: nil,
   ending_balance: -100,
   id: "cbtxn_1IlIMLFvgMYR2X5ykmdTnR5H",
   invoice: nil,
   livemode: false,
   metadata: %{},
   object: "customer_balance_transaction",
   type: "adjustment"
 }}

(the customer here is a throwaway user in my test account)

It's invalid to pass the `customer` key as both part of the URL (which
this function does) *and* in the body. Doing so leads to a Stripe
error:

```
iex(1)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD", customer: "cus_JO4D6sa5x
l4Uk7"})
{:error,
 %Stripe.Error{
   code: :invalid_request_error,
   extra: %{
     http_status: 400,
     param: :customer,
     raw_error: %{
       "message" => "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
       "param" => "customer",
       "type" => "invalid_request_error"
     }
   },
   message: "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
   request_id: nil,
   source: :stripe,
   user_message: nil
 }}
```

Whereas passing it as the first (required) positional argument works
fine:

```
iex(2)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD"})
{:ok,
 %Stripe.CustomerBalanceTransaction{
   amount: -100,
   created: 1619635421,
   credit_note: nil,
   currency: "usd",
   customer: "cus_JO4D6sa5xl4Uk7",
   description: nil,
   ending_balance: -100,
   id: "cbtxn_1IlIMLFvgMYR2X5ykmdTnR5H",
   invoice: nil,
   livemode: false,
   metadata: %{},
   object: "customer_balance_transaction",
   type: "adjustment"
 }}
```
@ascandella ascandella changed the title Remove customer from typespec in CustomerBalanceTransaction.create Remove customer from params typespec in CustomerBalanceTransaction.create Apr 28, 2021
@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.712% when pulling 8e42df6 on ascandella:fix-customer-balance-typespec into ce0f23f on code-corps:master.

Copy link
Collaborator

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@snewcomer snewcomer merged commit 30061d7 into beam-community:master May 10, 2021
jalexander pushed a commit to Frameio/stripity_stripe that referenced this pull request Nov 20, 2024
…eam-community#662)

It's invalid to pass the `customer` key as both part of the URL (which
this function does) *and* in the body. Doing so leads to a Stripe
error:

```
iex(1)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD", customer: "cus_JO4D6sa5x
l4Uk7"})
{:error,
 %Stripe.Error{
   code: :invalid_request_error,
   extra: %{
     http_status: 400,
     param: :customer,
     raw_error: %{
       "message" => "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
       "param" => "customer",
       "type" => "invalid_request_error"
     }
   },
   message: "A parameter provided in the URL (customer) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
   request_id: nil,
   source: :stripe,
   user_message: nil
 }}
```

Whereas passing it as the first (required) positional argument works
fine:

```
iex(2)> Stripe.CustomerBalanceTransaction.create("cus_JO4D6sa5xl4Uk7", %{amount: -100, currency: "USD"})
{:ok,
 %Stripe.CustomerBalanceTransaction{
   amount: -100,
   created: 1619635421,
   credit_note: nil,
   currency: "usd",
   customer: "cus_JO4D6sa5xl4Uk7",
   description: nil,
   ending_balance: -100,
   id: "cbtxn_1IlIMLFvgMYR2X5ykmdTnR5H",
   invoice: nil,
   livemode: false,
   metadata: %{},
   object: "customer_balance_transaction",
   type: "adjustment"
 }}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants