Skip to content

Commit

Permalink
Add disable recurring to recurring gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Dec 27, 2017
1 parent e2746c7 commit cb09201
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions recurring.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package adyen

// RecurringDetailsRequest structure to list all recurring payment associated to a shopperReference
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#recurringdetailsrequest
type RecurringDetailsRequest struct {
MerchantAccount string `json:"merchantAccount"`
ShopperReference string `json:"shopperReference,omitempty"`
Expand All @@ -9,6 +11,8 @@ type RecurringDetailsRequest struct {
}

// RecurringDetailsResult structure to hold the RecurringDetails
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#recurringdetailsresult
type RecurringDetailsResult struct {
CreationDate string `json:"creationDate"`
Details []struct {
Expand All @@ -19,6 +23,8 @@ type RecurringDetailsResult struct {
}

// RecurringDetail structure to hold information associated to a recurring payment
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#recurringdetail
type RecurringDetail struct {
Acquirer string `json:"acquirer"`
AcquirerAccount string `json:"acquirerAccount"`
Expand All @@ -40,6 +46,8 @@ type RecurringDetail struct {
//
// If `RecurringDetailReference` is specified, specific payment ID will be disabled
// otherwise all customer saved payment methods will be disabled
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#disablerequest
type RecurringDisableRequest struct {
MerchantAccount string `json:"merchantAccount"`
ShopperReference string `json:"shopperReference"`
Expand All @@ -50,6 +58,8 @@ type RecurringDisableRequest struct {
}

// RecurringDisableResponse structure to hold response for disable recurring request
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#disableresult
type RecurringDisableResponse struct {
Response string `json:"response"`
}
14 changes: 14 additions & 0 deletions recurring_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ type RecurringGateway struct {
// listRecurringDetailsType - listRecurringDetails type request, @TODO: move to enums
const listRecurringDetailsType = "listRecurringDetails"

// disableRecurringType - disable recurring type request, @TODO: move to enums
const disableRecurringType = "disable"

// ListRecurringDetails - Get list of recurring payments in Adyen
func (a *RecurringGateway) ListRecurringDetails(req *RecurringDetailsRequest) (*RecurringDetailsResult, error) {
resp, err := a.execute(RecurringService, listRecurringDetailsType, req)
Expand All @@ -18,3 +21,14 @@ func (a *RecurringGateway) ListRecurringDetails(req *RecurringDetailsRequest) (*

return resp.listRecurringDetails()
}

// DisableRecurring - disable customer's saved payment method based on a contract type or/and payment method ID
func (a *RecurringGateway) DisableRecurring(req *RecurringDisableRequest) (*RecurringDisableResponse, error) {
resp, err := a.execute(RecurringService, disableRecurringType, req)

if err != nil {
return nil, err
}

return resp.disableRecurring()
}
12 changes: 12 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,15 @@ func (r *Response) listRecurringDetails() (*RecurringDetailsResult, error) {

return &a, nil
}

// disableRecurring - generate Adyen disable recurring
//
// Link - https://docs.adyen.com/developers/api-reference/recurring-api#disableresult
func (r *Response) disableRecurring() (*RecurringDisableResponse, error) {
var a RecurringDisableResponse
if err := json.Unmarshal(r.Body, &a); err != nil {
return nil, err
}

return &a, nil
}

0 comments on commit cb09201

Please sign in to comment.