Skip to content

Commit

Permalink
Merge pull request #45 from mantishK/bugfix/invoice-expire-sub-accounts
Browse files Browse the repository at this point in the history
Expire an invoice belonging to a sub accounts
  • Loading branch information
stanleynguyen authored Sep 22, 2020
2 parents 25c527a + 4f59fda commit 2db15e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions invoice/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
3 changes: 1 addition & 2 deletions invoice/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ func TestExpire(t *testing.T) {

for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
var header *http.Header

apiRequesterMockObj.On(
"Call",
context.Background(),
"POST",
xendit.Opt.XenditURL+"/invoices/123/expire!",
xendit.Opt.SecretKey,
header,
&http.Header{},
nil,
&xendit.Invoice{},
).Return(nil)
Expand Down
3 changes: 2 additions & 1 deletion invoice/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}

0 comments on commit 2db15e1

Please sign in to comment.