Repository: VictorAvelar/mollie-api-go
Pull request #120 (2021-03-07 18:55:01)

onboarding api resource
<!--- Provide a general summary of your changes in the Title above -->

## Description

Add a service to interact with the Onboarding API

```go
// get onboarding status sample.
status, err := mollie.Onboarding.GetOnboardingStatus()
```

## Motivation and context

Ensure 100% API compatibility

## How has this been tested?

Tests added for the 2 new methods, extended full coverage.

## Screenshots (if appropriate)

## 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)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## 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] I have added tests to cover my changes.
- [x] If my change requires a change to the documentation, I have updated it accordingly.



Patch:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index ef6d931..c228ff4 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -8,4 +8,5 @@ changelog:
     exclude:
       - docs
       - changelog
-      - ^Merge pull request
\ No newline at end of file
+      - readme
+      - ^Merge pull request
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b90a421..16cd5d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,14 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
 
 ## master
 
+## v2.6.0
+
+### Added
+
+- OnboardingService
+- GetOnboardingData method
+- SubmitOnboardingData method
+
 ## v2.5.1
 
 ### Fixed
diff --git a/SECURITY.md b/SECURITY.md
index a0887fc..245373c 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -2,16 +2,16 @@
 
 ## Supported Versions
 
-Even though go offers full backwards compatibility, this package will only be concerned about the versions tested and 
-declared inside the `.travis.yml` file.
+Even though go offers full backwards compatibility, this package will only be concerned about the versions tested and
+declared inside the `.scrutinizer.yml` file.
 
 | Version | Supported          |
 | ------- | ------------------ |
-| 1.13.x   | :warning: |
-| 1.14.x   | :warning: |
-| 1.15.x   | :warning: |
-| 1.16.x   | :white_check_mark: |
-| master   | :x: |
+| 1.13.x  | :warning:          |
+| 1.14.x  | :warning:          |
+| 1.15.x  | :white_check_mark: |
+| 1.16.x  | :white_check_mark: |
+| master  | :x:                |
 
 ## Reporting a Vulnerability
 
