-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for all checkout creation options #18
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
"strconv" | ||
) | ||
|
||
// CheckoutsService is the API client for the `/v1/checkouts` endpoint | ||
|
@@ -13,39 +13,21 @@ type CheckoutsService service | |
// Create a custom checkout. | ||
// | ||
// https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout | ||
func (service *CheckoutsService) Create(ctx context.Context, params *CheckoutCreateParams) (*CheckoutApiResponse, *Response, error) { | ||
checkoutData := map[string]any{ | ||
"custom": params.CustomData, | ||
} | ||
if params.DiscountCode != nil { | ||
checkoutData["discount_code"] = params.DiscountCode | ||
} | ||
|
||
func (service *CheckoutsService) Create(ctx context.Context, variantId int, storeId int, attributes *CheckoutCreateAttributes) (*CheckoutApiResponse, *Response, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you used Another thing is the order of endpoints, usually i use the order of func (service *CheckoutsService) Create(ctx context.Context, storeID, variantID int, attributes *CheckoutCreateAttributes) (*CheckoutApiResponse, *Response, error) {
} |
||
payload := map[string]any{ | ||
"data": map[string]any{ | ||
"type": "checkouts", | ||
"attributes": map[string]any{ | ||
"custom_price": params.CustomPrice, | ||
"product_options": map[string]any{ | ||
"enabled_variants": params.EnabledVariants, | ||
}, | ||
"checkout_options": map[string]any{ | ||
"button_color": params.ButtonColor, | ||
}, | ||
"checkout_data": checkoutData, | ||
"expires_at": params.ExpiresAt.Format(time.RFC3339), | ||
"preview": true, | ||
}, | ||
"type": "checkouts", | ||
"attributes": attributes, | ||
"relationships": map[string]any{ | ||
"store": map[string]any{ | ||
"data": map[string]any{ | ||
"id": params.StoreID, | ||
"id": strconv.Itoa(storeId), | ||
"type": "stores", | ||
}, | ||
}, | ||
"variant": map[string]any{ | ||
"data": map[string]any{ | ||
"id": params.VariantID, | ||
"id": strconv.Itoa(variantId), | ||
"type": "variants", | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the same structure of variable names so this struct will be
CheckoutCreateDataVariantQuantity
instead ofQuantities