SDK for C# on the .NET platform
Overview
SDK for C# on the .NET platform is a software development kit for ensuring the interaction of the web services developed in C# with the ecommpay payment platform during the processing of purchases via Payment Page. SDK for C# on the .NET platform is used for signing the parameter set, generating the request for opening Payment Page, verifying callbacks received from ecommpay, and obtaining payment information from the callbacks.
SDK for C# on the .NET platform platform includes:
src
—library program code;composer.json
—quick information about the library usage;- other auxiliary files.
SDK for C# on the .NET platform is compatible with .NET version 6.0 or later and can be downloaded at the following URL: https://github.com/ITECOMMPAY/paymentpage-sdk-net.
Setup
To use SDK for C# on the .NET platform, proceed as follows:
-
Address the following organisational issues of interaction with ecommpay:
- If the company has not obtained a project identifier and a secret key for interacting with the ecommpay payment platform, submit the application for connecting to the payment platform.
- If the company has obtained a project identifier and a secret key for interacting with the ecommpay payment platform, inform the technical support specialists about the company's intention to integrate by using SDK for C# on the .NET platform and coordinate the procedure of launching the functionality.
Install the library that is included in SDK for C# on the .NET platform and link it into the code.
using ECommPay.PaymentPage.SDK;
- Modify the code for using the necessary functionality.
- Coordinate with the ecommpay technical support specialists the procedures and dates of integrating and launching the solution.
The questions about working with SDK for C# on the .NET platform, if any, should be directed to the ecommpay technical support specialists.
Payment form opening
To open the payment form with the help of SDK for C# on the .NET platform, proceed as follows:
- Ensure that the library included in SDK for C# on the .NET platform is linked into the web service source code.
- Create an object of the
Payment
class and specify the values of the payment parameters.dynamic payment = new Payment(<project_id>, "<payment_id_in_your_service>"); // Project and payment identifiers unique within the project payment.payment_amount = 1001; // Payment amount in minor currency units payment.payment_currency = "EUR"; // Currency code in the format of ISO-4217 alpha-3 payment.customer_id = "customer_112"; // Customer identifier payment.payment_description = "Test payment"; // Payment description (optional parameter)
All parameters in this example, except for the payment description, are mandatory for any purchase. You may also need to pass other parameters, for example, the customer's email or phone number when the 3‑D Secure authentication is required. Such parameters must be specified as follows.
payment.customer_phone = "The customer's phone number. Must have from 4 to 24 digits"; payment.customer_email = "The customer's email";
In addition, for card purchases you are recommended to pass the customer's billing address information: the country code in ISO 3166-1 alpha-2 (details), the postal code, the city, and the street address. Such parameters are specified as follows.
payment.billing_postal = "The postal code of the customer's billing address"; payment.billing_country = "The country of the customer's billing address, in ISO 3166-1 alpha-2"; payment.billing_city = "The city of the customer's billing address"; payment.billing_address = "The street of the customer's billing address";
You can also use any other optional parameters available for working with Payment Page (for more information, see Parameters for opening payment form).
- Create an object of the
Gate
class and specify the secret key value received from ecommpay. This is necessary for automatic signature generation.var gate = new Gate('<secret_key>'); // Secret key received from ecommpay
- Generate the URL for opening the payment form.
var paymentUrl = gate.GetPurchasePaymentPageUrl(payment);
A correct URL for opening the payment form contains the signature and the payment parameters.https://paymentpage.ecommpay.com/payment?signature=OEKRlLXKStyoH%2BM 36hokUzLZsuB2gO8JALVnyevcV59akRi29elbheVscAEl0ljcoQVXDE390MwgWg%3D%3D&payment_id=TEST_1555 943554067...
- Use the generated URL for opening the payment form (details).
Callback processing
A callback is an HTTP-POST request that contains payment information in the format of a JSON string. During the work with SDK for C# on the .NET platform, the information from the callbacks can be obtained with the help of the following methods:
getPaymentId()
—returns the payment identifier.getPaymentStatus()
—returns the current payment status.getPayment()
—returns all payment information received in the callback.
To obtain payment information via these methods, proceed as follows:
- Ensure that the library included in SDK for C# on the .NET platform is linked into the web service source code.
- If an object of the
Gate
class was not created during the generation of the request for Payment Page opening—create this object and specify the secret key value received from ecommpay.var gate = new Gate('<secret_key>');
- Create an object of the
Callback
class by using the JSON string that contains the payment information and was received in the callback from the ecommpay payment platform.try { var callback = gate.HandleCallback(data); // Receiving the data verification result } catch (ValidationException e) // Processing possible exceptions { Console.WriteLine(e); // Displaying the error message }
- Use the necessary method.
callback.get_payment_id() // Receiving the payment identifier callback.get_payment_status() // Receiving the current payment status callback.get_payment() // Receiving all payment information
If SDK for C# on the .NET platform is used, the verification of the signature from the callback is performed automatically.