Skip to content

Commit

Permalink
Add first_subscription_item to Subscriptions. Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
PJUllrich committed Jan 6, 2024
1 parent ff20ae8 commit d3fe344
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.2.2

* Add `first_subscription_item` to Subscriptions

## v0.2.1

* Set all dependencies to version `>= 0.0.0` to prevent version conflicts with applications that use the library.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An Elixir client for the API and Webhooks of LemonSqueezy.
```elixir
def deps do
[
{:lemon_ex, "~> 0.2.1"}
{:lemon_ex, "~> 0.2.2"}
]
end
```
Expand Down
17 changes: 17 additions & 0 deletions lib/lemon_ex/subscriptions/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule LemonEx.Subscriptions.Subscription do
:cancelled,
:trial_ends_at,
:billing_anchor,
:first_subscription_item,
:urls,
:renews_at,
:ends_at,
Expand Down Expand Up @@ -48,6 +49,7 @@ defmodule LemonEx.Subscriptions.Subscription do
pause: attributes["pause"],
cancelled: attributes["cancelled"],
billing_anchor: attributes["billing_anchor"],
first_subscription_item: first_subscription_item(attributes),
trial_ends_at: attributes["trial_ends_at"],
urls: %{
update_payment_method: urls["update_payment_method"],
Expand All @@ -62,4 +64,19 @@ defmodule LemonEx.Subscriptions.Subscription do
card_last_four: attributes["card_last_four"]
}
end

defp first_subscription_item(%{"first_subscription_item" => nil}) do
nil
end

defp first_subscription_item(%{"first_subscription_item" => item}) do
%{
id: item["id"],
subscription_id: item["subscription_id"],
price_id: item["price_id"],
quantity: item["quantity"],
created_at: item["created_at"],
updated_at: item["updated_at"]
}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LemonEx.MixProject do
use Mix.Project

@version "0.2.1"
@version "0.2.2"
@source_url "https://github.com/PJUllrich/lemon_ex"

def project do
Expand Down
23 changes: 20 additions & 3 deletions test/lemon_ex/subscriptions/subscriptions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ defmodule LemonEx.SubscriptionsTest do
import Support.Fixtures, only: [load_json: 1]

test "list" do
with_mock HTTPoison, get: succesful_response("api/v1/subscriptions_list") do
with_mock HTTPoison, get: successful_response("api/v1/subscriptions_list") do
assert LemonEx.Subscriptions.list() == expected_subscription_list()
end
end

test "get" do
with_mock HTTPoison, get: succesful_response("api/v1/subscriptions_get") do
with_mock HTTPoison, get: successful_response("api/v1/subscriptions_get") do
assert LemonEx.Subscriptions.get(169_590) == expected_subscription()
end
end

