diff --git a/modification_gateway.go b/modification_gateway.go index ecc6a85..310e36c 100644 --- a/modification_gateway.go +++ b/modification_gateway.go @@ -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 @@ -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 @@ -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 +} diff --git a/refund.go b/refund.go new file mode 100644 index 0000000..f3d5574 --- /dev/null +++ b/refund.go @@ -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"` +}