This library provides developers with a simple set of bindings to the 2Checkout purchase routine, Instant Notification, Payment API and Admin API.
Github URL - https://github.com/2Checkout/2checkout-dotnet
Download the repo and grab the TwoCheckout.dll, add to your project’s References and add it’s dependencies listed below.
Example Usage:
TwoCheckoutConfig.SellerID = "1817037"; TwoCheckoutConfig.PrivateKey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3"; //TwoCheckoutConfig.Sandbox = true; <-- Set Mode to use your 2Checkout sandbox account try { var Billing = new AuthBillingAddress(); Billing.addrLine1 = "123 test st"; Billing.city = "Columbus"; Billing.zipCode = "43123"; Billing.state = "OH"; Billing.country = "USA"; Billing.name = "Testing Tester"; Billing.email = "example@2co.com"; Billing.phoneNumber = "5555555555"; var Customer = new ChargeAuthorizeServiceOptions(); Customer.total = (decimal)1.00; Customer.currency = "USD"; Customer.merchantOrderId = "123"; Customer.billingAddr = Billing; Customer.token = "MzIwNzI3ZWQtMjdiNy00NTVhLWFhZTEtZGUyZGQ3MTk1ZDMw"; var Charge = new ChargeService(); var result = Charge.Authorize(Customer); Console.Write(result); } catch (TwoCheckoutException e) { Console.Write(e); }
Example Response:
{TwoCheckout.Authorization} responseMsg: "Successfully authorized the provided credit card" responseCode: "APPROVED" type: "AuthResponse" orderNumber: 205205956108 merchantOrderId: "123" transactionId: 205205956117 currencyCode: "USD" total: 1.00 lineItems: ... {TwoCheckout.AuthLineitem} type: "product" name: "123" quantity: 1 price: 1.0 tangible: "N" productId: "" recurrence: null duration: null startupFee: null options: ... billingAddr: { } {TwoCheckout.AuthBillingAddress} name: "Testing Tester" addrLine1: "123 test st" addrLine2: null city: "Columbus" state: "OH" zipCode: "43123" country: "USA" email: "example@2co.com" phone: null phoneExt: null
Example Usage:
TwoCheckoutConfig.ApiUsername = "APIuser1817037"; TwoCheckoutConfig.ApiPassword = "APIpass1817037"; try { var ServiceObject = new SaleService(); var ArgsObject = new SaleRefundServiceOptions(); ArgsObject.invoice_id = invoice_id; ArgsObject.comment = "test refund"; ArgsObject.category = 5; var result = ServiceObject.Refund(ArgsObject); } catch (TwoCheckoutException e) { // read e.message }
Example Response:
{TwoCheckout.TwoCheckoutResponse} response_code: "OK" response_message: "refund added to invoice"
Example Usage:
var dictionary = new Dictionary(); dictionary.Add("sid", "1817037"); dictionary.Add("mode", "2CO"); dictionary.Add("li_0_type", "product"); dictionary.Add("li_0_name", "Example Product"); dictionary.Add("li_0_price", "1.00"); String PaymentForm = ChargeService.Submit(dictionary);
Example Usage:
TwoCheckoutConfig.SecretWord = "tango"; TwoCheckoutConfig.SellerID = "1817037"; var Return = new ReturnService(); var Args = new ReturnCheckServiceOptions(); Args.total = "0.01"; Args.order_number = Request.Params["order_number"]; Args.key = Request.Params["key"]; bool result = Return.Check(Args);
Example Response:
true
Example Usage:
TwoCheckoutConfig.SecretWord = "tango"; TwoCheckoutConfig.SellerID = "1817037"; var Notification = new NotificationService(); var Args = new NotificationCheckServiceOptions(); Args.invoice_id = Request.Params["invoice_id"]; Args.sale_id = Request.Params["sale_id"]; Args.md5_hash = Request.Params["md5_hash"]; bool result = Notification.Check(Args);
Example Response:
true
TwoCheckoutException exceptions are thrown by if an error has returned. It is best to catch these exceptions so that they can be gracefully handled in your application.
Example Catch
TwoCheckoutConfig.SellerID = "1817037"; TwoCheckoutConfig.PrivateKey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3"; try { var Billing = new AuthBillingAddress(); Billing.addrLine1 = "123 test st"; Billing.city = "Columbus"; Billing.zipCode = "43123"; Billing.state = "OH"; Billing.country = "USA"; Billing.name = "Testing Tester"; Billing.email = "example@2co.com"; Billing.phone = "5555555555"; var Customer = new ChargeAuthorizeServiceOptions(); Customer.total = (decimal)1.00; Customer.currency = "USD"; Customer.merchantOrderId = "123"; Customer.billingAddr = Billing; Customer.token = "MzIwNzI3ZWQtMjdiNy00NTVhLWFhZTEtZGUyZGQ3MTk1ZDMw"; var Charge = new ChargeService(); var result = Charge.Authorize(Customer); Console.Write(result); } catch (TwoCheckoutException e) { Console.Write(e); }
Example Exception
Unauthorized