.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
1
// Customer details
2
string _name = "<Customer Name>";
3
string _email = "<Customer Email>";
4
string _mono = "<Customer Mobile Number>";
5
6
7
// Order details
8
string _orderId = "ORD" + (new Random()).Next(111111111, 999999999).ToString(); // Order ID must be between 10 To 30 Characters and unique for all transactions
9
string _productName = "<Name of the product>";
10
11
12
//Amount to be paid
13
double _amount = 10.0;
14
15
16
//Your return success page url
17
string _successUrl = "<Success page url>"; //http://www.xyz.com/success
18
19
20
//Your return failed page url
21
string _failureUrl = "<Failure Url>"; //http://www.xyz.com/failed
22
23
24
//Mandatory
25
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
26
27
28
//Mandatory
29
_payment.InitOrder(_orderId, _amount, _productName, _successUrl, _failureUrl);
30
31
32
//Mandatory
33
_payment.AddCustomer(_name, _email, _mono);
34
35
36
37
38
//Add here your shipping detail (Optional)
39
//If you want to ignore the shipping or billing address, just make all the params an empty string like
40
//_payment.AddShippingAddress("", "", "", "", "");
41
_payment.AddShippingAddress("<address>", "<country>", "<state>", "<city>", "<pincode>");
42
43
44
//Add here your billing detail (Optional)
45
//If you want to ignore the shipping or billing address, just make all the params an empty string like
46
//_payment.AddBillingAddress("", "", "", "", "");
47
_payment.AddBillingAddress("<address>", "<country>", "<state>", "<city>", "<pincode>");
48
49
50
//You can set your custom fields here. for ex. you can set order id for which this transaction is initiated
51
//You will get the same order id when you will call the method _payment.GetTransactionStatus(_reqId)
52
_payment.SetCustomField(_orderId, "", "", "", "");
53
54
55
/**
56
* if you want to render your custom form then use _payment.getRequestData(), this will return you with all the require params for the request.
57
* create form from the 'PkCustomForm' object and make it auto submit or as per your requirements
58
* */
59
//PkCustomForm requestData = _payment.getRequestData();
60
61
62
/*To render the direct form*/
63
string _res = _payment.Submit();
64
//_res => use this html to render default payment form. if you want custom form then
65
// uncomment this line of code and comment out submit method
66
//PkCustomForm requestData = _payment.getRequestData(); ==> For custom form
67
//Message = _res;
68
Copied!

Success/Failure page implementation

1
exit: Ctrl+↩
2
//Add this code to your success or failure url page and you will get all the detail about the current transaction
3
//You will get transaction Id in the success or failed url provided from your side.
4
//Suppose you have provided success url like http://localhost:8080/transaction_success?payment-id=56156-59572-62823-64618
5
//Get this transaction Id from the success or failed url and call this below function to get the current transaction detail.
6
7
8
string _reqId = "<assign here your payment-id returned in success or failed url>";
9
PaykunPayment _payment = new Paykun.PaykunPayment("<Merhcant Id>", "<Access Token>", "<API Secret>");
10
TransactionStatusRes transRes = _payment.GetTransactionStatus(_reqId);
11
12
13
if (transRes.status == true)
14
{ //Request status
15
16
17
//handle your response here
18
if (transRes.data.transaction.status == "Failed")
19
{
20
//Failed transaction
21
22
23
}
24
else if (transRes.data.transaction.status == "Initialized")
25
{ //Initialized transaction
26
27
28
}
29
else if (transRes.data.transaction.status == "Success")
30
{ //Success transaction
31
32
33
}
34
}
35
else {
36
//Request error get here your error description
37
string error = transRes.errors.errorMessage;
38
}
39
40
41
//This code should be added in success or failed page
42
Copied!

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.
    Log In to your PayKun Dashboard
    ‘Go to’ the Merchant Account under the ‘Payment Gateway’ section (If you are first-time-login then you will see the ‘Become a Merchant’ option.)
    After the merchant account login, click on your profile picture.
    Select ‘Test mode’.
    Select "Generate Sandbox Account" to activate your sandbox account
    After activating sandbox account,you can click on "Sandbox Login" button to go to sandbox dashboard and use generated username and password login.
    Now you have to generate your Device API key from sandbox account from Setting-Security tab
    You can get you Merchant ID clicking on profile icon from top right corner.
    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 [email protected]
Last modified 9mo ago