Skip to content

Commit

Permalink
updates from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jalexander committed Nov 20, 2024
1 parent 9a68614 commit 52b87e1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tags

/.idea
*.iml
priv/plts/*.plt
priv/plts/*
/cover
46 changes: 27 additions & 19 deletions lib/stripe/subscriptions/invoice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,30 @@ defmodule Stripe.Invoice do
attempt_count: non_neg_integer,
attempted: boolean,
auto_advance: boolean,
collection_method: String.t() | nil,
billing_reason: String.t() | nil,
charge: Stripe.id() | Stripe.Charge.t() | nil,
closed: boolean,
collection_method: String.t(),
collection_method: String.t() | nil,
created: Stripe.timestamp(),
currency: String.t(),
custom_fields: custom_fields() | nil,
customer: Stripe.id() | Stripe.Customer.t(),
customer_address: Stripe.Types.address() | nil,
customer_email: String.t() | nil,
customer_name: String.t() | nil,
customer_phone: String.t() | nil,
customer_shipping: Stripe.Types.shipping() | nil,
customer_tax_exempt: String.t() | nil,
customer_tax_ids: Stripe.List.t(map) | nil,
custom_fields: custom_fields() | nil,
customer: Stripe.id() | Stripe.Customer.t(),
created: Stripe.timestamp(),
default_payment_method: String.t() | nil,
default_source: String.t() | nil,
default_tax_rates: Stripe.List.t(map) | nil,
deleted: boolean | nil,
description: String.t() | nil,
discount: Stripe.Discount.t() | nil,
due_date: Stripe.timestamp() | nil,
ending_balance: integer | nil,
finalized_at: Stripe.timestamp() | nil,
footer: String.t() | nil,
forgiven: boolean,
hosted_invoice_url: String.t() | nil,
invoice_pdf: String.t() | nil,
lines: Stripe.List.t(Stripe.LineItem.t()),
Expand All @@ -74,12 +72,23 @@ defmodule Stripe.Invoice do
status: String.t() | nil,
status_transitions: status_transitions() | nil,
subscription: Stripe.id() | Stripe.Subscription.t() | nil,
subscription_proration_date: Stripe.timestamp(),
subscription_proration_date: Stripe.timestamp() | nil,
subtotal: integer,
tax: integer | nil,
tax_percent: number | nil,
total_tax_amounts: Stripe.List.t(map) | nil,
threshold_reason:
nil
| %{
amount_gte: integer,
item_reasons: [
%{
line_item_ids: [String.t()],
usage_gte: integer
}
]
},
total: integer,
total_tax_amounts: Stripe.List.t(map) | nil,
webhooks_delivered_at: Stripe.timestamp() | nil
}

Expand Down Expand Up @@ -115,32 +124,30 @@ defmodule Stripe.Invoice do
:attempt_count,
:attempted,
:auto_advance,
:collection_method,
:billing_reason,
:charge,
:closed,
:created,
:collection_method,
:created,
:currency,
:custom_fields,
:customer,
:customer_address,
:customer_email,
:customer_name,
:customer_phone,
:customer_shipping,
:customer_tax_exempt,
:customer_tax_ids,
:currency,
:custom_fields,
:customer,
:default_payment_method,
:default_source,
:default_tax_rates,
:deleted,
:description,
:discount,
:due_date,
:ending_balance,
:finalized_at,
:footer,
:forgiven,
:hosted_invoice_url,
:invoice_pdf,
:lines,
Expand All @@ -155,17 +162,18 @@ defmodule Stripe.Invoice do
:post_payment_credit_notes_amount,
:pre_payment_credit_notes_amount,
:receipt_number,
:status,
:status_transitions,
:starting_balance,
:statement_descriptor,
:status,
:status_transitions,
:subscription,
:subscription_proration_date,
:subtotal,
:tax,
:tax_percent,
:total_tax_amounts,
:threshold_reason,
:total,
:total_tax_amounts,
:webhooks_delivered_at
]

Expand Down
29 changes: 16 additions & 13 deletions lib/stripe/subscriptions/price.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
defmodule Stripe.Price do
@moduledoc """
Work with Stripe price objects.
The Prices API adds more flexibility to how you charge customers.
It also replaces the Plans API, so Stripe recommends migrating your existing
integration to work with prices.
To migrate, you need to identify how you use plans, products, and payment
flows and then update these parts of your integration to use the Prices API.
Migrating to Prices guide: https://stripe.com/docs/billing/migration/migrating-prices
You can:
- Create a price
- Retrieve a price
- Update a price
- List all prices
Stripe API reference: https://stripe.com/docs/api/prices
Example:
```
{
"id": "plan_HJ8MK9HTYgniMM",
Expand All @@ -34,10 +43,8 @@ defmodule Stripe.Price do
"trial_period_days": null,
"usage_type": "licensed"
},
"tax_behavior": "unspecified",
"tiers": null,
"tiers_mode": null,
"transform_lookup_key": false,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 999,
Expand All @@ -50,11 +57,11 @@ defmodule Stripe.Price do
import Stripe.Request

@type recurring :: %{
optional(:aggregate_usage) => String.t(),
optional(:interval) => String.t(),
optional(:interval_count) => pos_integer,
optional(:trial_period_days) => pos_integer,
optional(:usage_type) => String.t()
aggregate_usage: String.t(),
interval: String.t(),
interval_count: pos_integer,
trial_period_days: pos_integer,
usage_type: String.t()
}

@type price_tier :: %{
Expand Down Expand Up @@ -83,10 +90,8 @@ defmodule Stripe.Price do
nickname: String.t(),
product: Stripe.id() | Stripe.Product.t(),
recurring: recurring(),
tax_behavior: String.t(),
tiers: [price_tier()],
tiers_mode: String.t(),
transform_lookup_key: boolean(),
transform_quantity: transform_quantity(),
type: String.t(),
unit_amount: pos_integer,
Expand All @@ -106,10 +111,8 @@ defmodule Stripe.Price do
:nickname,
:product,
:recurring,
:tax_behavior,
:tiers,
:tiers_mode,
:transform_lookup_key,
:transform_quantity,
:type,
:unit_amount,
Expand All @@ -132,7 +135,6 @@ defmodule Stripe.Price do
optional(:nickname) => String.t(),
optional(:product) => Stripe.id() | Stripe.Product.t(),
optional(:recurring) => recurring(),
optional(:tax_behavior) => String.t(),
optional(:tiers) => [price_tier()],
optional(:tiers_mode) => String.t(),
optional(:billing_scheme) => String.t(),
Expand Down Expand Up @@ -164,6 +166,7 @@ defmodule Stripe.Price do

@doc """
Update a price.
Takes the `id` and a map of changes.
"""
@spec update(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
Expand Down Expand Up @@ -211,4 +214,4 @@ defmodule Stripe.Price do
|> cast_to_id([:product, :ending_before, :starting_after])
|> make_request()
end
end
end
3 changes: 0 additions & 3 deletions lib/stripe/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ defmodule Stripe.Types do
reset_billing_cycle_anchor: boolean | nil
}

<<<<<<< HEAD
@type tax :: %{
automatic_tax: String.t(),
ip_address: String.t(),
Expand All @@ -79,8 +78,6 @@ defmodule Stripe.Types do
verified_name: String.t() | nil
}

=======
>>>>>>> dc49e40 (Stripe API 2019-12-03 Remove deprecated Customer tax_info)
@type transfer_schedule :: %{
delay_days: non_neg_integer,
interval: String.t(),
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/webhook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule Stripe.Webhook do
end

defp compute_signature(payload, secret) do
:crypto.mac(:hmac, :sha256, secret, payload)
hmac(:sha256, secret, payload)
|> Base.encode16(case: :lower)
end

Expand Down
6 changes: 3 additions & 3 deletions test/stripe/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ defmodule Stripe.RequestTest do

describe "new_request/2" do
test "new_request/1 extracts headers from options and puts it on headers" do
new_request = Request.new_request([headers: %{foo: "bar"}])
new_request = Request.new_request(headers: %{foo: "bar"})

assert new_request.headers == %{
foo: "bar"
}
foo: "bar"
}
end
end
end

0 comments on commit 52b87e1

Please sign in to comment.