Skip to content

Commit

Permalink
Merge pull request #160 from VictorAvelar/feature/add-partner-status
Browse files Browse the repository at this point in the history
add organization partner status action
  • Loading branch information
VictorAvelar committed Oct 31, 2021
2 parents 4b37358 + d003b16 commit 704f57e
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 3 deletions.
70 changes: 70 additions & 0 deletions docs/README.md
Expand Up @@ -1848,6 +1848,35 @@ type OrganizationLinks struct {
OrganizationLinks describes all the possible links to be returned with a
organization object.

#### type OrganizationPartnerLinks

```go
type OrganizationPartnerLinks struct {
Self *URL `json:"self,omitempty"`
Documentation *URL `json:"documentation,omitempty"`
SignUpLink *URL `json:"signuplink,omitempty"`
}
```

OrganizationPartnerLinks is an object with several URL objects relevant to the
partner resource.

#### type OrganizationPartnerStatus

```go
type OrganizationPartnerStatus struct {
IsCommissionPartner bool `json:"isCommissionPartner,omitempty"`
PartnerContractUpdateAvailable bool `json:"partnerContractUpdate_available,omitempty"`
Resource string `json:"resource,omitempty"`
PartnerType PartnerType `json:"partnerType,omitempty"`
UserAgentTokens []*UserAgentToken `json:"userAgentTokens,omitempty"`
PartnerContractSignedAt *time.Time `json:"partnerContractSignedAt,omitempty"`
Links OrganizationPartnerLinks `json:"_links,omitempty"`
}
```

OrganizationPartnerStatus response descriptor.

#### type OrganizationsService

```go
Expand All @@ -1872,6 +1901,17 @@ func (os *OrganizationsService) GetCurrent() (o *Organization, err error)

GetCurrent retrieve the currently authenticated organization

#### func (\*OrganizationsService) GetPartnerStatus

```go
func (os *OrganizationsService) GetPartnerStatus() (ops *OrganizationPartnerStatus, err error)
```

GetPartnerStatus retrieves details about the partner status of the currently
authenticated organization.

See: https://docs.mollie.com/reference/v2/organizations-api/get-partner

#### type PaginationLinks

```go
Expand Down Expand Up @@ -1954,6 +1994,24 @@ Get retrieves all clients.

See: https://docs.mollie.com/reference/v2/partners-api/list-clients

#### type PartnerType

```go
type PartnerType string
```

PartnerType alias for organization partner types.

```go
const (
PartnerTypeOauth PartnerType = "oauth"
PartnerTypeSignUpLink PartnerType = "signuplink"
PartnerTypeUserAgent PartnerType = "useragent"
)
```

Available partner types.

#### type Payment

```go
Expand Down Expand Up @@ -3491,3 +3549,15 @@ type UsedGiftCard struct {
```

UsedGiftCard describes a used gift card.

#### type UserAgentToken

```go
type UserAgentToken struct {
Token string
StartsAt *time.Time
EndsAt *time.Time
}
```

UserAgentToken are time limited valid access tokens.
59 changes: 59 additions & 0 deletions mollie/organizations.go
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"time"
)

// Organization describes an organization detail
Expand Down Expand Up @@ -35,6 +36,42 @@ type OrganizationLinks struct {
Documentation *URL `json:"documentation,omitempty"`
}

// PartnerType alias for organization partner types.
type PartnerType string

// Available partner types.
const (
PartnerTypeOauth PartnerType = "oauth"
PartnerTypeSignUpLink PartnerType = "signuplink"
PartnerTypeUserAgent PartnerType = "useragent"
)

// UserAgentToken are time limited valid access tokens.
type UserAgentToken struct {
Token string
StartsAt *time.Time
EndsAt *time.Time
}

// OrganizationPartnerLinks is an object with several URL objects
// relevant to the partner resource.
type OrganizationPartnerLinks struct {
Self *URL `json:"self,omitempty"`
Documentation *URL `json:"documentation,omitempty"`
SignUpLink *URL `json:"signuplink,omitempty"`
}

