checkout - CheckoutSDK 2.3.1-unstable0036

Checkout.com SDK for .NET v2 - Docs: https://docs.checkout.com/

PM> Install-Package CheckoutSDK -Version 2.3.1-unstable0036 -Source https://www.myget.org/F/checkout/api/v3/index.json

Copy to clipboard

> nuget.exe install CheckoutSDK -Version 2.3.1-unstable0036 -Source https://www.myget.org/F/checkout/api/v3/index.json

Copy to clipboard

> dotnet add package CheckoutSDK --version 2.3.1-unstable0036 --source https://www.myget.org/F/checkout/api/v3/index.json

Copy to clipboard
<PackageReference Include="CheckoutSDK" Version="2.3.1-unstable0036" />
Copy to clipboard
source https://www.myget.org/F/checkout/api/v3/index.json

nuget CheckoutSDK  ~> 2.3.1-unstable0036
Copy to clipboard

> choco install CheckoutSDK --version 2.3.1-unstable0036 --source https://www.myget.org/F/checkout/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "checkout" -SourceLocation "https://www.myget.org/F/checkout/api/v2"
Install-Module -Name "CheckoutSDK" -RequiredVersion "2.3.1-unstable0036" -Repository "checkout" -AllowPreRelease
Copy to clipboard

Checkout.com .NET SDK

build-status CodeQL

build-status GitHub release NuGet

GitHub license

Getting started

Version 4.0.0 is here!

We improved the initialization of SDK making it easier to understand the available options.
Now NAS accounts are the default instance for the SDK and ABC structure was moved to a previous prefixes.
If you have been using this SDK before, you may find the following important changes:

  • Marketplace module was moved to Accounts module, same for classes and references.
  • In most cases, IDE can help you determine from where to import, but if you’re still having issues don't hesitate to open a ticket.

:rocket: Please check in GitHub releases for all the versions available.

:book: Checkout our official documentation.

:books: Check out our official API documentation guide, where you can also find more usage examples.

How to use the SDK

This SDK can be used with two different pair of API keys provided by Checkout. However, using different API keys imply using specific API features.
Please find in the table below the types of keys that can be used within this SDK.

Account System Public Key (example) Secret Key (example)
Default pk_pkhpdtvabcf7hdgpwnbhw7r2uic sk_m73dzypy7cf3gf5d2xr4k7sxo4e
Previous pk_g650ff27-7c42-4ce1-ae90-5691a188ee7b sk_gk3517a8-3z01-45fq-b4bd-4282384b0a64

Note: sandbox keys have a sbox_ or test_ identifier, for Default and Previous accounts respectively.

PLEASE NEVER SHARE OR PUBLISH YOUR CHECKOUT CREDENTIALS.

If you don't have your own API keys, you can sign up for a test account here.

Default

Default keys client instantiation can be done as follows:

ICheckoutApi api = CheckoutSdk.Builder().StaticKeys()
    .PublicKey("public_key") // optional, only required for operations related with tokens
    .SecretKey("secret_key")
    .Environment(Environment.Sandbox)
    .EnvironmentSubdomain("subdomain") // optional, Merchant-specific DNS name
    .LogProvider(logFactory) // optional
    .HttpClientFactory(httpClientFactory) // optional
    .Build();
    

Default OAuth

The SDK supports client credentials OAuth, when initialized as follows:

ICheckoutApi api = CheckoutSdk.Builder().OAuth()
    .ClientCredentials("client_id", "client_secret")
    .AuthorizationUri(new Uri("https://access.sandbox.checkout.com/connect/token")) // custom authorization URI, optional
    .Scopes(OAuthScope.Files, OAuthScope.Flow) // array of scopes, optional
    .Environment(Environment.Sandbox)
    .EnvironmentSubdomain("subdomain") // optional, Merchant-specific DNS name
    .LogProvider(logFactory) // optional
    .HttpClientFactory(httpClientFactory) // optional
    .Build();

Previous

If your pair of keys matches the previous system type, this is how the SDK should be used:

