Skip to content

Commit 3e3f52d

Browse files
Add Forward API client and request handling for forwarding API requests
1 parent d83cb07 commit 3e3f52d

21 files changed

+462
-1
lines changed

src/CheckoutSdk/CheckoutApi.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Checkout.Disputes;
66
using Checkout.Financial;
77
using Checkout.Forex;
8+
using Checkout.Forward;
89
using Checkout.Instruments;
910
using Checkout.Metadata;
1011
using Checkout.Payments;
@@ -43,6 +44,7 @@ public class CheckoutApi : ICheckoutApi
4344
private readonly IIssuingClient _issuingClient;
4445
private readonly IPaymentContextsClient _paymentContextsClient;
4546
private readonly IPaymentSessionsClient _paymentSessionsClient;
47+
private readonly IForwardClient _forwardClient;
4648

4749
public CheckoutApi(CheckoutConfiguration configuration)
4850
{
@@ -72,6 +74,7 @@ public CheckoutApi(CheckoutConfiguration configuration)
7274
_issuingClient = new IssuingClient(baseApiClient, configuration);
7375
_paymentContextsClient = new PaymentContextsClient(baseApiClient, configuration);
7476
_paymentSessionsClient = new PaymentSessionsClient(baseApiClient, configuration);
77+
_forwardClient = new ForwardClient(baseApiClient, configuration);
7578
}
7679

