-
Notifications
You must be signed in to change notification settings - Fork 12
/
modification_gateway.go
99 lines (73 loc) · 2.62 KB
/
modification_gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package adyen
// Adyen Modification actions
const (
captureType = "capture"
cancelType = "cancel"
cancelOrRefundType = "cancelOrRefund"
refundType = "refund"
adjustAuthorisation = "adjustAuthorisation"
technicalCancel = "technicalCancel"
)
// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
type ModificationGateway struct {
*Adyen
}
// Capture - Perform capture payment in Adyen
func (a *ModificationGateway) Capture(req *Capture) (*CaptureResponse, error) {
url := a.adyenURL(PaymentService, captureType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.capture()
}
// Cancel - Perform cancellation of the authorised transaction
func (a *ModificationGateway) Cancel(req *Cancel) (*CancelResponse, error) {
url := a.adyenURL(PaymentService, cancelType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.cancel()
}
// CancelOrRefund - Perform cancellation for not captured transaction
// otherwise perform refund action
func (a *ModificationGateway) CancelOrRefund(req *Cancel) (*CancelOrRefundResponse, error) {
url := a.adyenURL(PaymentService, cancelOrRefundType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.cancelOrRefund()
}
// Refund - perform refund for already captured request
func (a *ModificationGateway) Refund(req *Refund) (*RefundResponse, error) {
url := a.adyenURL(PaymentService, refundType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.refund()
}
// AdjustAuthorisation - perform adjustAuthorisation request to modify already authorised amount
//
// Link - https://docs.adyen.com/developers/payment-modifications#adjustauthorisation
func (a *ModificationGateway) AdjustAuthorisation(req *AdjustAuthorisation) (*AdjustAuthorisationResponse, error) {
url := a.adyenURL(PaymentService, adjustAuthorisation, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.adjustAuthorisation()
}
// TechnicalCancel - perform cancellation without knowing orinal payment reference (PSP), f.e. in case of technical error
//
// Link - https://docs.adyen.com/developers/payment-modifications#technicalcancel
func (a *ModificationGateway) TechnicalCancel(req *TechnicalCancel) (*TechnicalCancelResponse, error) {
url := a.adyenURL(PaymentService, technicalCancel, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.technicalCancel()
}