This SDK provides a wrapper around the PayDock REST API.
For more info on the Paydock API, see our full documentation.
In order to support the different ways our customers use PayDock, we've released 2 versions of the SDK:
- .Net 4.0 SDK (for pre .NET 4.5.1) - deprecated
- .Net Standard SDK - with async support (for net451+ and netcoreapp1.0+)
The best way to get this is on nuget
var charge = new ChargeRequest
{
amount = amount,
currency = "AUD",
customer = new Paydock_dotnet_sdk.Models.Customer
{
email = customerEmail,
payment_source = new PaymentSource
{
gateway_id = "<your gateway id here>",
card_name = "Test Name",
card_number = "4111111111111111",
card_ccv = "123",
expire_month = "10",
expire_year = "2020"
}
}
};
try
{
Config.Initialise(Environment.Sandbox, "<your access token here>");
var result = await new Charges().Add(charge);
if (!result.IsSuccess) {
// handle failed payment
}
}
catch (ResponseException ex)
{
// handle possible error
}
var customer = new CustomerRequest
{
first_name = "john",
last_name = "smith",
email = "email@email.com",
payment_source = new PaymentSource
{
gateway_id = TestConfig.GatewayId,
card_name = "John Smith",
card_number = "4111111111111111",
card_ccv = "123",
expire_month = "10",
expire_year = "2020"
}
};
try
{
Config.Initialise(Environment.Sandbox, "<your access token here>");
var result = await Customers().Add(request);
if (!result.IsSuccess) {
// handle failure to create customer
}
}
catch (ResponseException ex)
{
// handle possible error
}
In most cases, you'll be looking to use just one PayDock Account. However we support using multiple PayDock account, choosing which one you use when create the service classes.
var charge = new ChargeRequest
{
amount = amount,
currency = "AUD",
customer = new Paydock_dotnet_sdk.Models.Customer
{
email = customerEmail,
payment_source = new PaymentSource
{
gateway_id = "<your gateway id here>",
card_name = "Test Name",
card_number = "4111111111111111",
card_ccv = "123",
expire_month = "10",
expire_year = "2020"
}
}
};
try
{
Config.Initialise(Environment.Sandbox, "<this is the default access token>");
var result = await new Charges("<this is a different access token>").Add(charge);
if (!result.IsSuccess) {
// handle failed payment
}
}
catch (ResponseException ex)
{
// handle possible error
}
Webhooks are POSTed to the URL, once you've captured the payload, you can parse this:
// transaction webhook
var tran = (new Webhook()).Parse<TransactionWebhook>(tranJson);
// subscription webhook
var subscription = (new Webhook()).Parse<SubscriptionWebhook>(subscriptionJson);
The different webhook types map to different data objects:
- Transaction Success -> Webhook.Parse()
- Transaction by Subscription Success -> Webhook.Parse()
- Transaction by Subscription Failed -> Webhook.Parse()
- Subscription Creation Success -> Webhook.Parse()
- Subscription Finished -> Webhook.Parse()
- Subscription Updated -> Webhook.Parse()
- Subscription Failed -> Webhook.Parse()
- Refund Requested -> Webhook.Parse()
- Refund Success -> Webhook.Parse()
- Refund Failure -> Webhook.Parse()
- Card Expiration Warning -> Webhook.Parse()