1. Home
  2. Docs
  3. Integration Guide
  4. Using the .NET SDK

Using the .NET SDK

This library allows you to quickly and easily add YenePay as a payment method using C#.

 

Download and reference the SDK on your project

Our library can be added to your project from the NuGet packages store. To use this, open the Package Manager Console in Visual Studio from the View > Other Windows > Package Manager Console menu.

On the console window, make sure that the value of the Default Project dropdown is the project you want to add our SDK reference to. Then type the following command to pull the latest sdk from the NuGet store and add a reference to your project:

PM> Install-Package yenepay.yenepaysdk

 

Alternatively, you can download the .dll library, available on our git page, and add a reference to this dll to your project.
To do this, open your project in Visual Studio, right click on References node under your project name, select Add References and locate the YenePaySDK.dll file you downloaded.

Then, add a using reference in your class

using YenePaySDK;

Generate a Checkout Url

Using the help methods provided by the SDK library, create a new instance of the CheckoutOptions object

CheckoutOptions checkoutoptions = new CheckoutOptions("YOUR_SELLER_CODE", true);

This will create a new instance and sets the UseSandbox property to true, which will point all transactions to our sandbox application and lets you test freely. Set this to false when on production environment

 

Alternatively, you can call the overridden constructor with more setup options:

CheckoutOptions checkoutoptions = new CheckoutOptions("YOUR_SELLER_CODE", "MERCHANT_ORDER_ID", CheckoutType.Express, true, 30, "SUCCESS_URL", "CANCEL_URL", "IPN_URL", "FAILURE_URL"));

The above sample call will create a new instance and sets the checkout process type to Express, use sandbox and order expiration to 30 days.

You can also set these optional checkout options and provide the details of the order to be paid for as follows:

checkoutoptions.Process = CheckoutType.Express; //alternatively you can set this to CheckoutType.Cart if you are including multiple items in a single order

// These properties are optional
checkoutoptions.SuccessReturn = "PAYMENT_SUCCESS_RETURN_URL";
checkoutoptions.CancelReturn = "PAYMENT_CANCEL_RETURN_URL";
checkoutoptions.IpnUrlReturn = "PAYMENT_COMPLETION_NOTIFICATION_URL";
checkoutoptions.FailureReturn = "PAYMENT_FAILURE_RETURN_URL";
checkoutoptions.ExpiresInDays = "NUMBER_OF_DAYS_BEFORE_THE_ORDER_EXPIRES";
checkoutoptions.OrderId = "UNIQUE_ID_THAT_IDENTIFIES_THIS_ORDER_ON_YOUR_SYSTEM";

Once you have completed setting up the checkout options, you then need to provide details of the item being paid for by creating an instance of the CheckoutItem object:

 

CheckoutItem checkoutitem = new CheckoutItem("NAME_OF_ITEM", UNIT_PRICE_OF_ITEM, QUANTITY);

Alternatively you can instantiate this object by calling the overloaded constructor with more parameters for details:

 

CheckoutItem checkoutitem = new CheckoutItem("001", "Sample Item", 100.00, 1, 15.00, NULL, 0.00, 0.00, 5.00);

The above call creates a new instance with these details:

  • Item id: 001
  • Item name: Sample Item
  • Price: 100.00 ETB
  • Quantity: 1
  • VAT: 15.00 ETB
  • TOT: NULL
  • Discount: 0.00 ETB
  • Handling Fee: 0.00 ETB
  • Delivery Fee: 0.00 ETB

Once you have the checkout options and the checkout item in place, you are ready to generate the checkout link as follows:

string yenepayCheckoutUrl = CheckoutHelper.GetCheckoutUrl(checkoutoptions, checkoutitem);

Redirect your customers

After you have generated the checkout URL, you need to redirect your customers to our checkout page. Your customer will then be requested to login with his/her YenePay account and complete the payment there.

 

Receive and verify IPN

Once a payment has been successfully completed, we will send you an Instant Payment Notification (IPN) to the URL you provided. When you receive this notification, you should query our IPN verification url to make sure it is an authentic notification initiated by our servers.

A sample implementation of a method to receive and verify IPN is shown below

[HttpPost]
public void IPNDestination(IPNModel ipnModel)
{
     ipnModel.UseSandbox = true; // set to false on production environment
     if (ipnModel != null)
     {
          bool isIPNValid = CheckIPN(ipnModel).Result;

          if (isIPNValid)
          {
               //mark your order as "Paid" or "Completed" here
          }
    }
}

// verify ipn method
private async Task<bool> CheckIPN(IPNModel model)
{
     return await CheckoutHelper.IsIPNAuthentic(model);
}
Was this article helpful to you? Yes No

How can we help?