Checkout.Previous.ICheckoutApi api = CheckoutSdk.Builder()
    .Previous()
    .StaticKeys()
    .PublicKey("public_key") // optional, only required for operations related with tokens
    .SecretKey("secret_key")
    .Environment(Environment.Sandbox)
    .EnvironmentSubdomain("subdomain") // optional, Merchant-specific DNS name
    .LogProvider(logFactory) // optional
    .HttpClientFactory(httpClientFactory) // optional
    .Build();

Then just get any client, and start making requests:

var paymentResponse = await api.PaymentsClient().RequestPayment(new PaymentRequest());

.NET Core Applications

The CheckoutSDK.Extensions.Microsoft package makes it easier to add the Checkout SDK to your .NET Core applications.

Initialize the Configuration of your appsettings.json file:

{
  "Checkout": {
    "SecretKey": "secret_key",
    "PublicKey": "public_key",
    "Environment": "Sandbox",
    "PlatformType": "Default" 
  }
}

You can chose PlatformType Default or Previous depending of the type of keys and account system access.

For OAuth, the configuration file should include the following properties:

{
  "Checkout": {
    "ClientId": "client_id",
    "ClientSecret": "client_secret",
    "AuthorizationUri": "https://access.sandbox.checkout.com/connect/token",
    "Scopes": ["vault", "fx"],
    "Environment": "Sandbox",
    "PlatformType": "DefaultOAuth"
  }
}

Use Environment enum value to choose the desired environment for the SDK, and PlatformType value to choose between the different Account Settings. Then add the configuration:

public class Startup 
{
    public IConfigurationRoot Configuration { get; set; }

    public Startup(IWebHostEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

        Configuration = builder.Build();
    }
}

Register the CheckoutSdk:

public void ConfigureServices(IServiceCollection services)
{
    // LogFactory and HttpClientFactory are optional
    CheckoutServiceCollection.AddCheckoutSdk(services, configuration, logFactory, httpClientFactory);
}

Then take a dependency on ICheckoutApi in your class constructor:

public class CheckoutController : ControllerBase
{
    private readonly ICheckoutApi _api;

    public CheckoutController(ICheckoutApi api)
    {
        _api = api;
    }
}

Please note again that there are 2 different ICheckoutApi interfaces, depending on the way the SDK is built.

Custom HttpClient

Sometimes you need a custom thread pool, or any custom http property, so you can provide your own httpClient configuration as follows.

// Create a custom class from IHttpClientFactory
private class CustomClientFactory : IHttpClientFactory
{
    public HttpClient CreateClient()
    {
        var handler = new HttpClientHandler();
        handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
        var httpClient = new HttpClient(handler);
        httpClient.Timeout = TimeSpan.FromSeconds(2);
        return httpClient;
    }
}

ICheckoutApi api = CheckoutSdk.Builder().StaticKeys()
    .SecretKey("secret_key")
    .Environment(Environment.Sandbox)
    .EnvironmentSubdomain("subdomain") // optional, Merchant-specific DNS name
    .HttpClientFactory(new CustomClientFactory()) // optional
    .Build();

Logging

The SDK supports custom LogProvider that extends from Microsoft.Extensions.Logging ILoggerFactory, you need to provide your configuration as follows.

var logFactory = new NLogLoggerFactory();
_log = logFactory.CreateLogger(typeof(SandboxTestFixture));

ICheckoutApi api = CheckoutSdk.Builder().StaticKeys()
    .SecretKey("secret_key")
    .Environment(Environment.Sandbox)
    .EnvironmentSubdomain("subdomain") // optional, Merchant-specific DNS name
    .LogProvider(logFactory)
    .Build();

Exception handling

All the API responses that do not fall in the 2** status codes will cause a CheckoutApiException. The exception encapsulates the requestId, httpStatusCode and a map of errorDetails, if available.

Building from source

Once you check out the code from GitHub, the project can be built using the netcore CLI tools:

dotnet build

# run tests
dotnet test

The execution of integration tests require the following environment variables set in your system:

  • For Default account systems (NAS): CHECKOUT_DEFAULT_PUBLIC_KEY & CHECKOUT_DEFAULT_SECRET_KEY
  • For Default account systems (OAuth): CHECKOUT_DEFAULT_OAUTH_CLIENT_ID & CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET
  • For Previous account systems (ABC): CHECKOUT_PREVIOUS_PUBLIC_KEY & CHECKOUT_PREVIOUS_SECRET_KEY

