Sevenpay payment gateway integration using PHP

Hello friends, today I will show you Sevenpay payment gateway integration using PHP. In my previous post I show you How to integration Paypal payment gateway using PHP?. But today I will teach you on Sevenpay payment gateway. SevenPay is a secure, international, online payment gateway that allow payments and money transfers to be made through the Internet. It has many key features like free account, no setup or monthly fee, 24/7 customer support, mobile devices compatible, every country is welcome and many more. You can check all of them here. They have demo or sandbox account for test transaction. So before live transaction you may have a chance to check the demo version then make your account live.

Before starting my application I recommend you to create a free account here. After creating account login from here. After login you have your own dashboard like below image. Now add your site by clicking “Add your site” link.
sevenpay




After adding your website you work is done. You can add multiple website in a same account. Sevenpay list all your website in menu. Every website has it’s own “ID”. You can find it in “SITES” menu. After one or two days they will send you a conformation mail about your website. If sevenpay grant you website you can do test transaction. When your site approved by sevenpay it automatically in test mode. If you satisfy with sevenpay gateway then you can conver your site from test mode to live mode. For more see this link after login.

Now I write my code for integrate Sevenpay payment gateway using PHP

Step 1: Create form for customer where they put their information.

<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>Sevenpay Payment Gateway Integration</title>
</head>
<body>
	<form target="_new" method="post" action="https://secure.goinpay.com/pay.php">
		<input type="hidden" name="siteID" value=""> <!-- Put your site ID here. You will find it when you add your site. It is numeric.-->
		<input type="hidden" name="OrderID" value="myshop00001"> <!-- Your Order No -->
		<input type="hidden" name="OrderDescription" value="Purchased items">  <!-- Your Order Description -->
		<input type="hidden" name="Amount" value="10">  <!--  Amount to be paid  -->
		<input type="hidden" name="Qty" value="1"> <!--  Product Quantity  -->
		<input type="hidden" name="customerFullName" value="Abhijit Pal">  <!--  Your Customer name  -->
		<input type="hidden" name="customerPhone" value="44-234324544">  <!--  Your Customer Phone No  -->
		<input type="hidden" name="customerAddress" value="42 N K Guin Lane, Srerampur">  <!--  Your Customer Address  -->
		<input type="hidden" name="customerCity" value="Kolkata">  <!--  Your Customer City  -->
		<input type="hidden" name="customerZip" value="712409">  <!--  Your Customer Zip Code  -->
		<input type="hidden" name="customerCountryCode" value="IN">  <!--  Your Customer Country  Code  -->
		<input type="hidden" name="customerStateCode" value="WB">  <!--  Your Customer State  Code  -->
		<input type="hidden" name="customerEmail" value="abhijit@technokrats.in"> <!--  Your Customer Email address  Code  -->
		<input type="hidden" name="returnURL" value="http://abhijitpal.in/sevenpay_gateway/return.php">
		<input type="hidden" name="ApproveURL" value="http://abhijitpal.in/sevenpay_gateway/return_approved.php">
		<input type="hidden" name="DeclineURL" value="http://abhijitpal.in/sevenpay_gateway/return_declined.php">
		<input type="submit" value="Checkout">
	</form>
</body>
</html>

Step 2: Creating a checking page to determine if it comes from sevenpay gateway or not. I name it return_approved.php

<?php
$transaction_id = $_GET['transactionTransactionID'];
function sevenpay_check_order($transaction_id) {
            $url="https://secure.goinpay.com/api.php";
            $values=array(
                       'request'=>"
                                 <xml>
                                 <request>
                                 <transaction>
                                 <transactionType>transactionStatus</transactionType>
                                 <transactionTransactionID>".$transaction_id."</transactionTransactionID>
                                 </transaction>
                                 </request>
                                 </xml>
                                 ",
                   );
            $params='';
 
            foreach ($values as $key=>$value) {
                        $params.="$key=".urlencode($value)."&";
            }
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 180);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            $result=curl_exec($ch);
            if (curl_errno($ch)>0) {
                        exit("CURL ERROR:".curl_errno($ch).":".curl_error($ch));
            }
            curl_close($ch);
            $requestxml=$result;
            $p = xml_parser_create();
            if (!  xml_parse_into_struct($p, $requestxml, $vals, $index)) {
                        exit("can't parse gspay result");
            }
            xml_parser_free($p);
            if (is_array($vals)) 
			{
				foreach ($vals as $key=>$value) {
					//print_r($value);
					if ($value['type']=='complete') {
								$transinfo[$value['tag']]=trim(($value['value']) ? $value['value'] : '');
					}
				}
			}
            return $transinfo;
}
$content = sevenpay_check_order($transaction_id);

