Skip to content

Commit a89ff46

Browse files
committed
Extend Hosted Payments & Payment Links to Four API
This commit extends the existing default Hosted Payments & Payment Links to Four CheckoutApi. A few improvements and updates were performed on the existing Request/Response classes to be up to date with the latest API changes.
1 parent 332cc18 commit a89ff46

16 files changed

+264
-132
lines changed

src/CheckoutSdk/Four/CheckoutApi.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Checkout.Instruments.Four;
55
using Checkout.Marketplace;
66
using Checkout.Payments.Four;
7+
using Checkout.Payments.Hosted;
8+
using Checkout.Payments.Links;
79
using Checkout.Risk;
810
using Checkout.Sessions;
911
using Checkout.Tokens;
@@ -23,6 +25,8 @@ public class CheckoutApi : ICheckoutApi
2325
private readonly IWorkflowsClient _workflowsClient;
2426
private readonly ISessionsClient _sessionsClient;
2527
private readonly IMarketplaceClient _marketplaceClient;
28+
private readonly IPaymentLinksClient _paymentLinksClient;
29+
private readonly IHostedPaymentsClient _hostedPaymentsClient;
2630

2731
public CheckoutApi(CheckoutConfiguration configuration)
2832
{
@@ -45,6 +49,8 @@ public CheckoutApi(CheckoutConfiguration configuration)
4549
}
4650

4751
_marketplaceClient = new MarketplaceClient(apiClient, apiFilesClient, configuration);
52+
_paymentLinksClient = new PaymentLinksClient(apiClient, configuration);
53+
_hostedPaymentsClient = new HostedPaymentsClient(apiClient, configuration);
4854
}
4955

5056
public ITokensClient TokensClient()
@@ -96,5 +102,15 @@ public IMarketplaceClient MarketplaceClient()
96102
{
97103
return _marketplaceClient;
98104
}
105+
106+
public IPaymentLinksClient PaymentLinksClient()
107+
{
108+
return _paymentLinksClient;
109+
}
110+
111+
public IHostedPaymentsClient HostedPaymentsClient()
112+
{
113+
return _hostedPaymentsClient;
114+
}
99115
}
100116
}

src/CheckoutSdk/Four/ICheckoutApi.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Checkout.Instruments.Four;
55
using Checkout.Marketplace;
66
using Checkout.Payments.Four;
7+
using Checkout.Payments.Hosted;
8+
using Checkout.Payments.Links;
79
using Checkout.Risk;
810
using Checkout.Sessions;
911
using Checkout.Tokens;
@@ -32,5 +34,9 @@ public interface ICheckoutApi : ICheckoutApiClient
3234
ISessionsClient SessionsClient();
3335

3436
IMarketplaceClient MarketplaceClient();
37+
38+
IPaymentLinksClient PaymentLinksClient();
39+
40+
IHostedPaymentsClient HostedPaymentsClient();
3541
}
3642
}

src/CheckoutSdk/Payments/Hosted/HostedPaymentDetailsResponse.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,5 @@ public class HostedPaymentDetailsResponse : Resource
3232
public string CancelUrl { get; set; }
3333

3434
public string FailureUrl { get; set; }
35-
36-
public string Locale { get; set; }
3735
}
3836
}

src/CheckoutSdk/Payments/Hosted/HostedPaymentRequest.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public class HostedPaymentRequest
1111

1212
public Currency? Currency { get; set; }
1313

14+
public PaymentType? PaymentType { get; set; }
15+
16+
public string PaymentIp { get; set; }
17+
18+
public BillingDescriptor BillingDescriptor { get; set; }
19+
1420
public string Reference { get; set; }
1521

1622
public string Description { get; set; }
@@ -45,10 +51,12 @@ public class HostedPaymentRequest
4551

4652
public DateTime? CaptureOn { get; set; }
4753

48-
public PaymentType? PaymentType { get; set; }
54+
public IList<PaymentSourceType> AllowPaymentMethods { get; set; }
4955