// OrganizationPartnerStatus response descriptor.
type OrganizationPartnerStatus struct {
IsCommissionPartner bool `json:"isCommissionPartner,omitempty"`
PartnerContractUpdateAvailable bool `json:"partnerContractUpdate_available,omitempty"`
Resource string `json:"resource,omitempty"`
PartnerType PartnerType `json:"partnerType,omitempty"`
UserAgentTokens []*UserAgentToken `json:"userAgentTokens,omitempty"`
PartnerContractSignedAt *time.Time `json:"partnerContractSignedAt,omitempty"`
Links OrganizationPartnerLinks `json:"_links,omitempty"`
}

// OrganizationsService instance operates over organization resources
type OrganizationsService service

Expand All @@ -48,6 +85,28 @@ func (os *OrganizationsService) GetCurrent() (o *Organization, err error) {
return os.get("v2/organizations/me")
}

// GetPartnerStatus retrieves details about the partner status
// of the currently authenticated organization.
//
// See: https://docs.mollie.com/reference/v2/organizations-api/get-partner
func (os *OrganizationsService) GetPartnerStatus() (ops *OrganizationPartnerStatus, err error) {
req, err := os.client.NewAPIRequest(http.MethodGet, "v2/organizations/me/partner", nil)
if err != nil {
return
}

res, err := os.client.Do(req)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &ops); err != nil {
return
}

return
}

func (os *OrganizationsService) get(uri string) (o *Organization, err error) {
req, err := os.client.NewAPIRequest(http.MethodGet, uri, nil)
if err != nil {
Expand Down
35 changes: 32 additions & 3 deletions mollie/organizations_test.go
Expand Up @@ -61,15 +61,42 @@ func TestOrganizationsService_GetCurrent(t *testing.T) {
}
}

func TestOrganizationsService_GetPartnerStatus(t *testing.T) {
setup()
defer teardown()
_ = tClient.WithAuthenticationValue("access_token")
tMux.HandleFunc("/v2/organizations/me/partner", func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer access_token")
testMethod(t, r, "GET")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(testdata.GetPartnerStatusResponse))
})

res, err := tClient.Organizations.GetPartnerStatus()
if err != nil {
t.Fatal(err)
}

if res.PartnerType != PartnerTypeSignUpLink {
t.Errorf("mismatching info. got %v, want %v", res.PartnerType, PartnerTypeSignUpLink)
}

}

func TestOrganizationsService_HttpRequestErrors(t *testing.T) {
setup()
defer teardown()
tMux.HandleFunc("/v2/organizations/", errorHandler)

_, gerr := tClient.Organizations.Get("org_12345678")
_, gcerr := tClient.Organizations.GetCurrent()
_, gpserr := tClient.Organizations.GetPartnerStatus()

tests := []error{gerr, gcerr}
tests := []error{gerr, gcerr, gpserr}

for _, tt := range tests {
if tt == nil {
Expand All @@ -87,8 +114,9 @@ func TestOrganizationsService_NewAPIRequestErrors(t *testing.T) {

_, gerr := tClient.Organizations.Get("org_12345678")
_, gcerr := tClient.Organizations.GetCurrent()
_, gpserr := tClient.Organizations.GetPartnerStatus()

tests := []error{gerr, gcerr}
tests := []error{gerr, gcerr, gpserr}

for _, tt := range tests {
if tt != errBadBaseURL {
Expand All @@ -104,8 +132,9 @@ func TestOrganizationsService_EncodingResponseErrors(t *testing.T) {

_, gerr := tClient.Organizations.Get("org_12345678")
_, gcerr := tClient.Organizations.GetCurrent()
_, gpserr := tClient.Organizations.GetPartnerStatus()

tests := []error{gerr, gcerr}
tests := []error{gerr, gcerr, gpserr}

for _, tt := range tests {
if tt == nil {
Expand Down
20 changes: 20 additions & 0 deletions testdata/organizations.go
Expand Up @@ -79,3 +79,23 @@ const GetCurrentOrganizationResponse = `{
}
}
}`

const GetPartnerStatusResponse = `{
"resource": "partner",
"partnerType": "signuplink",
"partnerContractSignedAt": "2018-03-20T13:13:37+00:00",
"_links": {
"self": {
"href": "https://api.mollie.com/v2/organizations/me/partner",
"type": "application/hal+json"
},
"documentation": {
"href": "https://docs.mollie.com/reference/v2/partners-api/get-partner",
"type": "text/html"
},
"signuplink": {
"href": "https://www.mollie.com/dashboard/signup/myCode?lang=en",
"type": "text/html"
}
}
}`

0 comments on commit 704f57e

Please sign in to comment.