Skip to content

Commit

Permalink
Add cancelOrRefund action for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Apr 5, 2017
1 parent 2040009 commit 5354210
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Supported API Calls
* Capture
* Cancel
* [NEXT] Refund
* [NEXT] CancelOrRefund
* CancelOrRefund

## To run example

Expand Down
6 changes: 6 additions & 0 deletions cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ type CancelResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}

// CancelOrRefundResponse is a response structure for Adyen cancelOrRefund
type CancelOrRefundResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}
28 changes: 23 additions & 5 deletions modification_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package adyen

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"
/*
Adyen Modification actions
*/
const (
CaptureType = "capture"
CancelType = "cancel"
CancelOrRefund = "cancelOrRefund"
)

// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
type ModificationGateway struct {
Expand Down Expand Up @@ -40,3 +43,18 @@ func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {

return &val, nil
}

// CancelOrRefund - Perform cancellation for not captured transaction
// otherwise perform refund action
func (a *ModificationGateway) CancelOrRefund(req *Cancel) (*CancelOrRefundResponse, error) {
resp, err := a.execute(CancelOrRefund, req)

if err != nil {
return nil, err
}

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

return &val, nil
}

0 comments on commit 5354210

Please sign in to comment.