Repository: VictorAvelar/mollie-api-go
Pull request #334 (2024-03-06 19:23:49)

check customers resource against api reference
<!--- Provide a general summary of your changes in the Title above -->

# Description

Ensures that the `customers` resource delivers API parity. 

## Motivation and context

Ensures the library has full API parity.

## How has this been tested?

Please describe in detail how you tested your changes.

Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.

- [x] Unit tests added / updated
- [x] The tests run on docker (using `make test`)
- [ ] The required `test data` has been added / updated

If you are running the tests locally, please specify:

- OS: macos
- Go version 1.22

## Types of changes

What types of changes does your code introduce? Put an `x` in all the boxes that apply:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] This change requires a documentation update

## Checklist

Go over all the following points, and put an `x` in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/).

- [x] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document.
- [x] My pull request addresses exactly one patch/feature.
- [x] I have created a branch for this patch/feature.
- [x] Each individual commit in the pull request is meaningful.
- [x] If my change requires a change to the documentation, I have updated it accordingly.

<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->



Patch:
diff --git a/docs/README.md b/docs/README.md
index 0418b94..f9cdcfc 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -106,6 +106,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
   - [func \(cv \*ContextValues\) UnmarshalJSON\(data \[\]byte\) error](<#ContextValues.UnmarshalJSON>)
 - [type CreateCapture](<#CreateCapture>)
 - [type CreateClientLink](<#CreateClientLink>)
+- [type CreateCustomer](<#CreateCustomer>)
 - [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
 - [type CreatePayment](<#CreatePayment>)
 - [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -117,13 +118,13 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
 - [type CustomersList](<#CustomersList>)
 - [type CustomersListOptions](<#CustomersListOptions>)
 - [type CustomersService](<#CustomersService>)
-  - [func \(cs \*CustomersService\) Create\(ctx context.Context, c Customer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Create>)
+  - [func \(cs \*CustomersService\) Create\(ctx context.Context, c CreateCustomer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Create>)
   - [func \(cs \*CustomersService\) CreatePayment\(ctx context.Context, id string, p CreatePayment\) \(res \*Response, pp \*Payment, err error\)](<#CustomersService.CreatePayment>)
   - [func \(cs \*CustomersService\) Delete\(ctx context.Context, id string\) \(res \*Response, err error\)](<#CustomersService.Delete>)
   - [func \(cs \*CustomersService\) Get\(ctx context.Context, id string\) \(res \*Response, c \*Customer, err error\)](<#CustomersService.Get>)
   - [func \(cs \*CustomersService\) GetPayments\(ctx context.Context, id string, options \*CustomersListOptions\) \(res \*Response, pl \*PaymentList, err error\)](<#CustomersService.GetPayments>)
   - [func \(cs \*CustomersService\) List\(ctx context.Context, options \*CustomersListOptions\) \(res \*Response, cl \*CustomersList, err error\)](<#CustomersService.List>)
-  - [func \(cs \*CustomersService\) Update\(ctx context.Context, id string, c Customer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Update>)
+  - [func \(cs \*CustomersService\) Update\(ctx context.Context, id string, c UpdateCustomer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Update>)
 - [type EligibilityReasons](<#EligibilityReasons>)
 - [type EmbedValue](<#EmbedValue>)
 - [type EntityType](<#EntityType>)
@@ -355,6 +356,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
 - [type TransferDestination](<#TransferDestination>)
 - [type TransferFrequency](<#TransferFrequency>)
 - [type URL](<#URL>)
+- [type UpdateCustomer](<#UpdateCustomer>)
 - [type UpdatePayment](<#UpdatePayment>)
 - [type UsedGiftCard](<#UsedGiftCard>)
 - [type UserAgentToken](<#UserAgentToken>)
@@ -1826,6 +1828,20 @@ type CreateClientLink struct {
 }
 ```
 
+<a name="CreateCustomer"></a>
+## type [CreateCustomer](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L11-L16>)
+
+CreateCustomer contains the parameters to create a customer.
+
+```go
+type CreateCustomer struct {
+    Name     string `json:"name,omitempty"`
+    Email    string `json:"email,omitempty"`
+    Locale   Locale `json:"locale,omitempty"`
+    Metadata any    `json:"metadata,omitempty"`
+}
+```
+
 <a name="CreateMollieConnectPaymentFields"></a>
 ## type [CreateMollieConnectPaymentFields](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payments.go#L134-L137>)
 
@@ -1945,7 +1961,7 @@ type CreateShipmentRequest struct {
 ```
 
 <a name="Customer"></a>
-## type [Customer](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L24-L34>)
+## type [Customer](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L37-L47>)
 
 Customer represents buyers.
 
@@ -1957,30 +1973,30 @@ type Customer struct {
     Name      string        `json:"name,omitempty"`
     Email     string        `json:"email,omitempty"`
     Locale    Locale        `json:"locale,omitempty"`
-    Metadata  interface{}   `json:"metadata,omitempty"`
+    Metadata  any           `json:"metadata,omitempty"`
     CreatedAt *time.Time    `json:"createdAt,omitempty"`
     Links     CustomerLinks `json:"_links,omitempty"`
 }
 ```
 
 <a name="CustomerLinks"></a>
-## type [CustomerLinks](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L14-L21>)
+## type [CustomerLinks](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L27-L34>)
 
 CustomerLinks contains the HAL resources for a customer response.
 
 ```go
 type CustomerLinks struct {
     Self          *URL `json:"self,omitempty"`
+    Dashboard     *URL `json:"dashboard,omitempty"`
     Mandates      *URL `json:"mandates,omitempty"`
     Subscriptions *URL `json:"subscriptions,omitempty"`
     Payments      *URL `json:"payments,omitempty"`
     Documentation *URL `json:"documentation,omitempty"`
-    Dashboard     *URL `json:"dashboard,omitempty"`
 }
 ```
 
 <a name="CustomersList"></a>
-## type [CustomersList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L47-L53>)
+## type [CustomersList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L60-L66>)
 
 CustomersList contains a embedded list of customers wrapped in a standard Mollie paginated response.
 
@@ -1988,14 +2004,14 @@ CustomersList contains a embedded list of customers wrapped in a standard Mollie
 type CustomersList struct {
     Count    int `json:"count,omitempty"`
     Embedded struct {
-        Customers []Customer `json:"customers,omitempty"`
+        Customers []*Customer `json:"customers,omitempty"`
     }   `json:"_embedded,omitempty"`
     Links PaginationLinks `json:"links,omitempty"`
 }
 ```
 
 <a name="CustomersListOptions"></a>
-## type [CustomersListOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L37-L43>)
+## type [CustomersListOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L50-L56>)
 
 CustomersListOptions contains valid query parameters for the list customers endpoint.
 
@@ -2010,7 +2026,7 @@ type CustomersListOptions struct {
 ```
 
 <a name="CustomersService"></a>
-## type [CustomersService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L11>)
+## type [CustomersService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L69>)
 
 CustomersService operates over the customer resource.
 
@@ -2019,10 +2035,10 @@ type CustomersService service
 ```
 
 <a name="CustomersService.Create"></a>
-### func \(\*CustomersService\) [Create](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L77>)
+### func \(\*CustomersService\) [Create](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L93>)
 
 ```go
-func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Response, cc *Customer, err error)
+func (cs *CustomersService) Create(ctx context.Context, c CreateCustomer) (res *Response, cc *Customer, err error)
 ```
 
 Create creates a simple minimal representation of a customer in the Mollie API to use for the Mollie Checkout and Recurring features.
@@ -2030,7 +2046,7 @@ Create creates a simple minimal representation of a customer in the Mollie API t
 See: https://docs.mollie.com/reference/v2/customers-api/create-customer
 
 <a name="CustomersService.CreatePayment"></a>
-### func \(\*CustomersService\) [CreatePayment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L173-L177>)
+### func \(\*CustomersService\) [CreatePayment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L189-L193>)
 
 ```go
 func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p CreatePayment) (res *Response, pp *Payment, err error)
@@ -2041,7 +2057,7 @@ CreatePayment creates a payment for the customer.
 See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
 
 <a name="CustomersService.Delete"></a>
-### func \(\*CustomersService\) [Delete](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L117>)
+### func \(\*CustomersService\) [Delete](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L133>)
 
 ```go
 func (cs *CustomersService) Delete(ctx context.Context, id string) (res *Response, err error)
@@ -2054,7 +2070,7 @@ All mandates and subscriptions created for this customer will be canceled as wel
 See: https://docs.mollie.com/reference/v2/customers-api/delete-customer
 
 <a name="CustomersService.Get"></a>
-### func \(\*CustomersService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L58>)
+### func \(\*CustomersService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L74>)
 
 ```go
 func (cs *CustomersService) Get(ctx context.Context, id string) (res *Response, c *Customer, err error)
@@ -2065,7 +2081,7 @@ Get finds a customer by its ID.
 See: https://docs.mollie.com/reference/v2/customers-api/get-customer
 
 <a name="CustomersService.GetPayments"></a>
-### func \(\*CustomersService\) [GetPayments](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L151-L155>)
+### func \(\*CustomersService\) [GetPayments](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L167-L171>)
 
 ```go
 func (cs *CustomersService) GetPayments(ctx context.Context, id string, options *CustomersListOptions) (res *Response, pl *PaymentList, err error)
@@ -2076,7 +2092,7 @@ GetPayments retrieves all payments linked to the customer.
 See: https://docs.mollie.com/reference/v2/customers-api/list-customer-payments
 
 <a name="CustomersService.List"></a>
-### func \(\*CustomersService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L131-L135>)
+### func \(\*CustomersService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L147-L151>)
 
 ```go
 func (cs *CustomersService) List(ctx context.Context, options *CustomersListOptions) (res *Response, cl *CustomersList, err error)
@@ -2087,10 +2103,10 @@ List retrieves all customers created.
 See: https://docs.mollie.com/reference/v2/customers-api/list-customers
 
 <a name="CustomersService.Update"></a>
-### func \(\*CustomersService\) [Update](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L93-L97>)
+### func \(\*CustomersService\) [Update](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L109-L113>)
 
 ```go
-func (cs *CustomersService) Update(ctx context.Context, id string, c Customer) (res *Response, cc *Customer, err error)
+func (cs *CustomersService) Update(ctx context.Context, id string, c UpdateCustomer) (res *Response, cc *Customer, err error)
 ```
 
 Update an existing customer.
@@ -5546,6 +5562,20 @@ type URL struct {
 }
 ```
 
+<a name="UpdateCustomer"></a>
+## type [UpdateCustomer](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/customers.go#L19-L24>)
+
+UpdateCustomer contains the parameters to update a customer.
+
+```go
+type UpdateCustomer struct {
+    Name     string `json:"name,omitempty"`
+    Email    string `json:"email,omitempty"`
+    Locale   Locale `json:"locale,omitempty"`
+    Metadata any    `json:"metadata,omitempty"`
+}
+```
+
 <a name="UpdatePayment"></a>
 ## type [UpdatePayment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payments.go#L144-L158>)
 
diff --git a/mollie/customers.go b/mollie/customers.go
index 486aa37..a3e6739 100644
--- a/mollie/customers.go
+++ b/mollie/customers.go
@@ -7,17 +7,30 @@ import (
 	"time"
 )
 
-// CustomersService operates over the customer resource.
-type CustomersService service
+// CreateCustomer contains the parameters to create a customer.
+type CreateCustomer struct {
+	Name     string `json:"name,omitempty"`
+	Email    string `json:"email,omitempty"`
+	Locale   Locale `json:"locale,omitempty"`
+	Metadata any    `json:"metadata,omitempty"`
+}
+
+// UpdateCustomer contains the parameters to update a customer.
+type UpdateCustomer struct {
+	Name     string `json:"name,omitempty"`
+	Email    string `json:"email,omitempty"`
+	Locale   Locale `json:"locale,omitempty"`
+	Metadata any    `json:"metadata,omitempty"`
+}
 
 // CustomerLinks contains the HAL resources for a customer response.
 type CustomerLinks struct {
 	Self          *URL `json:"self,omitempty"`
+	Dashboard     *URL `json:"dashboard,omitempty"`
 	Mandates      *URL `json:"mandates,omitempty"`
 	Subscriptions *URL `json:"subscriptions,omitempty"`
 	Payments      *URL `json:"payments,omitempty"`
 	Documentation *URL `json:"documentation,omitempty"`
-	Dashboard     *URL `json:"dashboard,omitempty"`
 }
 
 // Customer represents buyers.
@@ -28,7 +41,7 @@ type Customer struct {
 	Name      string        `json:"name,omitempty"`
 	Email     string        `json:"email,omitempty"`
 	Locale    Locale        `json:"locale,omitempty"`
-	Metadata  interface{}   `json:"metadata,omitempty"`
+	Metadata  any           `json:"metadata,omitempty"`
 	CreatedAt *time.Time    `json:"createdAt,omitempty"`
 	Links     CustomerLinks `json:"_links,omitempty"`
 }
@@ -47,11 +60,14 @@ type CustomersListOptions struct {
 type CustomersList struct {
 	Count    int `json:"count,omitempty"`
 	Embedded struct {
-		Customers []Customer `json:"customers,omitempty"`
+		Customers []*Customer `json:"customers,omitempty"`
 	} `json:"_embedded,omitempty"`
 	Links PaginationLinks `json:"links,omitempty"`
 }
 
+// CustomersService operates over the customer resource.
+type CustomersService service
+
 // Get finds a customer by its ID.
 //
 // See: https://docs.mollie.com/reference/v2/customers-api/get-customer
@@ -74,7 +90,7 @@ func (cs *CustomersService) Get(ctx context.Context, id string) (res *Response,
 // to use for the Mollie Checkout and Recurring features.
 //
 // See: https://docs.mollie.com/reference/v2/customers-api/create-customer
-func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Response, cc *Customer, err error) {
+func (cs *CustomersService) Create(ctx context.Context, c CreateCustomer) (res *Response, cc *Customer, err error) {
 	res, err = cs.client.post(ctx, "v2/customers", c, nil)
 	if err != nil {
 		return
@@ -90,7 +106,7 @@ func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Respon
 // Update an existing customer.
 //
 // See: https://docs.mollie.com/reference/v2/customers-api/update-customer
-func (cs *CustomersService) Update(ctx context.Context, id string, c Customer) (
+func (cs *CustomersService) Update(ctx context.Context, id string, c UpdateCustomer) (
 	res *Response,
 	cc *Customer,
 	err error,
diff --git a/mollie/payments.go b/mollie/payments.go
index 67af858..e18d5e7 100644
--- a/mollie/payments.go
+++ b/mollie/payments.go
@@ -347,7 +347,7 @@ func (ps *PaymentsService) Update(ctx context.Context, id string, up UpdatePayme
 type PaymentList struct {
 	Count    int `json:"count,omitempty"`
 	Embedded struct {
-		Payments []Payment
+		Payments []*Payment
 	} `json:"_embedded,omitempty"`
 	Links PaginationLinks `json:"_links,omitempty"`
 }


Test patch:
diff --git a/mollie/customers_test.go b/mollie/customers_test.go
index 9863ab2..86e6b44 100644
--- a/mollie/customers_test.go
+++ b/mollie/customers_test.go
@@ -106,7 +106,7 @@ func TestCustomersService_Create(t *testing.T) {
 	defer unsetEnv()
 	type args struct {
 		ctx      context.Context
-		customer Customer
+		customer CreateCustomer
 	}
 
 	cases := []struct {
@@ -123,7 +123,7 @@ func TestCustomersService_Create(t *testing.T) {
 			http.StatusAccepted,
 			args{
 				context.Background(),
-				Customer{Locale: German},
+				CreateCustomer{Locale: German},
 			},
 			false,
 			nil,
@@ -143,7 +143,7 @@ func TestCustomersService_Create(t *testing.T) {
 			http.StatusInternalServerError,
 			args{
 				context.Background(),
-				Customer{},
+				CreateCustomer{},
 			},
 			true,
 			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -155,7 +155,7 @@ func TestCustomersService_Create(t *testing.T) {
 			http.StatusInternalServerError,
 			args{
 				context.Background(),
-				Customer{},
+				CreateCustomer{},
 			},
 			true,
 			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -167,7 +167,7 @@ func TestCustomersService_Create(t *testing.T) {
 			http.StatusInternalServerError,
 			args{
 				context.Background(),
-				Customer{},
+				CreateCustomer{},
 			},
 			true,
 			errBadBaseURL,
@@ -203,7 +203,7 @@ func TestCustomersService_Update(t *testing.T) {
 	type args struct {
 		ctx        context.Context
 		customerID string
-		customer   Customer
+		customer   UpdateCustomer
 	}
 
 	cases := []struct {
@@ -221,7 +221,7 @@ func TestCustomersService_Update(t *testing.T) {
 			args{
 				context.Background(),
 				"cst_kEn1PlbGa",
-				Customer{Locale: French},
+				UpdateCustomer{Locale: French},
 			},
 			false,
 			nil,
@@ -242,7 +242,7 @@ func TestCustomersService_Update(t *testing.T) {
 			args{
 				context.Background(),
 				"cst_kEn1PlbGa",
-				Customer{},
+				UpdateCustomer{},
 			},
 			true,
 			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -255,7 +255,7 @@ func TestCustomersService_Update(t *testing.T) {
 			args{
 				context.Background(),
 				"cst_kEn1PlbGa",
-				Customer{},
+				UpdateCustomer{},
 			},
 			true,
 			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -268,7 +268,7 @@ func TestCustomersService_Update(t *testing.T) {
 			args{
 				context.Background(),
 				"cst_kEn1PlbGa",
-				Customer{},
+				UpdateCustomer{},
 			},
 			true,
 			errBadBaseURL,