generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcheckout.go
144 lines (129 loc) · 6.73 KB
/
checkout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package lemonsqueezy
import "time"
// CheckoutAttributes contains information about a percentage or amount discount that can be applied to an order at checkout via a code.
type CheckoutAttributes struct {
StoreID int `json:"store_id"`
VariantID int `json:"variant_id"`
CustomPrice interface{} `json:"custom_price"`
ProductOptions CheckoutProductOptions `json:"product_options"`
CheckoutOptions CheckoutOptions `json:"checkout_options"`
CheckoutData CheckoutData `json:"checkout_data"`
ExpiresAt *time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
TestMode bool `json:"test_mode"`
URL string `json:"url"`
}
// CheckoutProductOptions are options for a checkout product
type CheckoutProductOptions struct {
Name string `json:"name"`
Description string `json:"description"`
Media []any `json:"media"`
RedirectURL string `json:"redirect_url"`
ReceiptButtonText string `json:"receipt_button_text"`
ReceiptLinkURL string `json:"receipt_link_url"`
ReceiptThankYouNote string `json:"receipt_thank_you_note"`
EnabledVariants []int `json:"enabled_variants"`
}
// CheckoutOptions are options for a checkout
type CheckoutOptions struct {
Embed bool `json:"embed"`
Media bool `json:"media"`
Logo bool `json:"logo"`
Desc bool `json:"desc"`
Discount bool `json:"discount"`
Dark bool `json:"dark"`
SubscriptionPreview bool `json:"subscription_preview"`
ButtonColor string `json:"button_color"`
}
// BillingAddress contains the checkout billing address
type BillingAddress struct {
Country string `json:"country"`
Zip string `json:"zip"`
}
// CheckoutData contains information about a checkout
type CheckoutData struct {
Email string `json:"email"`
Name string `json:"name"`
BillingAddress []BillingAddress `json:"billing_address"`
TaxNumber string `json:"tax_number"`
DiscountCode string `json:"discount_code"`
Custom any `json:"custom"`
}
// CheckoutPreview contains information about a percentage or amount discount that can be applied to an order at checkout via a code.
type CheckoutPreview struct {
Currency string `json:"currency"`
CurrencyRate int `json:"currency_rate"`
Subtotal int `json:"subtotal"`
DiscountTotal int `json:"discount_total"`
Tax int `json:"tax"`
Total int `json:"total"`
SubtotalUsd int `json:"subtotal_usd"`
DiscountTotalUsd int `json:"discount_total_usd"`
TaxUsd int `json:"tax_usd"`
TotalUsd int `json:"total_usd"`
SubtotalFormatted string `json:"subtotal_formatted"`
DiscountTotalFormatted string `json:"discount_total_formatted"`
TaxFormatted string `json:"tax_formatted"`
TotalFormatted string `json:"total_formatted"`
}
// APIResponseRelationshipsCheckout relationships of a checkout
type APIResponseRelationshipsCheckout struct {
Store ApiResponseLinks `json:"store"`
Variant ApiResponseLinks `json:"variant"`
}
// CheckoutAPIResponse is the api response for one checkout
type CheckoutAPIResponse = ApiResponse[CheckoutAttributes, APIResponseRelationshipsDiscount]
// CheckoutsAPIResponse is the api response for a list of checkout.
type CheckoutsAPIResponse = ApiResponseList[CheckoutAttributes, APIResponseRelationshipsDiscount]
// CheckoutCreateDataQuantity represents variant quantities when creating checkout
type CheckoutCreateDataQuantity struct {
VariantID int `json:"variant_id"`
Quantity int `json:"quantity"`
}
// CheckoutCreateData represents the data options for creating a checkout.
type CheckoutCreateData struct {
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
BillingAddressCountry string `json:"billing_address.country,omitempty"`
BillingAddressZip string `json:"billing_address.zip,omitempty"`
TaxNumber string `json:"tax_number,omitempty"`
DiscountCode string `json:"discount_code,omitempty"`
Custom map[string]any `json:"custom,omitempty"`
VariantQuantities []CheckoutCreateDataQuantity `json:"variant_quantities,omitempty"`
}
// CheckoutCreateOptions represents the checkout options for creating a checkout.
//
// Note: We use pointers for the boolean fields as otherwise, setting them to "false" would omit them, which would
// break some of the boolean checks in the API. See: https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout
type CheckoutCreateOptions struct {
Embed *bool `json:"embed,omitempty"`
Media *bool `json:"media,omitempty"`
Logo *bool `json:"logo,omitempty"`
Desc *bool `json:"desc,omitempty"`
Discount *bool `json:"discount,omitempty"`
Dark *bool `json:"dark,omitempty"`
SubscriptionPreview *bool `json:"subscription_preview,omitempty"`
ButtonColor string `json:"button_color,omitempty"`
}
// CheckoutCreateProductOptions represents product options for creating a checkout.
type CheckoutCreateProductOptions struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Media []string `json:"media,omitempty"`
RedirectURL string `json:"redirect_url,omitempty"`
ReceiptButtonText string `json:"receipt_button_text,omitempty"`
ReceiptLinkURL string `json:"receipt_link_url,omitempty"`
ReceiptThankYouNote string `json:"receipt_thank_you_note,omitempty"`
EnabledVariants []int `json:"enabled_variants,omitempty"`
}
// CheckoutCreateAttributes represents individual parameters for creating a checkout.
type CheckoutCreateAttributes struct {
CustomPrice *int `json:"custom_price,omitempty"`
ProductOptions CheckoutCreateProductOptions `json:"product_options,omitempty"`
CheckoutOptions CheckoutCreateOptions `json:"checkout_options,omitempty"`
CheckoutData CheckoutCreateData `json:"checkout_data,omitempty"`
Preview *bool `json:"preview,omitempty"`
TestMode *bool `json:"test_mode,omitempty"`
ExpiresAt *string `json:"expires_at,omitempty"`
}