diff --git a/docs/README.md b/docs/README.md
index bf1a087..d97f110 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -248,8 +248,10 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type PaymentLinksList](<#PaymentLinksList>)
- [type PaymentLinksService](<#PaymentLinksService>)
- [func \(pls \*PaymentLinksService\) Create\(ctx context.Context, p PaymentLink, opts \*PaymentLinkOptions\) \(res \*Response, np \*PaymentLink, err error\)](<#PaymentLinksService.Create>)
+ - [func \(pls \*PaymentLinksService\) Delete\(ctx context.Context, id string\) \(res \*Response, err error\)](<#PaymentLinksService.Delete>)
- [func \(pls \*PaymentLinksService\) Get\(ctx context.Context, id string\) \(res \*Response, pl \*PaymentLink, err error\)](<#PaymentLinksService.Get>)
- [func \(pls \*PaymentLinksService\) List\(ctx context.Context, opts \*PaymentLinkOptions\) \(res \*Response, pl \*PaymentLinksList, err error\)](<#PaymentLinksService.List>)
+ - [func \(pls \*PaymentLinksService\) Update\(ctx context.Context, id string, p UpdatePaymentLinks\) \(res \*Response, pl \*PaymentLink, err error\)](<#PaymentLinksService.Update>)
- [type PaymentList](<#PaymentList>)
- [type PaymentMethod](<#PaymentMethod>)
- [type PaymentMethodDetails](<#PaymentMethodDetails>)
@@ -383,6 +385,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type UpdateOrder](<#UpdateOrder>)
- [type UpdateOrderLine](<#UpdateOrderLine>)
- [type UpdatePayment](<#UpdatePayment>)
+- [type UpdatePaymentLinks](<#UpdatePaymentLinks>)
- [type UpdateShipment](<#UpdateShipment>)
- [type UpdateSubscription](<#UpdateSubscription>)
- [type UsedGiftCard](<#UsedGiftCard>)
@@ -4178,7 +4181,7 @@ type PaymentLinksList struct {
```
-## type [PaymentLinksService]()
+## type [PaymentLinksService]()
PaymentLinksService operates over the payment link resource.
@@ -4187,7 +4190,7 @@ type PaymentLinksService service
```
-### func \(\*PaymentLinksService\) [Create]()
+### func \(\*PaymentLinksService\) [Create]()
```go
func (pls *PaymentLinksService) Create(ctx context.Context, p PaymentLink, opts *PaymentLinkOptions) (res *Response, np *PaymentLink, err error)
@@ -4197,8 +4200,19 @@ Create generates payment links that by default, unlike regular payments, do not
See: https://docs.mollie.com/reference/v2/payment-links-api/create-payment-link
+
+### func \(\*PaymentLinksService\) [Delete]()
+
+```go
+func (pls *PaymentLinksService) Delete(ctx context.Context, id string) (res *Response, err error)
+```
+
+Delete removes a payment link from the website profile.
+
+See: https://docs.mollie.com/reference/delete-payment-link
+
-### func \(\*PaymentLinksService\) [Get]()
+### func \(\*PaymentLinksService\) [Get]()
```go
func (pls *PaymentLinksService) Get(ctx context.Context, id string) (res *Response, pl *PaymentLink, err error)
@@ -4209,7 +4223,7 @@ Get retrieves a single payment link object by its id/token.
See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link
-### func \(\*PaymentLinksService\) [List]()
+### func \(\*PaymentLinksService\) [List]()
```go
func (pls *PaymentLinksService) List(ctx context.Context, opts *PaymentLinkOptions) (res *Response, pl *PaymentLinksList, err error)
@@ -4219,6 +4233,17 @@ List retrieves all payments links created with the current website profile, orde
See: https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links
+
+### func \(\*PaymentLinksService\) [Update]()
+
+```go
+func (pls *PaymentLinksService) Update(ctx context.Context, id string, p UpdatePaymentLinks) (res *Response, pl *PaymentLink, err error)
+```
+
+Update changes certain details of an existing payment link.
+
+See: https://docs.mollie.com/reference/update-payment-link
+
## type [PaymentList]()
@@ -6038,6 +6063,18 @@ type UpdatePayment struct {
}
```
+
+## type [UpdatePaymentLinks]()
+
+UpdatePaymentLinks describes certain details of an existing payment link that can be updated.
+
+```go
+type UpdatePaymentLinks struct {
+ Description string `json:"description,omitempty"`
+ Archived bool `json:"archived,omitempty"`
+}
+```
+
## type [UpdateShipment]()
diff --git a/mollie/payment_links.go b/mollie/payment_links.go
index a8d3891..33e256e 100644
--- a/mollie/payment_links.go
+++ b/mollie/payment_links.go
@@ -58,6 +58,13 @@ type PaymentLinksList struct {
} `json:"_embedded,omitempty"`
}
+// UpdatePaymentLinks describes certain details of an existing payment link
+// that can be updated.
+type UpdatePaymentLinks struct {
+ Description string `json:"description,omitempty"`
+ Archived bool `json:"archived,omitempty"`
+}
+
// PaymentLinksService operates over the payment link resource.
type PaymentLinksService service
@@ -117,3 +124,35 @@ func (pls *PaymentLinksService) List(ctx context.Context, opts *PaymentLinkOptio
return
}
+
+// Update changes certain details of an existing payment link.
+//
+// See: https://docs.mollie.com/reference/update-payment-link
+func (pls *PaymentLinksService) Update(ctx context.Context, id string, p UpdatePaymentLinks) (
+ res *Response,
+ pl *PaymentLink,
+ err error,
+) {
+ res, err = pls.client.patch(ctx, fmt.Sprintf("v2/payment-links/%s", id), p)
+ if err != nil {
+ return
+ }
+
+ if err = json.Unmarshal(res.content, &pl); err != nil {
+ return
+ }
+
+ 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
+}
diff --git a/mollie/payment_links_test.go b/mollie/payment_links_test.go
index 6e0c6c7..0c48812 100644
--- a/mollie/payment_links_test.go
+++ b/mollie/payment_links_test.go
@@ -320,3 +320,182 @@ func TestPaymentLinkService_List(t *testing.T) {
})
}
}
+
+func TestPaymentLinkService_Update(t *testing.T) {
+ setEnv()
+ defer unsetEnv()
+
+ type args struct {
+ ctx context.Context
+ paymentLink string
+ pl UpdatePaymentLinks
+ }
+
+ cases := []struct {
+ name string
+ args args
+ wantErr bool
+ err error
+ pre func()
+ handler http.HandlerFunc
+ }{
+ {
+ "update payment links works as expected.",
+ args{
+ context.Background(),
+ "pl_ka21123129",
+ UpdatePaymentLinks{
+ Archived: true,
+ },
+ },
+ false,
+ nil,
+ noPre,
+ func(w http.ResponseWriter, r *http.Request) {
+ testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
+ testMethod(t, r, "PATCH")
+
+ if _, ok := r.Header[AuthHeader]; !ok {
+ w.WriteHeader(http.StatusUnauthorized)
+ }
+ _, _ = w.Write([]byte(testdata.UpdatePaymentLinksResponse))
+ },
+ },
+ {
+ "update payment links, an error is returned from the server",
+ args{
+ context.Background(),
+ "pl_ka21123129",
+ UpdatePaymentLinks{},
+ },
+ true,
+ fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
+ noPre,
+ errorHandler,
+ },
+ {
+ "update payment links, an error occurs when parsing json",
+ args{
+ context.Background(),
+ "pl_ka21123129",
+ UpdatePaymentLinks{},
+ },
+ true,
+ fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
+ noPre,
+ encodingHandler,
+ },
+ {
+ "update payment links, invalid url when building request",
+ args{
+ context.Background(),
+ "pl_ka21123129",
+ UpdatePaymentLinks{},
+ },
+ 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, m, err := tClient.PaymentLinks.Update(c.args.ctx, c.args.paymentLink, c.args.pl)
+ if c.wantErr {
+ assert.NotNil(t, err)
+ assert.EqualError(t, err, c.err.Error())
+ } else {
+ assert.Nil(t, err)
+ assert.IsType(t, &PaymentLink{}, m)
+ assert.IsType(t, &http.Response{}, res.Response)
+ }
+ })
+ }
+}
+
+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)
+ }
+ })
+ }
+}
diff --git a/testdata/payment_links.go b/testdata/payment_links.go
index c80c447..7de567d 100644
--- a/testdata/payment_links.go
+++ b/testdata/payment_links.go
@@ -119,3 +119,35 @@ const ListPaymentLinksResponse = `{
}
}
}`
+
+// UpdatePaymentLinksResponse example.
+const UpdatePaymentLinksResponse = `{
+ "resource": "payment-link",
+ "id": "pl_4Y0eZitmBnQ6IDoMqZQKh",
+ "mode": "live",
+ "description": "Bicycle tires",
+ "amount": {
+ "currency": "EUR",
+ "value": "24.95"
+ },
+ "archived": true,
+ "redirectUrl": "https://webshop.example.org/thanks",
+ "webhookUrl": "https://webshop.example.org/payment-links/webhook",
+ "profileId": "pfl_QkEhN94Ba",
+ "createdAt": "2021-03-20T09:29:56+00:00",
+ "expiresAt": "2023-06-06T11:00:00+00:00",
+ "_links": {
+ "self": {
+ "href": "...",
+ "type": "application/hal+json"
+ },
+ "paymentLink": {
+ "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh",
+ "type": "text/html"
+ },
+ "documentation": {
+ "href": "...",
+ "type": "text/html"
+ }
+ }
+}`