-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
369 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Represents a customer in a payment request. | ||
/// </summary> | ||
public class CustomerRequest | ||
{ | ||
/// <summary> | ||
/// Gets or sets the unique identifier of the customer. This can be specified in a <see cref="Payments.CustomerSource"/> | ||
/// in subsequent payment requests to use the customer's default payment method. | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer email address. | ||
/// </summary> | ||
public string Email { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer full name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Represents a customer in a payment response. | ||
/// </summary> | ||
public class CustomerResponse | ||
{ | ||
/// <summary> | ||
/// Gets or sets the unique identifier of the customer. This can be specified in a <see cref="Payments.CustomerSource"/> | ||
/// in subsequent payment requests to use the customer's default payment method. | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer email address. | ||
/// </summary> | ||
public string Email { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer full name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Defines the operations available on the Checkout.com Sources API. | ||
/// </summary> | ||
public interface ISourcesClient | ||
{ | ||
/// <summary> | ||
/// Add a reusable payment source that can be used later to make one or more payments. | ||
/// Payment sources are linked to a specific customer and cannot be shared between customers. | ||
/// </summary> | ||
/// <param name="sourceRequest">The source details such as type and billing address.</param> | ||
/// <returns>A task that upon completion contains the source response.</returns> | ||
Task<SourceResponse> RequestAsync(SourceRequest sourceRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Defines the response data of a <see cref="SourceResponse"/>. | ||
/// </summary> | ||
public class ResponseData : Dictionary<string, object> { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Defines the source data of a <see cref="SourceRequest"/>. | ||
/// </summary> | ||
public class SourceData : Dictionary<string, object> { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Checkout.Common; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Indicates the source has been successfully processed. | ||
/// </summary> | ||
public class SourceProcessed : Resource | ||
{ | ||
/// <summary> | ||
/// Gets or sets the id of the source. | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the type of the source. | ||
/// </summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the response code of the source. | ||
/// </summary> | ||
public string ResponseCode { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer of the source. | ||
/// </summary> | ||
public CustomerResponse Customer { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="ResponseData"/> of the source. | ||
/// </summary> | ||
public ResponseData ResponseData { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Checkout.Common; | ||
using System; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Defines a request for a source. | ||
/// </summary> | ||
public class SourceRequest | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="SourceRequest"/> instance. | ||
/// </summary> | ||
/// <param name="type">The payment source type.</param> | ||
/// <param name="billingAddress">The payment source owner's billing address.</param> | ||
public SourceRequest(string type, Address billingAddress) | ||
{ | ||
if (string.IsNullOrWhiteSpace(type)) | ||
throw new ArgumentException("The payment source type is required.", nameof(type)); | ||
|
||
Type = type; | ||
BillingAddress = billingAddress ?? throw new ArgumentNullException("The payment source owner's billing address is required.", nameof(billingAddress)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the type of the source. | ||
/// </summary> | ||
public string Type { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the billing address of the source. | ||
/// </summary> | ||
public Address BillingAddress { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the reference of the source. | ||
/// </summary> | ||
public string Reference { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the phone number of the source. | ||
/// </summary> | ||
public Phone Phone { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the customer of the source. | ||
/// </summary> | ||
public CustomerRequest Customer { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the specific source data of the source. | ||
/// </summary> | ||
public SourceData SourceData { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Checkout.Common; | ||
|
||
namespace Checkout.Sources | ||
{ | ||
/// <summary> | ||
/// Defines a source response. | ||
/// </summary> | ||
public class SourceResponse : Resource | ||
{ | ||
/// <summary> | ||
/// Gets or sets the processed response returned following a successfully processed source (HTTP Status Code 201). | ||
/// </summary> | ||
public SourceProcessed Source { get; set; } | ||
|
||
/// <summary> | ||
/// Gets a value that indicates whether the source is in a pending state. | ||
/// </summary> | ||
public bool IsPending => Source == null; | ||
|
||
/// <summary> | ||
/// Enables the implicit conversion of <see cref="SourceProcessed"/> to <see cref="SourceResponse"/>. | ||
/// This is required for dynamic dispatch during the deserialization of source responses. | ||
/// </summary> | ||
/// <param name="processedResponse">The processed response.</param> | ||
public static implicit operator SourceResponse(SourceProcessed processedResponse) | ||
{ | ||
return new SourceResponse { Source = processedResponse }; | ||
} | ||
} | ||
} |
Oops, something went wrong.