SSLCOMMERZ payment gateway(BD)

SSLCOMMERZ is the first payment gateway in Bangladesh opening doors for merchants to receive payments on the internet via their online stores.

Let’s get started: First of all we may create a database and table, copy the table script and execute it using corresponding database.

CREATE TABLE [dbo].[PaymentLog](
        [PaymentLogID] [int] IDENTITY(1,1) NOT NULL,
        [tran_id] [nvarchar](250) NULL,
        [tran_date] [datetime] NULL,
        [status] [nvarchar](50) NULL,
        [val_id] [nvarchar](50) NULL,
        [amount] [decimal](18, 2) NULL,
        [store_amount] [decimal](18, 2) NULL,
        [currency] [nvarchar](50) NULL,
        [bank_tran_id] [nvarchar](50) NULL,
        [card_type] [nvarchar](50) NULL,
        [card_no] [nvarchar](50) NULL,
        [card_issuer] [nvarchar](50) NULL,
        [card_brand] [nvarchar](50) NULL,
        [card_issuer_country] [nvarchar](50) NULL,
        [card_issuer_country_code] [nvarchar](50) NULL,
        [currency_type] [nvarchar](50) NULL,
        [currency_amount] [decimal](18, 2) NULL,
        [currency_rate] [decimal](18, 2) NULL,
        [base_fair] [decimal](18, 2) NULL,
        [value_a] [nvarchar](50) NULL,
        [value_b] [nvarchar](50) NULL,
        [value_c] [nvarchar](50) NULL,
        [risk_title] [nvarchar](50) NULL,
        [risk_level] [int] NULL,
        [APIConnect] [nvarchar](50) NULL,
        [validated_on] [nvarchar](50) NULL,
        [gw_version] [nvarchar](50) NULL,
 CONSTRAINT [PK_PaymentLog] PRIMARY KEY CLUSTERED 
(
        [PaymentLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

In this post we have use ASP.Net MVC application to perform operations. create a new MVC application and copy the view to your Home page/billing page.

pay_1

Home View

@{
    ViewBag.Title = "Payments";
}

{{pageTitle}}

.ActionLink("Go back", "Index", "Home", new { area = "" }, new { = "navbar-brand" })
.Status
Amount to Pay: 1500

After clicking Pay now button it will redirect to sslcommerz page, select a payment method.

 

pay_2

response message will display like below

pay_3

Home Controller

private PaymentGatewayEntities _ctx = null;
// GET: Home
public ActionResult Index()
{
    string Status = string.Empty;
    vmPaymentPostback result = null;
    try
    {
        result = GetResponseData();
        if (result != null)
        {
            SavePayment(result);
            Status = "Payment Done!";
        }
        else
        {
            Status = "Payment Fails!";
        }
    }
    catch (Exception)
    {
        Status = "";
    }
    ViewBag.Status = Status;
    return View();
}

In our controller we need to reference below .dll

  1. using Newtonsoft.Json;
  2. using System.IO;
  3. using System.Net;

Response Data

public vmPaymentPostback GetResponseData()
{
    vmPaymentPostback objrspParam = null;
    string[] keys = Request.Form.AllKeys;
    var key = keys[1]; //1 = val_id
    var valId = Request.Form[keys[1]]; //1 = val_id
    var storeID = "test_storeID"; //Replace with LiveID
    var storePass = "test_storePass"; //Replace with LivePassword
    var validateurl = "https://securepay.sslcommerz.com/validator/api/testbox/validationserverAPI.php?val_id=" + valId + "&Store_Id=" + storeID + "&Store_Passwd=" + storePass + "&v=1&format=json"; //Replace with LiveValidURL
    try
    {
        //request
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(validateurl);
        request.Method = "GET";

        //response
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        objrspParam = JsonConvert.DeserializeObject(reader.ReadToEnd().ToString());
    }
    catch (Exception)
    {
    }
    return objrspParam;
}

Save Transnational data to database

after successful transaction we can now save our transnational data to database.

public int SavePayment(vmPaymentPostback _Payment)
{
    int status = 0;
    try
    {
        PaymentLog objPay = new PaymentLog
        {
            tran_id = _Payment.tran_id,
            tran_date = Convert.ToDateTime(_Payment.tran_date),
            status = _Payment.status,
            val_id = _Payment.status,
            amount = _Payment.amount,
            store_amount = _Payment.store_amount,
            currency = _Payment.currency,
            bank_tran_id = _Payment.bank_tran_id,
            card_type = _Payment.card_type,
            card_no = _Payment.card_no,
            card_issuer = _Payment.card_issuer,
            card_brand = _Payment.card_brand,
            card_issuer_country = _Payment.card_issuer_country,
            card_issuer_country_code = _Payment.card_issuer_country_code,
            currency_type = _Payment.currency_type,
            currency_amount = _Payment.currency_amount,
            currency_rate = _Payment.currency_rate,
            base_fair = _Payment.base_fair,
            value_a = _Payment.value_a,
            value_b = _Payment.value_b,
            value_c = _Payment.value_c,
            risk_title = _Payment.risk_title,
            risk_level = _Payment.risk_level,
            APIConnect = _Payment.APIConnect,
            validated_on = _Payment.validated_on,
            gw_version = _Payment.gw_version,
        };

        using (_ctx = new PaymentGatewayEntities())
        {
            _ctx.PaymentLogs.Add(objPay);
            _ctx.SaveChanges();
            status = 1;
        }
    }
    catch
    {
        status = 0;
    }
    return status;
}

Finally it will redirect to merchant application success page.

pay_4 pay_5

Source Code: I’ve uploaded the full source code to download/clone , Hope this will help 🙂

Documentation:

Author:

Since March 2011, have 8+ years of professional experience on software development, currently working as Senior Software Engineer at s3 Innovate Pte Ltd.

11 thoughts on “SSLCOMMERZ payment gateway(BD)”

  • Nayan Pal says:

    Reply

    Is there any need of authority authentication if i just pass the amount of taka from my project in the front page of api??That means i just want to show the amount in the api front page from my project ?

  • Thanks a lot. But when I implement I get an error.That is –
    Not Found
    The requested URL /gwprocess/testbox/v3/process.php was not found on this server.

    Please let me know how can solve this error.
    Thanks in advance.

  • They do not respond to your email and closed merchant account for more than 30 days now. There were some chargeback issues which was resolved but still no update. Unprofessional. Disappointed. They do not care if you use their service or not. But i respect one staff from this team who is Nusrat Shirmin. The day she left as our account manager, a crap person took the responsibility and causing a merchant’s business interruption. I hope the owner sees this and take action. Md. Moinul Hasan is a shit. His phone never gave a clear voice. He talks so slowly and unclear voice. Never helped us with anything while i always felt fine working with Nusrat Shirmin.

    SSLcommerz admin, check your workers. Some are causing your merchant to leave SSLcommerz. That is not good for your business.

Leave a Reply