50-
public string PaymentIp { get; set; }
56+
// Only available in Four
5157

52-
public BillingDescriptor BillingDescriptor { get; set; }
58+
public string ProcessingChannelId { get; set; }
59+
60+
public MarketplaceData Marketplace { get; set; }
5361
}
5462
}

src/CheckoutSdk/Payments/Hosted/HostedPaymentResponse.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Checkout.Common;
2+
using System.Collections.Generic;
23

34
namespace Checkout.Payments.Hosted
45
{
@@ -7,5 +8,7 @@ public class HostedPaymentResponse : Resource
78
public string Id { get; set; }
89

910
public string Reference { get; set; }
11+
12+
public IList<object> Warnings { get; set; }
1013
}
1114
}

src/CheckoutSdk/Payments/Links/PaymentLinkDetailsResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ public class PaymentLinkDetailsResponse : Resource
3838

3939
public string Locale { get; set; }
4040

41+
// Only available in Four
42+
43+
public string ProcessingChannelId { get; set; }
44+
45+
public MarketplaceData Marketplace { get; set; }
4146
}
4247
}

src/CheckoutSdk/Payments/Links/PaymentLinkRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ public class PaymentLinkRequest
4848
public string PaymentIp { get; set; }
4949

5050
public BillingDescriptor BillingDescriptor { get; set; }
51+
52+
public IList<PaymentSourceType> AllowPaymentMethods { get; set; }
5153
}
5254
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using Checkout.Common;
22
using System;
3+
using System.Collections.Generic;
34

45
namespace Checkout.Payments.Links
56
{
67
public class PaymentLinkResponse : Resource
78
{
89
public string Id { get; set; }
910

10-
public string PaymentId { get; set; }
11-
1211
public DateTime? ExpiresOn { get; set; }
1312

1413
public string Reference { get; set; }
15-
14+
15+
public IList<object> Warnings { get; set; }
1616
}
1717
}

test/CheckoutSdkTest/CheckoutApiTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Net.Http;
21
using Moq;
32
using Shouldly;
3+
using System.Net.Http;
44
using Xunit;
55

66
namespace Checkout
@@ -19,7 +19,7 @@ public void ShouldInstantiateAndRetrieveClientsDefault()
1919
httpClientFactoryMock.Object);
2020

2121
//Act
22-
var checkoutApi = new CheckoutApi(checkoutConfiguration);
22+
CheckoutApi checkoutApi = new CheckoutApi(checkoutConfiguration);
2323

2424
//Assert
2525
checkoutApi.TokensClient().ShouldNotBeNull();
@@ -50,8 +50,8 @@ public void ShouldInstantiateAndRetrieveClientsFour()
5050
httpClientFactoryMock.Object);
5151

5252
//Act
53-
var checkoutApi = new Four.CheckoutApi(checkoutConfiguration);
54-
53+
Four.ICheckoutApi checkoutApi = new Four.CheckoutApi(checkoutConfiguration);
54+
5555
//Assert
5656
checkoutApi.TokensClient().ShouldNotBeNull();
5757
checkoutApi.CustomersClient().ShouldNotBeNull();
@@ -63,6 +63,8 @@ public void ShouldInstantiateAndRetrieveClientsFour()
6363
checkoutApi.WorkflowsClient().ShouldNotBeNull();
6464
checkoutApi.SessionsClient().ShouldNotBeNull();
6565
checkoutApi.MarketplaceClient().ShouldNotBeNull();
66+
checkoutApi.PaymentLinksClient().ShouldNotBeNull();
67+
checkoutApi.HostedPaymentsClient().ShouldNotBeNull();
6668
}
6769
}
6870
}

test/CheckoutSdkTest/Payments/AbstractPaymentsIntegrationTest.cs

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System;
2-
using System.Threading.Tasks;
31
using Checkout.Common;
42
using Checkout.Payments.Hosted;
53
using Checkout.Payments.Request;
64
using Checkout.Payments.Request.Source;
75
using Checkout.Payments.Response;
86
using Checkout.Tokens;
97
using Shouldly;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Threading.Tasks;
1011
using Xunit.Sdk;
1112

