From 479e4290471cceeefa8e3da73519c1688918a233 Mon Sep 17 00:00:00 2001 From: Kumar Mantesh Date: Fri, 18 Sep 2020 22:16:49 +0530 Subject: [PATCH 1/2] expire an invoice belonging to a subaccount --- invoice/client.go | 7 +++++-- invoice/params.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/invoice/client.go b/invoice/client.go index 1c09dd89..3d28bce1 100644 --- a/invoice/client.go +++ b/invoice/client.go @@ -90,13 +90,16 @@ func (c *Client) ExpireWithContext(ctx context.Context, data *ExpireParams) (*xe } response := &xendit.Invoice{} - + header := &http.Header{} + if data.ForUserID != "" { + header.Add("for-user-id", data.ForUserID) + } err := c.APIRequester.Call( ctx, "POST", fmt.Sprintf("%s/invoices/%s/expire!", c.Opt.XenditURL, data.ID), c.Opt.SecretKey, - nil, + header, nil, response, ) diff --git a/invoice/params.go b/invoice/params.go index 21541a56..dff57460 100644 --- a/invoice/params.go +++ b/invoice/params.go @@ -77,5 +77,6 @@ func (p *GetAllParams) QueryString() string { // ExpireParams contains parameters for Expire type ExpireParams struct { - ID string `json:"id" validate:"required"` + ID string `json:"id" validate:"required"` + ForUserID string `json:"-"` } From 4f59fda237e30262d96bbfb13900b818a6cd3f7c Mon Sep 17 00:00:00 2001 From: Kumar Mantesh Date: Fri, 18 Sep 2020 23:06:29 +0530 Subject: [PATCH 2/2] corrected header in the tests --- invoice/invoice_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/invoice/invoice_test.go b/invoice/invoice_test.go index a9bcc7f2..55e44b0a 100644 --- a/invoice/invoice_test.go +++ b/invoice/invoice_test.go @@ -184,7 +184,6 @@ func TestExpire(t *testing.T) { for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - var header *http.Header apiRequesterMockObj.On( "Call", @@ -192,7 +191,7 @@ func TestExpire(t *testing.T) { "POST", xendit.Opt.XenditURL+"/invoices/123/expire!", xendit.Opt.SecretKey, - header, + &http.Header{}, nil, &xendit.Invoice{}, ).Return(nil)