diff --git a/docs/README.md b/docs/README.md
index a72cbfd..6772637 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -389,6 +389,7 @@ type Client struct {
 	Miscellaneous *MiscellaneousService
 	Mandates      *MandatesService
 	Permissions   *PermissionsService
+	Onboarding    *OnboardingService
 }
 ```
 
@@ -1285,6 +1286,114 @@ const (
 
 Valid modes
 
+#### type Onboarding
+
+```go
+type Onboarding struct {
+	Resource              string           `json:"reference,omitempty"`
+	Name                  string           `json:"name,omitempty"`
+	SignedUpAt            *time.Time       `json:"signedUpAt,omitempty"`
+	Status                OnboardingStatus `json:"status,omitempty"`
+	CanReceivePayments    bool             `json:"canReceivePayments,omitempty"`
+	CanReveiceSettlements bool             `json:"canReceiveSettlements,omitempty"`
+	Links                 OnboardingLinks  `json:"_links,omitempty"`
+}
+```
+
+Onboarding data for an organization.
+
+#### type OnboardingData
+
+```go
+type OnboardingData struct {
+	Organization struct {
+		Name               string   `json:"name,omitempty"`
+		Address            *Address `json:"address,omitempty"`
+		RegistrationNumber string   `json:"registrationNumber,omitempty"`
+		VatNumber          string   `json:"vatNumber,omitempty"`
+		VatRegulation      string   `json:"vatRegulation,omitempty"`
+	} `json:"organization,omitempty"`
+	Profile struct {
+		Name         string       `json:"name,omitempty"`
+		URL          string       `json:"url,omitempty"`
+		Email        string       `json:"email,omitempty"`
+		Description  string       `json:"description,omitempty"`
+		Phone        string       `json:"phone,omitempty"`
+		CategoryCode CategoryCode `json:"categoryCode,omitempty"`
+	} `json:"profile,omitempty"`
+}
+```
+
+OnboardingData request possible values.
+
+Please note that even though all parameters are optional, at least one of them
+needs to be provided in the request.
+
+Information that the merchant has entered in their dashboard will not be
+overwritten.
+
+#### type OnboardingLinks
+
+```go
+type OnboardingLinks struct {
+	Self          *URL `json:"self,omitempty"`
+	Dashboard     *URL `json:"dashboard,omitempty"`
+	Organization  *URL `json:"organization,omitempty"`
+	Documentation *URL `json:"documentation,omitempty"`
+}
+```
+
+OnboardingLinks contains URL objects relevant to the onboarding status.
+
+#### type OnboardingService
+
+```go
+type OnboardingService service
+```
+
+OnboardingService operates over the onboarding API.
+
+#### func (\*OnboardingService) GetOnboardingStatus
+
+```go
+func (os *OnboardingService) GetOnboardingStatus() (o *Onboarding, err error)
+```
+
+GetOnboardingStatus gets the status of onboarding of the authenticated
+organization.
+
+See: https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status
+
+#### func (\*OnboardingService) SubmitOnboardingData
+
+```go
+func (os *OnboardingService) SubmitOnboardingData(d *OnboardingData) (err error)
+```
+
+SubmitOnboardingData sends data that will be prefilled in the merchant’s
+onboarding. Please note that the data you submit will only be processed when the
+onboarding status is needs-data.
+
+See: https://docs.mollie.com/reference/v2/onboarding-api/submit-onboarding-data
+
+#### type OnboardingStatus
+
+```go
+type OnboardingStatus string
+```
+
+OnboardingStatus describes status of the organization’s onboarding process.
+
+```go
+const (
+	NeedsDataOnboardingStatus OnboardingStatus = "needs-data"
+	InReviewOnboardingStatus  OnboardingStatus = "in-review"
+	CompletedOnboardingStatus OnboardingStatus = "completed"
+)
+```
+
+Possible status values.
+
 #### type Order
 
 ```go
