-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpayment_gateway.go
122 lines (93 loc) · 3.44 KB
/
payment_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package adyen
import "github.com/google/go-querystring/query"
// PaymentGateway - Adyen payment transaction logic
type PaymentGateway struct {
*Adyen
}
// authoriseType - authorise type request, @TODO: move to enums
const authoriseType = "authorise"
// directoryLookupURL - version 2 url for Directory Lookup request
const directoryLookupURL = "directory/v2"
// skipHppUrl - SkipDetails request endpoint
const skipHppURL = "skipDetails"
// authorise3DType - authorise type request, @TODO: move to enums
const authorise3DType = "authorise3d"
// AuthoriseEncrypted - Perform authorise payment in Adyen
//
// To perform recurring payment, AuthoriseEncrypted need to have contract specified and shopperReference
//
// Example:
// &adyen.AuthoriseEncrypted{
// Amount: &adyen.Amount{Value: "2000", Currency: "EUR"},
// MerchantAccount: "merchant-account",
// AdditionalData: &adyen.AdditionalData{Content: r.Form.Get("adyen-encrypted-data")}, // encrypted CC data
// ShopperReference: "unique-customer-reference",
// Recurring: &adyen.Recurring{Contract:adyen.RecurringPaymentRecurring}
// Reference: "some-merchant-reference",
// }
//}
// adyen.Recurring{Contract:adyen.RecurringPaymentRecurring} as one of the contracts
func (a *PaymentGateway) AuthoriseEncrypted(req *AuthoriseEncrypted) (*AuthoriseResponse, error) {
url := a.adyenURL(PaymentService, authoriseType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.authorize()
}
// Authorise - Perform authorise payment in Adyen
//
// Used to perform authorisation transaction without credit card data encrypted
//
// NOTE: Due to PCI compliance, it's not recommended to send credit card data to server
//
// Please use AuthoriseEncrypted instead and adyen frontend encryption library
func (a *PaymentGateway) Authorise(req *Authorise) (*AuthoriseResponse, error) {
url := a.adyenURL(PaymentService, authoriseType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.authorize()
}
// DirectoryLookup - Execute directory lookup request
//
// Link - https://docs.adyen.com/developers/api-reference/hosted-payment-pages-api
func (a *PaymentGateway) DirectoryLookup(req *DirectoryLookupRequest) (*DirectoryLookupResponse, error) {
// Calculate HMAC signature to request
err := req.CalculateSignature(a.Adyen)
if err != nil {
return nil, err
}
url := a.createHPPUrl(directoryLookupURL)
v, _ := query.Values(req)
url = url + "?" + v.Encode()
resp, err := a.executeHpp(url, req)
if err != nil {
return nil, err
}
return resp.directoryLookup()
}
// GetHPPRedirectURL - Generates link, so customer could be redirected
// to perform Hosted Payment Page payments
//
// Link - https://docs.adyen.com/developers/api-reference/hosted-payment-pages-api
func (a *PaymentGateway) GetHPPRedirectURL(req *SkipHppRequest) (string, error) {
// Calculate HMAC signature to request
if err := req.CalculateSignature(a.Adyen); err != nil {
return "", err
}
url := a.createHPPUrl(skipHppURL)
v, _ := query.Values(req)
url = url + "?" + v.Encode()
return url, nil
}
// Authorise3D - Perform authorise payment in Adyen
func (a *PaymentGateway) Authorise3D(req *Authorise3D) (*AuthoriseResponse, error) {
url := a.adyenURL(PaymentService, authorise3DType, PaymentAPIVersion)
resp, err := a.execute(url, req)
if err != nil {
return nil, err
}
return resp.authorize()
}