7780
private static ApiClient BaseApiClient(CheckoutConfiguration configuration)
@@ -204,5 +207,10 @@ public IPaymentSessionsClient PaymentSessionsClient()
204207
{
205208
return _paymentSessionsClient;
206209
}
210+
211+
public IForwardClient ForwardClient()
212+
{
213+
return _forwardClient;
214+
}
207215
}
208216
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Checkout.Forward.Requests;
2+
using Checkout.Forward.Responses;
3+
using System;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace Checkout.Forward
8+
{
9+
public class ForwardClient : AbstractClient, IForwardClient
10+
{
11+
private const string Forward = "forward";
12+
13+
public ForwardClient(IApiClient apiClient, CheckoutConfiguration configuration) :
14+
base(apiClient, configuration, SdkAuthorizationType.SecretKeyOrOAuth)
15+
{
16+
}
17+
18+
public Task<ForwardAnApiResponse> ForwardAnApiRequest(ForwardRequest forwardRequest,
19+
CancellationToken cancellationToken = default)
20+
{
21+
CheckoutUtils.ValidateParams("forwardRequest", forwardRequest);
22+
return ApiClient.Post<ForwardAnApiResponse>(
23+
Forward,
24+
SdkAuthorization(),
25+
forwardRequest,
26+
cancellationToken
27+
);
28+
}
29+
30+
public Task<GetForwardResponse> GetForwardRequest(string forwardId,
31+
CancellationToken cancellationToken = default)
32+
{
33+
CheckoutUtils.ValidateParams("forwardId", forwardId);
34+
return ApiClient.Get<GetForwardResponse>(
35+
BuildPath(Forward, forwardId),
36+
SdkAuthorization(),
37+
cancellationToken
38+
);
39+
}
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Checkout.Forward.Requests;
2+
using Checkout.Forward.Responses;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace Checkout.Forward
7+
{
8+
public interface IForwardClient
9+
{
10+
/// <summary>
11+
/// Forward an API request<br />
12+
/// <b>Beta</b><br />
13+
/// Forwards an API request to a third-party endpoint.<br />
14+
/// For example, you can forward payment credentials you've stored in our Vault to a third-party payment processor.
15+
/// </summary>
16+
Task<ForwardAnApiResponse> ForwardAnApiRequest(ForwardRequest forwardRequest,
17+
CancellationToken cancellationToken = default);
18+
19+
/// <summary>
20+
/// Get forward request<br />
21+
/// Retrieve the details of a successfully forwarded API request.<br />
22+
/// The details can be retrieved for up to 14 days after the request was initiated.
23+
/// </summary>
24+
Task<GetForwardResponse> GetForwardRequest(string forwardId, CancellationToken cancellationToken = default);
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Checkout.Forward.Requests
2+
{
3+
public class DestinationRequest
4+
{
5+
/// <summary>
6+
/// The URL to forward the request to (Required, max 1024 characters) </summary>
7+
public string Url { get; set; }
8+
9+
/// <summary> The HTTP method to use for the forward request (Required) </summary>
10+
public MethodType Method { get; set; }
11+
12+
/// <summary> The HTTP headers to include in the forward request (Required) </summary>
13+
public Headers Headers { get; set; }
14+
15+
/// <summary>
16+
/// The HTTP message body to include in the forward request. If you provide source.id or source.token, you can specify
17+
/// placeholder values in the body. The request will be enriched with the respective payment details from the token or
18+
/// payment instrument you specified. For example, {{card_number}} (Required, max 16384 characters) </summary>
19+
public string Body { get; set; }
20+
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Checkout.Forward.Requests.Sources;
2+
3+
namespace Checkout.Forward.Requests
4+
{
5+
public class ForwardRequest
6+
{
7+
/// <summary>
8+
/// The payment source to enrich the forward request with. You can provide placeholder values in
9+
/// destination_request.body. The request will be enriched with the respective payment credentials from the token or
10+
/// payment instrument you specified. For example, {{card_number}} (Required)
11+
/// </summary>
12+
public AbstractSource Source { get; set; }
13+
14+
/// <summary> The parameters of the forward request (Required) </summary>
15+
public DestinationRequest DestinationRequest { get; set; }
16+
17+
/// <summary>
18+
/// The unique reference for the forward request (Optional, max 80 characters) </summary>
19+
public string Reference { get; set; }
20+
21+
/// <summary>
22+
/// The processing channel ID to associate the billing for the forward request with (Optional,
23+
/// pattern ^(pc)_(\w{26})$)
24+
/// </summary>
25+
public string ProcessingChannelId { get; set; }
26+
27+
/// <summary> Specifies if and how a network token should be used in the forward request (Optional) </summary>
28+
public NetworkToken NetworkToken { get; set; }
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace Checkout.Forward.Requests
4+
{
5+
public class Headers
6+
{
7+
/// <summary>
8+
/// The raw headers to include in the forward request (Required, max 16 characters) </summary>
9+
public IDictionary<string, string> Raw { get; set; } = new Dictionary<string, string>();
10+
11+
/// <summary>
12+
/// The encrypted headers to include in the forward request, as a JSON object with string values encrypted with JSON
13+
/// Web Encryption (JWE) (Optional, max 8192 characters) </summary>
14+
public string Encrypted { get; set; }
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Checkout.Forward.Requests
4+
{
5+
public enum MethodType
6+
{
7+
[EnumMember(Value = "GET")] Get,
8+
9+
[EnumMember(Value = "POST")] Post,
10+
11+
[EnumMember(Value = "PUT")] Put,
12+
13+
[EnumMember(Value = "DELETE")] Delete,
14+
15+
[EnumMember(Value = "PATCH")] Patch,
16+
17+
[EnumMember(Value = "HEAD")] Head,
18+
19+
[EnumMember(Value = "OPTIONS")] Options,
20+
21+
[EnumMember(Value = "TRACE")] Trace
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Checkout.Forward.Requests
2+
{
3+
public class NetworkToken
4+
{
5+
/// <summary> Specifies whether to use a network token (Optional) </summary>
6+
public bool? Enabled { get; set; }
7+
8+
/// <summary>
9+
/// Specifies whether to generate a cryptogram. For example, for customer-initiated transactions (CITs). If you
10+
/// set network_token.enabled to true, you must provide this field (Optional)
11+
/// </summary>
12+
public bool? RequestCryptogram { get; set; }
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Checkout.Forward.Requests.Sources
2+
{
3+
public abstract class AbstractSource
4+
{
5+
protected AbstractSource(SourceType type) { Type = type; }
6+
7+
/// <summary> The payment source type (Required) </summary>
8+
public SourceType? Type { get; set; }
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Checkout.Forward.Requests.Sources
2+
{
3+
public class IdSource : AbstractSource
4+
{
5+
/// <summary>Initializes a new instance of the IdSource class.</summary>
6+
public IdSource() : base(SourceType.Id) { }
7+
8+
/// <summary> The unique identifier of the payment instrument (Required, pattern ^(src)_(\w{26})$) </summary>
9+
public string Id { get; set; }
10+
11+
/// <summary>
12+
/// The unique token for the card's security code. Checkout.com does not store a card's Card Verification Value
13+
/// (CVV) with its associated payment instrument. To pass a CVV with your forward request, use the Frames SDK for
14+
/// Android or iOS to collect and tokenize the CVV and pass the value in this field. The token will replace the
15+
/// placeholder {{card_cvv}} value in destination_request.body (Optional, pattern ^(tok)_(\w{26})$)
16+
/// </summary>
17+
public string CvvToken { get; set; }
18+
}
19+
}

0 commit comments

Comments
 (0)