Skip to content

Commit

Permalink
Merge pull request #11 from webtaken/update-subscriptions-object
Browse files Browse the repository at this point in the history
Updated subscriptions object
  • Loading branch information
AchoArnold authored Sep 5, 2023
2 parents 8d8f3cf + 2d85b57 commit 06c57de
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 26 deletions.
119 changes: 119 additions & 0 deletions internal/stubs/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func SubscriptionGetResponse() []byte {
"id": "1",
"attributes": {
"store_id": 1,
"customer_id": 1,
"order_id": 1,
"order_item_id": 1,
"product_id": 1,
Expand All @@ -25,10 +26,20 @@ func SubscriptionGetResponse() []byte {
"user_email": "[email protected]",
"status": "active",
"status_formatted": "Active",
"card_brand": "visa",
"card_last_four": "42424",
"pause": null,
"cancelled": false,
"trial_ends_at": null,
"billing_anchor": 12,
"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"
},
"urls": {
"update_payment_method": "https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413"
},
Expand All @@ -45,6 +56,12 @@ func SubscriptionGetResponse() []byte {
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store"
}
},
"customer": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer"
}
},
"order": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/order",
Expand All @@ -68,6 +85,18 @@ func SubscriptionGetResponse() []byte {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/variant",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant"
}
},
"subscription-items": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-items",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-items"
}
},
"subscription-invoices": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-invoices",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-invoices"
}
}
},
"links": {
Expand All @@ -93,6 +122,7 @@ func SubscriptionUpdateResponse() []byte {
"id": "1",
"attributes": {
"store_id": 1,
"customer_id": 1,
"order_id": 1,
"order_item_id": 1,
"product_id": 9,
Expand All @@ -107,6 +137,14 @@ func SubscriptionUpdateResponse() []byte {
"cancelled": false,
"trial_ends_at": null,
"billing_anchor": 29,
"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"
},
"urls": {
"update_payment_method": "https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413"
},
Expand Down Expand Up @@ -148,6 +186,7 @@ func SubscriptionsListResponse() []byte {
"id":"1",
"attributes":{
"store_id":1,
"customer_id": 1,
"order_id":1,
"order_item_id":1,
"product_id":1,
Expand All @@ -162,6 +201,14 @@ func SubscriptionsListResponse() []byte {
"cancelled":false,
"trial_ends_at":null,
"billing_anchor":12,
"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"
},
"urls":{
"update_payment_method":"https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413"
},
Expand All @@ -178,6 +225,12 @@ func SubscriptionsListResponse() []byte {
"self":"https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store"
}
},
"customer": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer"
}
},
"order":{
"links":{
"related":"https://api.lemonsqueezy.com/v1/subscriptions/1/order",
Expand All @@ -201,6 +254,18 @@ func SubscriptionsListResponse() []byte {
"related":"https://api.lemonsqueezy.com/v1/subscriptions/1/variant",
"self":"https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant"
}
},
"subscription-items": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-items",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-items"
}
},
"subscription-invoices": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-invoices",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-invoices"
}
}
},
"links":{
Expand All @@ -212,6 +277,7 @@ func SubscriptionsListResponse() []byte {
"id":"2",
"attributes":{
"store_id":2,
"customer_id": 2,
"order_id":2,
"order_item_id":2,
"product_id":2,
Expand All @@ -226,6 +292,14 @@ func SubscriptionsListResponse() []byte {
"cancelled":false,
"trial_ends_at":null,
"billing_anchor":13,
"first_subscription_item": {
"id": 2,
"subscription_id": 2,
"price_id": 2,
"quantity": 5,
"created_at": "2021-08-11T13:47:28.000000Z",
"updated_at": "2021-08-11T13:47:28.000000Z"
},
"urls":{
"update_payment_method":"https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413"
},
Expand All @@ -242,6 +316,12 @@ func SubscriptionsListResponse() []byte {
"self":"https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store"
}
},
"customer": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer"
}
},
"order":{
"links":{
"related":"https://api.lemonsqueezy.com/v1/subscriptions/1/order",
Expand All @@ -265,6 +345,18 @@ func SubscriptionsListResponse() []byte {
"related":"https://api.lemonsqueezy.com/v1/subscriptions/1/variant",
"self":"https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant"
}
},
"subscription-items": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-items",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-items"
}
},
"subscription-invoices": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-invoices",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-invoices"
}
}
},
"links":{
Expand All @@ -291,6 +383,7 @@ func SubscriptionCancelResponse() []byte {
"id": "1",
"attributes": {
"store_id": 1,
"customer_id": 1,
"order_id": 1,
"order_item_id": 1,
"product_id": 1,
Expand All @@ -305,6 +398,14 @@ func SubscriptionCancelResponse() []byte {
"cancelled": true,
"trial_ends_at": null,
"billing_anchor": 12,
"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"
},
"urls": {
"update_payment_method": "https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413"
},
Expand All @@ -321,6 +422,12 @@ func SubscriptionCancelResponse() []byte {
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store"
}
},
"customer": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/customer",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/customer"
}
},
"order": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/order",
Expand All @@ -344,6 +451,18 @@ func SubscriptionCancelResponse() []byte {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/variant",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant"
}
},
"subscription-items": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-items",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-items"
}
},
"subscription-invoices": {
"links": {
"related": "https://api.lemonsqueezy.com/v1/subscriptions/1/subscription-invoices",
"self": "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/subscription-invoices"
}
}
},
"links": {
Expand Down
1 change: 1 addition & 0 deletions subscription_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lemonsqueezy
import "time"

// SubscriptionInvoiceAttributes is the invoice for a subscription
// https://docs.lemonsqueezy.com/api/subscription-invoices#the-subscription-invoice-object
type SubscriptionInvoiceAttributes struct {
StoreID int `json:"store_id"`
SubscriptionID int `json:"subscription_id"`
Expand Down
39 changes: 39 additions & 0 deletions subscription_items.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package lemonsqueezy

import "time"

// In Lemon Squeezy A subscription item is an object that links a price to a subscription and also contains quantity information.
// https://docs.lemonsqueezy.com/api/subscription-items#the-subscription-item-object
type SubscriptionItem struct {
ID int `json:"id"`
SubscriptionID int `json:"subscription_id"`
PriceID int `json:"price_id"`
Quantity int `json:"quantity"`
IsUsageBased bool `json:"is_usage_based"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

// SubscriptionUpdateParams are parameters for updating a subscription
type SubscriptionItemUpdateParams struct {
ID string `json:"id"`
Attributes SubscriptionItemUpdateParamsAttributes `json:"attributes"`
}

// SubscriptionUpdateParamsAttributes are subscription update attributes
type SubscriptionItemUpdateParamsAttributes struct {
Quantity int `json:"quantity,omitempty"`
}

// ApiResponseRelationshipsSubscription relationships of a subscription object
type ApiResponseRelationshipsSubscriptionItem struct {
Subscription ApiResponseLinks `json:"subscription"`
Price ApiResponseLinks `json:"price"`
UsageRecords ApiResponseLinks `json:"usage-records"`
}

// SubscriptionItemApiResponse represents a subscription item api response
type SubscriptionItemApiResponse = ApiResponse[SubscriptionItem, ApiResponseRelationshipsSubscriptionItem]

// SubscriptionItemsApiResponse represents a list of subscription items api responses
type SubscriptionItemsApiResponse = ApiResponseList[SubscriptionItem, ApiResponseRelationshipsSubscriptionItem]
59 changes: 33 additions & 26 deletions subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ import "time"
// Subscription is created when a subscription product is purchased and will bill the customer on a recurring basis.
// https://docs.lemonsqueezy.com/api/subscriptions#the-subscription-object
type Subscription struct {
StoreID int `json:"store_id"`
OrderID int `json:"order_id"`
OrderItemID int `json:"order_item_id"`
ProductID int `json:"product_id"`
VariantID int `json:"variant_id"`
ProductName string `json:"product_name"`
VariantName string `json:"variant_name"`
UserName string `json:"user_name"`
UserEmail string `json:"user_email"`
Status string `json:"status"`
StatusFormatted string `json:"status_formatted"`
Pause *SubscriptionPause `json:"pause"`
Cancelled bool `json:"cancelled"`
TrialEndsAt *time.Time `json:"trial_ends_at"`
BillingAnchor int `json:"billing_anchor"`
Urls SubscriptionURLs `json:"urls"`
RenewsAt time.Time `json:"renews_at"`
EndsAt *time.Time `json:"ends_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
TestMode bool `json:"test_mode"`
StoreID int `json:"store_id"`
CustomerID int `json:"customer_id"`
OrderID int `json:"order_id"`
OrderItemID int `json:"order_item_id"`
ProductID int `json:"product_id"`
VariantID int `json:"variant_id"`
ProductName string `json:"product_name"`
VariantName string `json:"variant_name"`
UserName string `json:"user_name"`
UserEmail string `json:"user_email"`
Status string `json:"status"`
StatusFormatted string `json:"status_formatted"`
CardBrand string `json:"card_brand"`
CardLastFour string `json:"card_last_four"`
Pause *SubscriptionPause `json:"pause"`
Cancelled bool `json:"cancelled"`
TrialEndsAt *time.Time `json:"trial_ends_at"`
BillingAnchor int `json:"billing_anchor"`
FirstSubscriptionItem *SubscriptionItem `json:"first_subscription_item"`
Urls SubscriptionURLs `json:"urls"`
RenewsAt time.Time `json:"renews_at"`
EndsAt *time.Time `json:"ends_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
TestMode bool `json:"test_mode"`
}

// SubscriptionURLs is object of customer-facing URLs for managing the subscription.
Expand Down Expand Up @@ -58,11 +62,14 @@ type SubscriptionUpdateParamsAttributes struct {

// ApiResponseRelationshipsSubscription relationships of a subscription object
type ApiResponseRelationshipsSubscription struct {
Store ApiResponseLinks `json:"store"`
Order ApiResponseLinks `json:"order"`
OrderItem ApiResponseLinks `json:"order-item"`
Product ApiResponseLinks `json:"product"`
Variant ApiResponseLinks `json:"variant"`
Store ApiResponseLinks `json:"store"`
Customer ApiResponseLinks `json:"customer"`
Order ApiResponseLinks `json:"order"`
OrderItem ApiResponseLinks `json:"order-item"`
Product ApiResponseLinks `json:"product"`
Variant ApiResponseLinks `json:"variant"`
SubscriptionItems ApiResponseLinks `json:"subscription-items"`
SubscriptionInvoices ApiResponseLinks `json:"subscription-invoices"`
}

// ApiResponseSubscription represents a subscription api response
Expand Down
Loading

0 comments on commit 06c57de

Please sign in to comment.