defp succesful_response(json_file) do
defp successful_response(json_file) do
fn _url, _params, _headers ->
{:ok,
%HTTPoison.Response{
Expand Down Expand Up @@ -59,6 +59,7 @@ defmodule LemonEx.SubscriptionsTest do
cancelled: false,
trial_ends_at: nil,
billing_anchor: 27,
first_subscription_item: nil,
urls: %{
customer_portal:
"https:\\/\\/mystore.lemonsqueezy.com\\/billing?expires=1698434430&user=1461055&signature=27b0921cc4b6a37bc5caed624bc5dbaa44d374e26e892544421668561b8ff0f5",
Expand Down Expand Up @@ -91,6 +92,14 @@ defmodule LemonEx.SubscriptionsTest do
cancelled: false,
trial_ends_at: nil,
billing_anchor: 27,
first_subscription_item: %{
id: 132_211,
subscription_id: 169_586,
price_id: 127_630,
quantity: 1,
created_at: "2023-10-27T07:27:30.000000Z",
updated_at: "2023-10-27T07:27:30.000000Z"
},
urls: %{
customer_portal:
"https:\\/\\/mystore.lemonsqueezy.com\\/billing?expires=1698434430&user=1461055&signature=27b0921cc4b6a37bc5caed624bc5dbaa44d374e26e892544421668561b8ff0f5",
Expand Down Expand Up @@ -129,6 +138,14 @@ defmodule LemonEx.SubscriptionsTest do
cancelled: false,
trial_ends_at: nil,
billing_anchor: 27,
first_subscription_item: %{
id: 132_215,
subscription_id: 169_590,
price_id: 127_630,
quantity: 1,
created_at: "2023-10-27T07:32:24.000000Z",
updated_at: "2023-10-27T07:32:24.000000Z"
},
urls: %{
customer_portal:
"https://mystore.lemonsqueezy.com/billing?expires=1698445809&user=1461055&signature=d0accab17db6cd5fbd9243dd5b57afd131972d61ad81284d26b0dbfcc5e91119",
Expand Down
43 changes: 21 additions & 22 deletions test/support/fixtures/api/v1/subscriptions_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0"
},
"links": {
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590"
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590"
},
"data": {
"type": "subscriptions",
Expand Down Expand Up @@ -32,13 +32,12 @@
"subscription_id": 169590,
"price_id": 127630,
"quantity": 1,
"is_usage_based": false,
"created_at": "2023-10-27T07:32:24.000000Z",
"updated_at": "2023-10-27T07:32:24.000000Z"
},
"urls": {
"update_payment_method": "https:\/\/mystore.lemonsqueezy.com\/subscription\/169590\/payment-details?expires=1698510609&signature=09c4d3759f6e0c5124e3ab9714e0c87ba0a9ca3f19d73d30c8f81622ac15d9f2",
"customer_portal": "https:\/\/mystore.lemonsqueezy.com\/billing?expires=1698445809&user=1461055&signature=d0accab17db6cd5fbd9243dd5b57afd131972d61ad81284d26b0dbfcc5e91119"
"update_payment_method": "https://mystore.lemonsqueezy.com/subscription/169590/payment-details?expires=1698510609&signature=09c4d3759f6e0c5124e3ab9714e0c87ba0a9ca3f19d73d30c8f81622ac15d9f2",
"customer_portal": "https://mystore.lemonsqueezy.com/billing?expires=1698445809&user=1461055&signature=d0accab17db6cd5fbd9243dd5b57afd131972d61ad81284d26b0dbfcc5e91119"
},
"renews_at": "2023-11-27T07:32:22.000000Z",
"ends_at": null,
Expand All @@ -49,55 +48,55 @@
"relationships": {
"store": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/store",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/store"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/store",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/store"
}
},
"customer": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/customer",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/customer"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/customer",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/customer"
}
},
"order": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/order",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/order"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/order",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/order"
}
},
"order-item": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/order-item",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/order-item"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/order-item",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/order-item"
}
},
"product": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/product",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/product"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/product",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/product"
}
},
"variant": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/variant",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/variant"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/variant",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/variant"
}
},
"subscription-items": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/subscription-items",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/subscription-items"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/subscription-items",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/subscription-items"
}
},
"subscription-invoices": {
"links": {
"related": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/subscription-invoices",
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590\/relationships\/subscription-invoices"
"related": "https://api.lemonsqueezy.com/v1/subscriptions/169590/subscription-invoices",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590/relationships/subscription-invoices"
}
}
},
"links": {
"self": "https:\/\/api.lemonsqueezy.com\/v1\/subscriptions\/169590"
"self": "https://api.lemonsqueezy.com/v1/subscriptions/169590"
}
}
}
}
13 changes: 2 additions & 11 deletions test/support/fixtures/api/v1/subscriptions_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@
"cancelled": false,
"trial_ends_at": null,
"billing_anchor": 27,
"first_subscription_item": {
"id": 132215,
"subscription_id": 169590,
"price_id": 127630,
"quantity": 1,
"is_usage_based": false,
"created_at": "2023-10-27T07:32:24.000000Z",
"updated_at": "2023-10-27T07:32:24.000000Z"
},
"first_subscription_item": null,
"urls": {
"update_payment_method": "https:\\/\\/mystore.lemonsqueezy.com\\/subscription\\/169590\\/payment-details?expires=1698499230&signature=18cbb5bfc703292df67d0f3528e533e396115096a404bb1876c895805956a959",
"customer_portal": "https:\\/\\/mystore.lemonsqueezy.com\\/billing?expires=1698434430&user=1461055&signature=27b0921cc4b6a37bc5caed624bc5dbaa44d374e26e892544421668561b8ff0f5"
Expand Down Expand Up @@ -139,7 +131,6 @@
"subscription_id": 169586,
"price_id": 127630,
"quantity": 1,
"is_usage_based": false,
"created_at": "2023-10-27T07:27:30.000000Z",
"updated_at": "2023-10-27T07:27:30.000000Z"
},
Expand Down Expand Up @@ -208,4 +199,4 @@
}
}
]
}
}
10 changes: 9 additions & 1 deletion test/support/fixtures/subscription_created_event.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
"order_item_id": 1,
"trial_ends_at": null,
"billing_anchor": 14,
"first_subscription_item": {
"id": 1,
"subscription_id": 1,
"price_id": 1,
"quantity": 5,
"created_at": "2021-08-11T13:47:28.000000Z",
"updated_at": "2021-08-11T13:47:28.000000Z"
},
"card_last_four": "4242",
"status_formatted": "Active"
},
Expand Down Expand Up @@ -86,4 +94,4 @@
}
}
}
}
}

0 comments on commit d3fe344

Please sign in to comment.