1
- using System ;
2
- using System . Threading . Tasks ;
3
1
using Checkout . Common ;
4
2
using Checkout . Payments . Hosted ;
5
3
using Checkout . Payments . Request ;
6
4
using Checkout . Payments . Request . Source ;
7
5
using Checkout . Payments . Response ;
8
6
using Checkout . Tokens ;
9
7
using Shouldly ;
8
+ using System ;
9
+ using System . Collections . Generic ;
10
+ using System . Threading . Tasks ;
10
11
using Xunit . Sdk ;
11
12
12
13
namespace Checkout . Payments
@@ -27,18 +28,15 @@ protected async Task<PaymentResponse> MakeCardPayment(bool shouldCapture = false
27
28
throw new XunitException ( "CaptureOn was provided but the payment is not set for capture" ) ;
28
29
}
29
30
30
- var phone = GetPhone ( ) ;
31
- var billingAddress = GetAddress ( ) ;
32
-
33
31
var requestCardSource = new RequestCardSource
34
32
{
35
33
Name = TestCardSource . Visa . Name ,
36
34
Number = TestCardSource . Visa . Number ,
37
35
ExpiryYear = TestCardSource . Visa . ExpiryYear ,
38
36
ExpiryMonth = TestCardSource . Visa . ExpiryMonth ,
39
37
Cvv = TestCardSource . Visa . Cvv ,
40
- BillingAddress = billingAddress ,
41
- Phone = phone
38
+ BillingAddress = GetAddress ( ) ,
39
+ Phone = GetPhone ( )
42
40
} ;
43
41
44
42
var paymentRequest = new PaymentRequest
@@ -75,18 +73,14 @@ protected async Task<PaymentResponse> MakeTokenPayment()
75
73
var cardTokenResponse = await DefaultApi . TokensClient ( ) . Request ( cardTokenRequest ) ;
76
74
cardTokenResponse . ShouldNotBeNull ( ) ;
77
75
78
- var requestTokenSource = new RequestTokenSource { Token = cardTokenResponse . Token } ;
79
-
80
- var customerRequest = new CustomerRequest { Email = GenerateRandomEmail ( ) } ;
81
-
82
76
var paymentRequest = new PaymentRequest
83
77
{
84
- Source = requestTokenSource ,
78
+ Source = new RequestTokenSource { Token = cardTokenResponse . Token } ,
85
79
Capture = true ,
86
80
Reference = Guid . NewGuid ( ) . ToString ( ) ,
87
81
Amount = 10L ,
88
82
Currency = Currency . USD ,
89
- Customer = customerRequest
83
+ Customer = new CustomerRequest { Email = GenerateRandomEmail ( ) }
90
84
} ;
91
85
92
86
var paymentResponse = await DefaultApi . PaymentsClient ( ) . RequestPayment ( paymentRequest ) ;
@@ -138,34 +132,13 @@ protected async Task<PaymentResponse> Make3dsCardPayment(bool attemptN3d = false
138
132
return paymentResponse ;
139
133
}
140
134
141
- protected static Phone GetPhone ( )
142
- {
143
- return new Phone ( ) { CountryCode = "1" , Number = "4155552671" } ;
144
- }
145
-
146
- protected static Address GetAddress ( )
147
- {
148
- return new Address ( )
149
- {
150
- AddressLine1 = "CheckoutSdk.com" ,
151
- AddressLine2 = "90 Tottenham Court Road" ,
152
- City = "London" ,
153
- State = "London" ,
154
- Zip = "W1T 4TJ" ,
155
- Country = CountryCode . GB
156
- } ;
157
- }
158
-
159
135
protected static HostedPaymentRequest CreateHostedPaymentRequest ( string reference )
160
136
{
161
137
var customer = new CustomerRequest { Name = "Jack Napier" , Email = GenerateRandomEmail ( ) } ;
162
-
163
138
var shippingDetails = new ShippingDetails { Address = GetAddress ( ) , Phone = GetPhone ( ) } ;
139
+ var billing = new BillingInformation { Address = GetAddress ( ) , Phone = GetPhone ( ) } ;
164
140
165
- var billing = new BillingInformation ( ) { Address = GetAddress ( ) , Phone = GetPhone ( ) } ;
166
-
167
-
168
- var recipient = new PaymentRecipient ( )
141
+ var recipient = new PaymentRecipient
169
142
{
170
143
AccountNumber = "1234567" ,
171
144
Country = CountryCode . ES ,
@@ -175,14 +148,6 @@ protected static HostedPaymentRequest CreateHostedPaymentRequest(string referenc
175
148
Zip = "12345"
176
149
} ;
177
150
178
- var products = new Product [ ] { new Product ( ) { Name = "Gold Necklace" , Quantity = 1L , Price = 200L } } ;
179
-
180
- var threeDs = new ThreeDsRequest ( ) { Enabled = false , AttemptN3D = false } ;
181
-
182
- var processing = new ProcessingSettings { Aft = true } ;
183
-
184
- var risk = new RiskRequest { Enabled = false } ;
185
-
186
151
return new HostedPaymentRequest
187
152
{
188
153
Amount = 1000L ,
@@ -193,14 +158,14 @@ protected static HostedPaymentRequest CreateHostedPaymentRequest(string referenc
193
158
Shipping = shippingDetails ,
194
159
Billing = billing ,
195
160
Recipient = recipient ,
196
- Processing = processing ,
197
- Products = products ,
198
- Risk = risk ,
161
+ Processing = new ProcessingSettings { Aft = true } ,
162
+ Products = new List < Product > { new Product { Name = "Gold Necklace" , Quantity = 1L , Price = 200L } } ,
163
+ Risk = new RiskRequest { Enabled = false } ,
199
164
SuccessUrl = "https://example.com/payments/success" ,
200
165
CancelUrl = "https://example.com/payments/success" ,
201
166
FailureUrl = "https://example.com/payments/success" ,
202
167
Locale = "en-GB" ,
203
- ThreeDs = threeDs ,
168
+ ThreeDs = new ThreeDsRequest { Enabled = false , AttemptN3D = false } ,
204
169
Capture = true ,
205
170
CaptureOn = DateTime . UtcNow
206
171
} ;
0 commit comments