1213
namespace Checkout.Payments
@@ -27,18 +28,15 @@ protected async Task<PaymentResponse> MakeCardPayment(bool shouldCapture = false
2728
throw new XunitException("CaptureOn was provided but the payment is not set for capture");
2829
}
2930

30-
var phone = GetPhone();
31-
var billingAddress = GetAddress();
32-
3331
var requestCardSource = new RequestCardSource
3432
{
3533
Name = TestCardSource.Visa.Name,
3634
Number = TestCardSource.Visa.Number,
3735
ExpiryYear = TestCardSource.Visa.ExpiryYear,
3836
ExpiryMonth = TestCardSource.Visa.ExpiryMonth,
3937
Cvv = TestCardSource.Visa.Cvv,
40-
BillingAddress = billingAddress,
41-
Phone = phone
38+
BillingAddress = GetAddress(),
39+
Phone = GetPhone()
4240
};
4341

4442
var paymentRequest = new PaymentRequest
@@ -75,18 +73,14 @@ protected async Task<PaymentResponse> MakeTokenPayment()
7573
var cardTokenResponse = await DefaultApi.TokensClient().Request(cardTokenRequest);
7674
cardTokenResponse.ShouldNotBeNull();
7775

78-
var requestTokenSource = new RequestTokenSource {Token = cardTokenResponse.Token};
79-
80-
var customerRequest = new CustomerRequest {Email = GenerateRandomEmail()};
81-
8276
var paymentRequest = new PaymentRequest
8377
{
84-
Source = requestTokenSource,
78+
Source = new RequestTokenSource {Token = cardTokenResponse.Token},
8579
Capture = true,
8680
Reference = Guid.NewGuid().ToString(),
8781
Amount = 10L,
8882
Currency = Currency.USD,
89-
Customer = customerRequest
83+
Customer = new CustomerRequest {Email = GenerateRandomEmail()}
9084
};
9185

9286
var paymentResponse = await DefaultApi.PaymentsClient().RequestPayment(paymentRequest);
@@ -138,34 +132,13 @@ protected async Task<PaymentResponse> Make3dsCardPayment(bool attemptN3d = false
138132
return paymentResponse;
139133
}
140134

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-
159135
protected static HostedPaymentRequest CreateHostedPaymentRequest(string reference)
160136
{
161137
var customer = new CustomerRequest {Name = "Jack Napier", Email = GenerateRandomEmail()};
162-
163138
var shippingDetails = new ShippingDetails {Address = GetAddress(), Phone = GetPhone()};
139+
var billing = new BillingInformation {Address = GetAddress(), Phone = GetPhone()};
164140

165-
var billing = new BillingInformation() {Address = GetAddress(), Phone = GetPhone()};
166-
167-
168-
var recipient = new PaymentRecipient()
141+
var recipient = new PaymentRecipient
169142
{
170143
AccountNumber = "1234567",
171144
Country = CountryCode.ES,
@@ -175,14 +148,6 @@ protected static HostedPaymentRequest CreateHostedPaymentRequest(string referenc
175148
Zip = "12345"
176149
};
177150

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-
186151
return new HostedPaymentRequest
187152
{
188153
Amount = 1000L,
@@ -193,14 +158,14 @@ protected static HostedPaymentRequest CreateHostedPaymentRequest(string referenc
193158
Shipping = shippingDetails,
194159
Billing = billing,
195160
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},
199164
SuccessUrl = "https://example.com/payments/success",
200165
CancelUrl = "https://example.com/payments/success",
201166
FailureUrl = "https://example.com/payments/success",
202167
Locale = "en-GB",
203-
ThreeDs = threeDs,
168+
ThreeDs = new ThreeDsRequest {Enabled = false, AttemptN3D = false},
204169
Capture = true,
205170
CaptureOn = DateTime.UtcNow
206171
};

0 commit comments

Comments
 (0)