diff --git a/.gitignore b/.gitignore index 085f12f9d..a353b8c89 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ tags /.idea *.iml -priv/plts/*.plt +priv/plts/* +/cover diff --git a/lib/stripe/subscriptions/invoice.ex b/lib/stripe/subscriptions/invoice.ex index 18acc5890..0aa8c7756 100644 --- a/lib/stripe/subscriptions/invoice.ex +++ b/lib/stripe/subscriptions/invoice.ex @@ -29,12 +29,14 @@ 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, @@ -42,19 +44,15 @@ defmodule Stripe.Invoice do 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()), @@ -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 } @@ -115,12 +124,14 @@ 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, @@ -128,19 +139,15 @@ defmodule Stripe.Invoice do :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, @@ -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 ] diff --git a/lib/stripe/subscriptions/price.ex b/lib/stripe/subscriptions/price.ex index 5e76eb7e7..6ba7fe07b 100644 --- a/lib/stripe/subscriptions/price.ex +++ b/lib/stripe/subscriptions/price.ex @@ -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", @@ -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, @@ -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 :: %{ @@ -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, @@ -106,10 +111,8 @@ defmodule Stripe.Price do :nickname, :product, :recurring, - :tax_behavior, :tiers, :tiers_mode, - :transform_lookup_key, :transform_quantity, :type, :unit_amount, @@ -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(), @@ -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()} @@ -211,4 +214,4 @@ defmodule Stripe.Price do |> cast_to_id([:product, :ending_before, :starting_after]) |> make_request() end -end \ No newline at end of file +end diff --git a/lib/stripe/types.ex b/lib/stripe/types.ex index 286998c25..b90a54801 100644 --- a/lib/stripe/types.ex +++ b/lib/stripe/types.ex @@ -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(), @@ -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(), diff --git a/lib/stripe/webhook.ex b/lib/stripe/webhook.ex index f71679c4a..024a6a743 100644 --- a/lib/stripe/webhook.ex +++ b/lib/stripe/webhook.ex @@ -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 diff --git a/test/stripe/request_test.exs b/test/stripe/request_test.exs index 156dab106..21ecc38ae 100644 --- a/test/stripe/request_test.exs +++ b/test/stripe/request_test.exs @@ -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