@@ -7,13 +7,15 @@ import (
7
7
"github.com/google/uuid"
8
8
"github.com/stretchr/testify/assert"
9
9
10
+ "github.com/checkout/checkout-sdk-go/common"
10
11
"github.com/checkout/checkout-sdk-go/payments"
11
12
"github.com/checkout/checkout-sdk-go/payments/nas"
13
+ "github.com/checkout/checkout-sdk-go/payments/nas/sources"
12
14
)
13
15
14
16
func TestIncrementAuthorization (t * testing.T ) {
15
- t . Skip ( "Skipping because increment authorization needs an authorized payment" )
16
- paymentResponse := makeCardPayment (t , false , 10 )
17
+ paymentResponse := makeCardPaymentPartialAuthorization ( t , false , 10 )
18
+ assert . NotNil (t , paymentResponse , "Expected paymentResponse not to be nil" )
17
19
18
20
metadata := make (map [string ]interface {})
19
21
metadata ["TestIncrementAuthorization" ] = "metadata"
@@ -38,20 +40,26 @@ func TestIncrementAuthorization(t *testing.T) {
38
40
checkerOne : func (response * nas.IncrementAuthorizationResponse , err error ) {
39
41
assert .Nil (t , err )
40
42
assert .NotNil (t , response )
41
- assert .NotEmpty (t , response .Reference )
43
+ assert .Equal (t , int64 ( 5 ), response .Amount )
42
44
assert .NotEmpty (t , response .ActionId )
45
+ assert .NotEmpty (t , response .Currency )
46
+ assert .False (t , response .Approved )
47
+ assert .NotEmpty (t , response .ResponseCode )
48
+ assert .NotEmpty (t , response .ResponseSummary )
49
+ assert .NotEmpty (t , response .ExpiresOn )
50
+ assert .NotEmpty (t , response .ProcessedOn )
51
+ assert .NotEmpty (t , response .Balances )
43
52
assert .NotEmpty (t , response .Links )
44
- assert .NotEmpty (t , response .Links ["payment" ])
45
53
},
46
54
checkerTwo : func (response * nas.GetPaymentResponse , err error ) {
47
55
assert .NotEmpty (t , response .Balances )
48
56
assert .Equal (t , int64 (10 ), response .Balances .TotalAuthorized )
49
- assert .Equal (t , int64 (5 ), response .Balances .TotalCaptured )
57
+ assert .Equal (t , int64 (0 ), response .Balances .TotalCaptured )
50
58
assert .Equal (t , int64 (0 ), response .Balances .TotalRefunded )
51
59
assert .Equal (t , int64 (0 ), response .Balances .TotalVoided )
52
- assert .Equal (t , int64 (0 ), response .Balances .AvailableToCapture )
53
- assert .Equal (t , int64 (5 ), response .Balances .AvailableToRefund )
54
- assert .Equal (t , int64 (0 ), response .Balances .AvailableToVoid )
60
+ assert .Equal (t , int64 (10 ), response .Balances .AvailableToCapture )
61
+ assert .Equal (t , int64 (0 ), response .Balances .AvailableToRefund )
62
+ assert .Equal (t , int64 (10 ), response .Balances .AvailableToVoid )
55
63
},
56
64
},
57
65
}
@@ -69,8 +77,8 @@ func TestIncrementAuthorization(t *testing.T) {
69
77
}
70
78
71
79
func TestIncrementAuthorizationIdempotently (t * testing.T ) {
72
- t . Skip ( "Skipping because increment authorization needs an authorized payment" )
73
- paymentResponse := makeCardPayment (t , false , 10 )
80
+ paymentResponse := makeCardPaymentPartialAuthorization ( t , false , 10 )
81
+ assert . NotNil (t , paymentResponse , "Expected paymentResponse not to be nil" )
74
82
75
83
metadata := make (map [string ]interface {})
76
84
metadata ["TestIncrementAuthorization" ] = "metadata"
@@ -115,7 +123,9 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) {
115
123
checker : func (response1 interface {}, err1 error , response2 interface {}, err2 error ) {
116
124
assert .Nil (t , err1 )
117
125
assert .NotNil (t , response1 )
118
- assert .NotNil (t , err2 )
126
+ assert .Nil (t , err2 )
127
+ assert .NotNil (t , response2 )
128
+ assert .NotEqual (t , response1 .(* nas.IncrementAuthorizationResponse ).ActionId , response2 .(* nas.IncrementAuthorizationResponse ).ActionId )
119
129
},
120
130
},
121
131
}
@@ -128,15 +138,15 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) {
128
138
return client .IncrementAuthorization (tc .paymentId , tc .request , & tc .idempotencyKeyRandom1 )
129
139
}
130
140
predicateOne := func (data interface {}) bool {
131
- response := data .(* payments. CaptureResponse )
141
+ response := data .(* nas. IncrementAuthorizationResponse )
132
142
return response .Links != nil && len (response .Links ) >= 0
133
143
}
134
144
135
145
processTwo := func () (interface {}, error ) {
136
146
return client .IncrementAuthorization (tc .paymentId , tc .request , & tc .idempotencyKeyRandom2 )
137
147
}
138
148
predicateTwo := func (data interface {}) bool {
139
- response := data .(* payments. CaptureResponse )
149
+ response := data .(* nas. IncrementAuthorizationResponse )
140
150
return response .Links != nil && len (response .Links ) >= 0
141
151
}
142
152
@@ -146,3 +156,71 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) {
146
156
})
147
157
}
148
158
}
159
+
160
+ func makeCardPaymentPartialAuthorization (t * testing.T , shouldCapture bool , amount int64 ) * nas.PaymentResponse {
161
+ currentYear := time .Now ().Year () + 1
162
+
163
+ cardSource := sources .NewRequestCardSource ()
164
+ cardSource .Name = "Mr. Test"
165
+ cardSource .Number = "4556447238607884"
166
+ cardSource .ExpiryYear = currentYear
167
+ cardSource .ExpiryMonth = 12
168
+ cardSource .Cvv = "123"
169
+ cardSource .BillingAddress = & common.Address {
170
+ AddressLine1 : "CheckoutSdk.com" ,
171
+ AddressLine2 : "90 Tottenham Court Road" ,
172
+ City : "London" ,
173
+ State : "London" ,
174
+ Zip : "W1T 4TJ" ,
175
+ Country : common .GB ,
176
+ }
177
+ cardSource .Phone = & common.Phone {
178
+ CountryCode : "44" ,
179
+ Number : "1234567890" ,
180
+ }
181
+
182
+ customerRequest := & common.CustomerRequest {
183
+
184
+ Name : "Test Customer" ,
185
+ Phone : & common.Phone {
186
+ CountryCode : "44" ,
187
+ Number : "1234567890" ,
188
+ },
189
+ }
190
+
191
+ paymentIndividualSender := nas .NewRequestIndividualSender ()
192
+ paymentIndividualSender .FirstName = "Mr"
193
+ paymentIndividualSender .LastName = "Test"
194
+ paymentIndividualSender .Address = & common.Address {
195
+ AddressLine1 : "CheckoutSdk.com" ,
196
+ AddressLine2 : "90 Tottenham Court Road" ,
197
+ City : "London" ,
198
+ State : "London" ,
199
+ Zip : "W1T 4TJ" ,
200
+ Country : common .GB ,
201
+ }
202
+
203
+ paymentRequest := nas.PaymentRequest {
204
+ Source : cardSource ,
205
+ Amount : amount ,
206
+ Currency : common .USD ,
207
+ Reference : uuid .New ().String (),
208
+ Description : "Test Payment" ,
209
+ Capture : shouldCapture ,
210
+ Customer : customerRequest ,
211
+ Sender : paymentIndividualSender ,
212
+ AuthorizationType : nas .EstimatedAuthorizationType ,
213
+ PartialAuthorization : & nas.PartialAuthorization {
214
+ Enabled : true ,
215
+ },
216
+ BillingDescriptor : & payments.BillingDescriptor {
217
+ Name : "CheckoutSdk.com" ,
218
+ City : "London" ,
219
+ },
220
+ }
221
+
222
+ response , err := DefaultApi ().Payments .RequestPayment (paymentRequest , nil )
223
+ assert .Nil (t , err , "Expected no error in RequestPayment" )
224
+ assert .NotNil (t , response , "Expected response not to be nil" )
225
+ return response
226
+ }
0 commit comments