/*if you use print_r($content); it will give you the below array like this
Array ( [RESULTSTATUS] => test [RESULTSTATUSCODE] => 2 [RESULTDESCRIPTION] => TestMode [TRANSACTIONID] => TRX1414304364638 [TRANSACTIONTRANSACTIONID] => TRX1414304364638 [TRANSACTIONDATE] => 2014-10-26 07:19:24 [TRANSACTIONTYPE] => sale [TRANSACTIONSTATUS] => test [TRANSACTIONRETURNNUMBER] => AUTH_TESTCARD_APP [TRANSACTIONAMOUNT] => 10 [TRANSACTIONREASON] => TestMode [TRANSACTIONMESSAGE] => Transaction made by test card (app) [TRANSACTIONRETURNDESCRIPTOR] => AUTH_TESTCARD [ORDERID] => myshop00001 [CUSTOMERFULLNAME] => Abhijit Pal [CUSTOMERPHONE] => 44-234324544 [CUSTOMERADDRESS] => 42 N K Guin Lane, Srerampur [CUSTOMERCITY] => Kolkata [CUSTOMERSTATECODE] => XX [CUSTOMERZIP] => 712409 [CUSTOMERCOUNTRYCODE] => 712409 [CUSTOMERSHIPPINGFULLNAME] => [CUSTOMERSHIPPINGPHONE] => [CUSTOMERSHIPPINGADDRESS] => [CUSTOMERSHIPPINGCITY] => [CUSTOMERSHIPPINGSTATECODE] => XX [CUSTOMERSHIPPINGZIP] => [CUSTOMERSHIPPINGCOUNTRYCODE] => )
*/
//This is for demo/test transaction.
if($content['RESULTSTATUS'] == 'test' && $content['TRANSACTIONTYPE'] == 'sale' && $content['TRANSACTIONSTATUS'] == 'test' && $content['RESULTSTATUSCODE'] == 2)
{
	$status = $content['TRANSACTIONSTATUS'];
	$transactionId = $content['TRANSACTIONTRANSACTIONID'];
	$transactionDate = $content['TRANSACTIONDATE'];
	$message = $content['TRANSACTIONMESSAGE'];
	$orderId = $content['ORDERID'];
	$amount = $content['TRANSACTIONAMOUNT'];
	$customerName = $content['CUSTOMERFULLNAME'];
	$customerPhone = $content['CUSTOMERPHONE'];
	$customerAddress = $content['CUSTOMERADDRESS'];
	$customerCity = $content['CUSTOMERCITY'];
	
	/* Now You may insert all this data to database table and sent mail to you customer. After successfull insertion and send mail processs you redirected your customer to success page */
        header('Location:return.php?msg=success');
}
else{
      // Redirected your customer to cancle or error page with a message
      header('Location:return_declined.php?msg=error');
}

/* For live transaction above if condition will change like this
if($content['RESULTSTATUS'] == 'approved' && $content['TRANSACTIONTYPE'] == 'sale' && $content['TRANSACTIONSTATUS'] == 'approved' && $content['RESULTSTATUSCODE'] == 1)
*/

Step 3: Create a return.php where user will be redirected after successfull payment.

<?php
if($_GET['msg']=='success')
{
	echo '<h1 style="padding:100px 50px;">Your payment successfully done. Thank you</h1>';
}
else
{
	echo '<h1 style="padding:100px 50px;color:red;">You are not authorize to view this pay<h1>';
}
?>

Step 4: Create return_declined.php where user will be redirected after incomplete payment.

<?php
if($_GET['msg']=='error')
{
	echo '<h1 style="padding:100px 50px;color:red;">Your payment is declined. Please try again</h1>';
}
else
{
	echo '<h1 style="padding:100px 50px;color:red;">You are not authorize to view this pay<h1>';
}
?>

Using the above method you can easily integrate sevenpay payment gateway in your website.

Spread the love
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share