diff --git a/mollie/mollie.go b/mollie/mollie.go
index 4b869dc..c087dfa 100644
--- a/mollie/mollie.go
+++ b/mollie/mollie.go
@@ -54,6 +54,7 @@ type Client struct {
 	Miscellaneous *MiscellaneousService
 	Mandates      *MandatesService
 	Permissions   *PermissionsService
+	Onboarding    *OnboardingService
 }
 
 type service struct {
@@ -176,6 +177,7 @@ func NewClient(baseClient *http.Client, c *Config) (mollie *Client, err error) {
 	mollie.Miscellaneous = (*MiscellaneousService)(&mollie.common)
 	mollie.Mandates = (*MandatesService)(&mollie.common)
 	mollie.Permissions = (*PermissionsService)(&mollie.common)
+	mollie.Onboarding = (*OnboardingService)(&mollie.common)
 
 	// Parse authorization from specified environment variable
 	tkn, ok := os.LookupEnv(c.auth)
diff --git a/mollie/onboarding.go b/mollie/onboarding.go
new file mode 100644
index 0000000..113df89
--- /dev/null
+++ b/mollie/onboarding.go
@@ -0,0 +1,104 @@
+package mollie
+
+import (
+	"encoding/json"
+	"net/http"
+	"time"
+)
+
+const onboardingTarget = "v2/onboarding/me"
+
+// OnboardingStatus describes status of the organization’s onboarding process.
+type OnboardingStatus string
+
+// Possible status values.
+const (
+	NeedsDataOnboardingStatus OnboardingStatus = "needs-data"
+	InReviewOnboardingStatus  OnboardingStatus = "in-review"
+	CompletedOnboardingStatus OnboardingStatus = "completed"
+)
+
+// OnboardingService operates over the onboarding API.
+type OnboardingService service
+
+// OnboardingLinks contains URL objects relevant to the onboarding status.
+type OnboardingLinks struct {
+	Self          *URL `json:"self,omitempty"`
+	Dashboard     *URL `json:"dashboard,omitempty"`
+	Organization  *URL `json:"organization,omitempty"`
+	Documentation *URL `json:"documentation,omitempty"`
+}
+
+// Onboarding data for an organization.
+type Onboarding struct {
+	Resource              string           `json:"reference,omitempty"`
+	Name                  string           `json:"name,omitempty"`
+	SignedUpAt            *time.Time       `json:"signedUpAt,omitempty"`
+	Status                OnboardingStatus `json:"status,omitempty"`
+	CanReceivePayments    bool             `json:"canReceivePayments,omitempty"`
+	CanReveiceSettlements bool             `json:"canReceiveSettlements,omitempty"`
+	Links                 OnboardingLinks  `json:"_links,omitempty"`
+}
+
+// GetOnboardingStatus gets the status of onboarding of the authenticated organization.
+//
+// See: https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status
+func (os *OnboardingService) GetOnboardingStatus() (o *Onboarding, err error) {
+	req, err := os.client.NewAPIRequest(http.MethodGet, onboardingTarget, nil)
+	if err != nil {
+		return
+	}
+
+	res, err := os.client.Do(req)
+	if err != nil {
+		return
+	}
+
+	if err = json.Unmarshal(res.content, &o); err != nil {
+		return
+	}
+
+	return
+}
+
+// OnboardingData request possible values.
+//
+// Please note that even though all parameters are optional,
+// at least one of them needs to be provided in the request.
+//
+// Information that the merchant has entered in their dashboard will not be overwritten.
+type OnboardingData struct {
+	Organization struct {
+		Name               string   `json:"name,omitempty"`
+		Address            *Address `json:"address,omitempty"`
+		RegistrationNumber string   `json:"registrationNumber,omitempty"`
+		VatNumber          string   `json:"vatNumber,omitempty"`
+		VatRegulation      string   `json:"vatRegulation,omitempty"`
+	} `json:"organization,omitempty"`
+	Profile struct {
+		Name         string       `json:"name,omitempty"`
+		URL          string       `json:"url,omitempty"`
+		Email        string       `json:"email,omitempty"`
+		Description  string       `json:"description,omitempty"`
+		Phone        string       `json:"phone,omitempty"`
+		CategoryCode CategoryCode `json:"categoryCode,omitempty"`
+	} `json:"profile,omitempty"`
+}
+
+// SubmitOnboardingData sends data that will be prefilled in the merchant’s onboarding.
+// Please note that the data you submit will only be processed when the onboarding status is needs-data.
+//
+// See: https://docs.mollie.com/reference/v2/onboarding-api/submit-onboarding-data
+func (os *OnboardingService) SubmitOnboardingData(d *OnboardingData) (err error) {
+	req, err := os.client.NewAPIRequest(http.MethodPost, onboardingTarget, d)
+	if err != nil {
+		return
+	}
+
+	_, err = os.client.Do(req)
+	if err != nil {
+		return
+	}
+
+	return
+}


Test patch:
diff --git a/mollie/onboarding_test.go b/mollie/onboarding_test.go
new file mode 100644
index 0000000..f45e71a
--- /dev/null
+++ b/mollie/onboarding_test.go
@@ -0,0 +1,121 @@
+package mollie
+
+import (
+	"net/http"
+	"net/url"
+	"strings"
+	"testing"
+
+	"github.com/VictorAvelar/mollie-api-go/v2/testdata"
+)
+
+func TestOnboardingService_GetOnboardingStatus(t *testing.T) {
+	setEnv()
+	setup()
+	defer func() {
+		teardown()
+		unsetEnv()
+	}()
+
+	tMux.HandleFunc("/"+onboardingTarget, func(rw http.ResponseWriter, r *http.Request) {
+		testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
+		testMethod(t, r, "GET")
+		if _, ok := r.Header[AuthHeader]; !ok {
+			rw.WriteHeader(http.StatusUnauthorized)
+		}
+
+		rw.WriteHeader(http.StatusOK)
+		_, _ = rw.Write([]byte(testdata.GetOnboardingStatusResponse))
+	})
+
+	res, err := tClient.Onboarding.GetOnboardingStatus()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if res.Status != CompletedOnboardingStatus {
+		t.Error("unexpected onboarding status")
+	}
+}
+
+func TestOnboardingService_SubmitOnboardingData(t *testing.T) {
+	setEnv()
+	setup()
+	defer func() {
+		teardown()
+		unsetEnv()
+	}()
+
+	tMux.HandleFunc("/"+onboardingTarget, func(rw http.ResponseWriter, r *http.Request) {
+		testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
+		testMethod(t, r, "POST")
+		if _, ok := r.Header[AuthHeader]; !ok {
+			rw.WriteHeader(http.StatusUnauthorized)
+		}
+
+		rw.WriteHeader(http.StatusCreated)
+		return
+	})
+
+	od := OnboardingData{}
+	od.Organization.Name = "Testing Org. B.V."
+
+	err := tClient.Onboarding.SubmitOnboardingData(&od)
+	if err != nil {
+		t.Fatal(err)
+	}
+}
+
+func TestOnboardingService_NewAPIRequestErrors(t *testing.T) {
+	setup()
+	defer teardown()
+	u, _ := url.Parse(tServer.URL)
+	tClient.BaseURL = u
+	tMux.HandleFunc("/"+onboardingTarget, errorHandler)
+
+	_, gerr := tClient.Onboarding.GetOnboardingStatus()
+	gcerr := tClient.Onboarding.SubmitOnboardingData(&OnboardingData{})
+
+	tests := []error{gerr, gcerr}
+
+	for _, tt := range tests {
+		if tt != errBadBaseURL {
+			t.Fail()
+		}
+	}
+}
+
+func TestOnboardingService_HttpRequestErrors(t *testing.T) {
+	setup()
+	defer teardown()
+	tMux.HandleFunc("/"+onboardingTarget, errorHandler)
+
+	_, gerr := tClient.Onboarding.GetOnboardingStatus()
+	gcerr := tClient.Onboarding.SubmitOnboardingData(&OnboardingData{})
+
+	tests := []error{gerr, gcerr}
+
+	for _, tt := range tests {
+		if tt == nil {
+			t.Fail()
+		}
+	}
+}
+
+func TestOnboardingService_EncodingResponseErrors(t *testing.T) {
+	setup()
+	defer teardown()
+	tMux.HandleFunc("/"+onboardingTarget, encodingHandler)
+
+	_, gerr := tClient.Onboarding.GetOnboardingStatus()
+
+	tests := []error{gerr}
+
+	for _, tt := range tests {
+		if tt == nil {
+			t.Fail()
+		} else if !strings.Contains(tt.Error(), "invalid character") {
+			t.Errorf("unexpected error %v", tt)
+		}
+	}
+}
diff --git a/testdata/onboarding.go b/testdata/onboarding.go
new file mode 100644
index 0000000..de54834
--- /dev/null
+++ b/testdata/onboarding.go
@@ -0,0 +1,30 @@
+package testdata
+
+// GetOnboardingStatusResponse example.
+const GetOnboardingStatusResponse = `{
+    "resource": "onboarding",
+    "name": "Mollie B.V.",
+    "signedUpAt": "2018-12-20T10:49:08+00:00",
+    "status": "completed",
+    "canReceivePayments": true,
+    "canReceiveSettlements": true,
+    "_links": {
+        "self": {
+            "href": "https://api.mollie.com/v2/onboarding/me",
+            "type": "application/hal+json"
+        },
+        "dashboard": {
+            "href": "https://www.mollie.com/dashboard/onboarding",
+            "type": "text/html"
+        },
+        "organization": {
+            "href": "https://api.mollie.com/v2/organization/org_12345",
+            "type": "application/hal+json"
+        },
+        "documentation": {
+            "href": "https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status",
+            "type": "text/html"
+        }
+    }
+}
+`