From 67caacbfab049a1ee4844723f6257cd3311d6f04 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Mon, 31 Jul 2023 19:39:02 +0000 Subject: [PATCH] api: add update_customer_address checkout field --- api/api.go | 1 + api/apitypes/apitypes.go | 1 + client/tier/client.go | 2 ++ control/schedule.go | 4 ++++ 4 files changed, 8 insertions(+) diff --git a/api/api.go b/api/api.go index 88d9887..6cf35b6 100644 --- a/api/api.go +++ b/api/api.go @@ -215,6 +215,7 @@ func (h *Handler) serveCheckout(w http.ResponseWriter, r *http.Request) error { Features: fs, CancelURL: cr.CancelURL, RequireBillingAddress: cr.RequireBillingAddress, + UpdateCustomerAddress: cr.UpdateCustomerAddress, AutomaticTax: cr.Tax.Automatic, CollectTaxID: cr.Tax.CollectID, }) diff --git a/api/apitypes/apitypes.go b/api/apitypes/apitypes.go index a69b415..2e169a7 100644 --- a/api/apitypes/apitypes.go +++ b/api/apitypes/apitypes.go @@ -126,6 +126,7 @@ type CheckoutRequest struct { SuccessURL string `json:"success_url"` CancelURL string `json:"cancel_url"` RequireBillingAddress bool `json:"require_billing_address"` + UpdateCustomerAddress bool `json:"update_customer_address"` Tax Taxation `json:"tax"` } diff --git a/client/tier/client.go b/client/tier/client.go index eba2250..5f918aa 100644 --- a/client/tier/client.go +++ b/client/tier/client.go @@ -302,6 +302,7 @@ func (c *Client) Checkout(ctx context.Context, org string, successURL string, p TrialDays: p.TrialDays, Features: p.Features, RequireBillingAddress: p.RequireBillingAddress, + UpdateCustomerAddress: p.UpdateCustomerAddress, Tax: p.Tax, } return fetchOK[*apitypes.CheckoutResponse, *apitypes.Error](ctx, c, "POST", "/v1/checkout", r) @@ -315,6 +316,7 @@ type CheckoutParams struct { Features []string CancelURL string RequireBillingAddress bool + UpdateCustomerAddress bool Tax Taxation } diff --git a/control/schedule.go b/control/schedule.go index 26794de..6e4c761 100644 --- a/control/schedule.go +++ b/control/schedule.go @@ -537,6 +537,7 @@ type CheckoutParams struct { Features []Feature CancelURL string RequireBillingAddress bool + UpdateCustomerAddress bool // if true, update customer address to the address entered at checkout AutomaticTax bool CollectTaxID bool } @@ -568,6 +569,9 @@ func (c *Client) Checkout(ctx context.Context, org string, successURL string, p if p.RequireBillingAddress { f.Set("billing_address_collection", "required") } + if p.UpdateCustomerAddress { + f.Set("customer_update", "address", "auto") + } if len(p.Features) == 0 { f.Set("mode", "setup") // TODO: support other payment methods: