Skip to content

Commit

Permalink
Add payment cancallation request
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Apr 5, 2017
1 parent fe1ad55 commit 5b9eb42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ g, err := instance.Payment().Authorise(req)
Supported API Calls
* Authorise (only encrypted)
* Capture
* [NEXT] Cancel
* Cancel
* [NEXT] Refund
* [NEXT] CancelOrRefund
Expand Down
14 changes: 14 additions & 0 deletions cancel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package adyen

// Cancel structure for Cancel request
type Cancel struct {
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
OriginalReference string `json:"originalReference"`
}

// CancelResponse is a response structure for Adyen cancellation
type CancelResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}
17 changes: 17 additions & 0 deletions modification_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "encoding/json"
// CaptureType - capture type request, @TODO: move to enums
const CaptureType = "capture"

// CancelType - cancel type request, @TODO: move to enums
const CancelType = "cancel"

// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
type ModificationGateway struct {
*Adyen
Expand All @@ -23,3 +26,17 @@ func (a *ModificationGateway) Capture(req *Capture) (*CaptureResponse, error) {

return &val, nil
}

// Cancel - Perform cancellation of the authorised transaction
func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {
resp, err := a.execute(CancelType, req)

if err != nil {
return nil, err
}

var val CancelResponse
json.NewDecoder(resp.Body).Decode(&val)

return &val, nil
}

0 comments on commit 5b9eb42

Please sign in to comment.