Skip to content

Commit

Permalink
Add refund request
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed May 1, 2017
1 parent 6c12109 commit 8d4c6b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
23 changes: 19 additions & 4 deletions modification_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import "encoding/json"
Adyen Modification actions
*/
const (
CaptureType = "capture"
CancelType = "cancel"
CancelOrRefund = "cancelOrRefund"
CaptureType = "capture"
CancelType = "cancel"
CancelOrRefundType = "cancelOrRefund"
RefundType = "refund"
)

// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
Expand Down Expand Up @@ -47,7 +48,7 @@ func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {
// 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)
resp, err := a.execute(CancelOrRefundType, req)

if err != nil {
return nil, err
Expand All @@ -58,3 +59,17 @@ func (a *ModificationGateway) CancelOrRefund(req *Cancel) (*CancelOrRefundRespon

return &val, nil
}

// Refund - perform refund for already captured request
func (a *ModificationGateway) Refund(req *Refund) (*RefundResponse, error) {
resp, err := a.execute(RefundType, req)

if err != nil {
return nil, err
}

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

return &val, nil
}
15 changes: 15 additions & 0 deletions refund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package adyen

// Refund structure for refund request
type Refund struct {
ModificationAmount *Amount `json:"modificationAmount"`
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
OriginalReference string `json:"originalReference"`
}

// RefundResponse is a response structure for Adyen refund request
type RefundResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}

0 comments on commit 8d4c6b3

Please sign in to comment.