Skip to content

Commit

Permalink
feat(payment_links): add support to delete payment links
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar committed Jun 23, 2024
1 parent 5b8a699 commit 1564000
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mollie/payment_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,15 @@ func (pls *PaymentLinksService) Update(ctx context.Context, id string, p UpdateP

return
}

// Delete removes a payment link from the website profile.
//
// See: https://docs.mollie.com/reference/delete-payment-link
func (pls *PaymentLinksService) Delete(ctx context.Context, id string) (res *Response, err error) {
res, err = pls.client.delete(ctx, fmt.Sprintf("v2/payment-links/%s", id))
if err != nil {
return
}

return
}
80 changes: 80 additions & 0 deletions mollie/payment_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,83 @@ func TestPaymentLinkService_Update(t *testing.T) {
})
}
}

func TestPaymentLinkService_Delete(t *testing.T) {
setEnv()
defer unsetEnv()

type args struct {
ctx context.Context
paymentLink string
}

cases := []struct {
name string
args args
wantErr bool
err error
pre func()
handler http.HandlerFunc
}{
{
"delete payment links works as expected.",
args{
context.Background(),
"pl_ka21123129",
},
false,
nil,
noPre,
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
testMethod(t, r, "DELETE")

if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}
w.WriteHeader(http.StatusNoContent)
},
},
{
"delete payment links, an error is returned from the server",
args{
context.Background(),
"pl_ka21123129",
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
noPre,
errorHandler,
},
{
"delete payment links, invalid url when building request",
args{
context.Background(),
"pl_ka21123129",
},
true,
errBadBaseURL,
crashSrv,
errorHandler,
},
}

for _, c := range cases {
setup()
defer teardown()

t.Run(c.name, func(t *testing.T) {
c.pre()
tMux.HandleFunc(fmt.Sprintf("/v2/payment-links/%s", c.args.paymentLink), c.handler)

res, err := tClient.PaymentLinks.Delete(c.args.ctx, c.args.paymentLink)
if c.wantErr {
assert.NotNil(t, err)
assert.EqualError(t, err, c.err.Error())
} else {
assert.Nil(t, err)
assert.IsType(t, &http.Response{}, res.Response)
}
})
}
}

0 comments on commit 1564000

Please sign in to comment.