.Net

Collecting online payments can be very easy with PayKun. You can provide multiple payment options to your customer and a great checkout experience. Also, they will get all sorts of payment option that will make them buy on the spot.

Prerequisite

Following things will be required before you can begin integration:

Installation

  1. You can download the zip file from below given link PayKun DotNet zip file

  2. Unzip the given file

  3. Download the 'Paykun.dll' file from github.

  4. Add this dll file as a reference in your project

  5. Import this two name spaces

    1. using Paykun;

    2. using Paykun.Json;

  6. Add 'Newtonsoft.Json' NuGet to your project

  7. Implementation

// Customer details
string _name = "<Customer Name>";
string _email = "<Customer Email>";
string _mono = "<Customer Mobile Number>";
// Order details
string _orderId = "ORD" + (new Random()).Next(111111111, 999999999).ToString(); // Order ID must be between 10 To 30 Characters and unique for all transactions
string _productName = "<Name of the product>";
//Amount to be paid
double _amount = 10.0;
//Your return success page url
string _successUrl = "<Success page url>"; //http://www.xyz.com/success
//Your return failed page url
string _failureUrl = "<Failure Url>"; //http://www.xyz.com/failed
//Mandatory
PaykunPayment _payment = new Paykun.PaykunPayment("<Merhcant Id>", "<Access Token>", "<API Secret>", _isLive: true); // Change _isLive to false for sandbox mode, While using sandbox mode you will need to provide credintials for sandbox and not of live environment
//Mandatory
_payment.InitOrder(_orderId, _amount, _productName, _successUrl, _failureUrl);
//Mandatory
_payment.AddCustomer(_name, _email, _mono);
//Add here your shipping detail (Optional)
//If you want to ignore the shipping or billing address, just make all the params an empty string like
//_payment.AddShippingAddress("", "", "", "", "");
_payment.AddShippingAddress("<address>", "<country>", "<state>", "<city>", "<pincode>");
//Add here your billing detail (Optional)
//If you want to ignore the shipping or billing address, just make all the params an empty string like
//_payment.AddBillingAddress("", "", "", "", "");
_payment.AddBillingAddress("<address>", "<country>", "<state>", "<city>", "<pincode>");
//You can set your custom fields here. for ex. you can set order id for which this transaction is initiated
//You will get the same order id when you will call the method _payment.GetTransactionStatus(_reqId)
_payment.SetCustomField(_orderId, "", "", "", "");
/**
* if you want to render your custom form then use _payment.getRequestData(), this will return you with all the require params for the request.
* create form from the 'PkCustomForm' object and make it auto submit or as per your requirements
* */
//PkCustomForm requestData = _payment.getRequestData();
/*To render the direct form*/
string _res = _payment.Submit();
//_res => use this html to render default payment form. if you want custom form then
// uncomment this line of code and comment out submit method
//PkCustomForm requestData = _payment.getRequestData(); ==> For custom form
//Message = _res;

Success/Failure page implementation

exit: Ctrl+↩
//Add this code to your success or failure url page and you will get all the detail about the current transaction
//You will get transaction Id in the success or failed url provided from your side.
//Suppose you have provided success url like http://localhost:8080/transaction_success?payment-id=56156-59572-62823-64618
//Get this transaction Id from the success or failed url and call this below function to get the current transaction detail.
string _reqId = "<assign here your payment-id returned in success or failed url>";
PaykunPayment _payment = new Paykun.PaykunPayment("<Merhcant Id>", "<Access Token>", "<API Secret>");
TransactionStatusRes transRes = _payment.GetTransactionStatus(_reqId);
if (transRes.status == true)
{ //Request status
//handle your response here
if (transRes.data.transaction.status == "Failed")
{
//Failed transaction
}
else if (transRes.data.transaction.status == "Initialized")
{ //Initialized transaction
}
else if (transRes.data.transaction.status == "Success")
{ //Success transaction
}
}
else {
//Request error get here your error description
string error = transRes.errors.errorMessage;
}
//This code should be added in success or failed page

Test your Integration (sandbox)

If you need it for testing purposes you can use our sandbox mode by sending “isLive” parameter to false.

If you need it for testing purposes you should login in Paykun dashboard using sandbox mode and get your testing merchant Id and Device API key(access token).

To test your integration in sandbox environment before going like, you can use our test environment (See how to create one) and use your test credentials, You just have to use isLive=false in your integration, You can use test card details provided here for testing purpose.

  1. Navigate to Account drop down (Top Right corner) and select "Test Mode"

  2. Select "Generate Sandbox Account" to activate your sandbox account

  3. After activating sandbox account,you can click on "Sandbox Login" button to go to sandbox dashboard and use generated username and password login.

  4. Now you have to generate your Device API key from sandbox account from Setting-Security tab

  5. You can get you Merchant ID clicking on profile icon from top right corner.

  6. Now you have to use this API key and Merchant Id in your Demo project for testing purposes. Note: Remember that you can login in Sandbox account from your Live account.

For Live environment

If you want to do real transaction than set "isLive" parameter to true and use your Live MerchantId and AccessToken from Paykun dashboard.

License

The Paykun .Net SDK is released under the MIT License.

For any Assistance

In case of any query, please contact to tech@paykun.com