Code of Conduct

Please refer to Code of Conduct

Licensing

MIT

.NET SDK 3.0.0 has breaking changes!

  It adds support for the following APIs:
  (on develop branch)
  - Webhooks
  - Events
  - Instruments

  (selected for development)
  - Reconciliation
  - Customer
  - Hosted Payments
  - Sessions

  It adds:
  (on develop branch)
  - the option to send the idempotency header wherever available

  (selected for development)
  - the SchemeId to a processed payment response
  - the merchantInitiated parameter to a payment request

  It changes:
  (on develop branch)
  - the way that contentless API responses are handled; for example: instead of throwing an exception on a 404 response, the new "CheckoutNotFoundApiResponse" object is returned
  • .NETFramework 4.5
    • Newtonsoft.Json (>= 11.0.2)
  • .NETStandard 1.4
    • Microsoft.CSharp (>= 4.4.1)
    • NETStandard.Library (>= 1.6.1)
    • Newtonsoft.Json (>= 11.0.2)
  • .NETStandard 2.0
    • Microsoft.CSharp (>= 4.4.1)
    • Newtonsoft.Json (>= 11.0.2)
  • .NETFramework 4.5: 4.5.0.0
  • .NETStandard 1.4: 1.4.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Checkout.com

Authors

Checkout.com

Project URL

https://github.com/checkout/checkout-sdk-net

License

MIT

Tags

Checkout.com payments gateway sdk

Info

34 total downloads
3 downloads for version 2.3.1-unstable0036
Download (166.98 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
2.3.1-unstable0036 166.98 KB Thu, 12 Nov 2020 10:38:54 GMT 3
2.3.1-unstable0031 162.93 KB Wed, 11 Nov 2020 10:48:55 GMT 1
2.3.1-unstable0028 147.51 KB Wed, 20 May 2020 09:18:00 GMT 1
2.3.1-unstable0024 157.03 KB Wed, 22 Jul 2020 08:34:51 GMT 1
2.3.1-unstable0017 154.93 KB Wed, 17 Jun 2020 12:10:53 GMT 1
2.3.1-unstable0012 154.37 KB Wed, 10 Jun 2020 09:08:55 GMT 1
2.3.1-task-process-con0001 159.31 KB Tue, 10 Nov 2020 11:46:55 GMT 2
2.3.1-task-int-96-add-0001 154.45 KB Wed, 10 Jun 2020 08:53:56 GMT 2
2.3.1-task-int-67-add-0001 147.57 KB Wed, 20 May 2020 09:11:52 GMT 3
2.3.1-task-int-152-add0001 167.4 KB Thu, 12 Nov 2020 21:20:53 GMT 1
2.3.1-task-int-147-add0001 167.13 KB Thu, 12 Nov 2020 19:55:52 GMT 1
2.3.1-task-int-132-sup0001 155.01 KB Wed, 17 Jun 2020 11:48:01 GMT 1
2.3.1-task-int-110-add0001 163 KB Wed, 11 Nov 2020 10:24:00 GMT 1
2.3.1-task-int-103-add0001 167.04 KB Thu, 12 Nov 2020 10:33:59 GMT 2
2.3.1-story-int-163-re0001 174.58 KB Wed, 25 Nov 2020 17:49:00 GMT 1
2.3.0 147.38 KB Wed, 20 May 2020 12:53:51 GMT 2
2.2.1-unstable0010 129.64 KB Thu, 30 Apr 2020 08:41:08 GMT 1
2.2.1-unstable0007 129.61 KB Fri, 17 Apr 2020 10:28:06 GMT 1
2.2.1-unstable0001 129.14 KB Mon, 16 Mar 2020 13:33:11 GMT 1
2.2.1-task-upgrade-cak0001 129.19 KB Mon, 16 Mar 2020 13:22:00 GMT 2
2.2.1-task-cp-1868-int0001 129.7 KB Thu, 23 Apr 2020 09:56:11 GMT 2
2.2.0 129.02 KB Mon, 17 Feb 2020 11:09:47 GMT 1
0.2.0 119.64 KB Fri, 28 Sep 2018 11:34:09 GMT 2