Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,828 members, 7,802,652 topics. Date: Friday, 19 April 2024 at 06:17 PM

Payment System Integration Webpay(interswitch) With Php - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Payment System Integration Webpay(interswitch) With Php (3242 Views)

[Tutorial Post] How To Integrate Paystack Payment System With PHP / 10 Nights Of Cloning Nairaland With PHP / Interswitch Webpay Integration With Lightspeed Retail (2) (3) (4)

(1) (Reply) (Go Down)

Payment System Integration Webpay(interswitch) With Php by dplumptre(m): 3:41pm On Dec 11, 2015
Hello guys,

I have worked on a few payment platforms before but this particular one gave me alot of

headaches

also due to the poor documentation , it can be very frustrating but then I decided to do a

quick guide to help anyone facing this.

I had some help from a guy “Akinyele ” after reading some steps he wrote on his blog.


Firstly , there are some basic parameters you will be given from interswitch,

the file is usually called webpay demo merchant , so its the information here that you will use

to set up


1. product_id : This value will be in the demo document from interswitch
2 Amount : The amount, note that this will be in kobo ,thats the way you send it and this can be done by multipling it with 100
3 Currency : This value will be in the demo document usually 566 for naira
4 site_redirect_url : This will be the page you will be redirected to after the payment , here is where you will pickup the request from
interswitch service and know if the transaction was successful or not , here is also where you can
display your transaction receipt
5 site_name : website name
6 cust_id : this is should be unique , I used email
7 txn_ref : this should be a unique code , you can use the time() orappend it with something, the fact is that it much be unique
for every transaction
8 MacKey : This value will be in the demo document, it very long about 100 char or so

9 $hash -> this is a hash you need to create by concatenating some values together , its very important because if there is any little
mistake you wont even see the payment page to begin with , every thing has to be on point, it will also be 512 hashed
10: pay_item_id : This value will be in the demo document from interswitch


To make things easy we can define a constant file and include it in your scripts for the variables that wont change
it will look like this below





define(“SITE_NAME”,”MY SITE NAME”);
define(“BASE_PATH”,”http://localhost/mysite”);
define(“MAC_KEY”,”xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”);
define(“P_ID”,2909); //product id
define(“INTERSWITCH_URL”,”https://stageserv.interswitchng.com/test_paydirect/pay”);
define(“P_I_ID”,101); //pay_item_id
define(“SITE_REDIRECT_URL”,”http://localhost/mysite/response.php/”);





<form name=”payform” id=”payform” action=”<?php echo INTERSWITCH_URL; ?>” method=”post”>
<input name=”product_id” type=”hidden” value=”<?php echo P_ID ; ?>” />
<input name=”amount” type=”hidden” value=”<?php echo $amountwp ; ?>” /> <!– adjusted amount to interswitch –>
<input name=”currency” type=”hidden” value=”566″ />
<input name=”site_redirect_url” type=”hidden” value=”<?php echo SITE_REDIRECT_URL; ?>” />
<input name=”site_name” type=”hidden” value=”<?php echo SITE_NAME; ?>” />
<input name=”txn_ref” type=”hidden” value=”<?php echo $txnref; ?>” />
<input name=”pay_item_id” type=”hidden” value=”<?php echo P_I_ID ; ?>” />
<input name=”hash” type=”hidden” value=”<?php echo $hash; ?>” />
<input name=”cust_name” type=”hidden” value=”<?php echo $name; ?>” /> <!– cust_name user fullname–>
<input name=”cust_id” type=”hidden” value=”<?php echo $email; ?>” /> <!– cust_id user email–>
</form>

$amountwp = amount * 100;

Then the $hash we will form will look like this below
$concatenation = $txnref.P_ID.P_I_ID.$amountwp.SITE_REDIRECT_URL.MAC_KEY;
$hash = hash(‘sha512’,$concatenation);



If all things go well you should see the payment page, but note that you will need to store data in the db I wont cover that part though that pretty basic.

After payment you will redirected to the response.php page here you need to make use of the webpay service

1. note that it returns transaction reference



$txnRef = $_POST[‘txnref’];
$xml = $plumptre->getresponse(P_ID, MAC_KEY, $amountwp, $txnRef);
$response_code = $xml->ResponseCode; //00 means successful
$response_descr = $xml->ResponseDescription ; //Approved Successful



in the above code I am using the xml there is a function I created getresponse() it accepts 4 values
the product id, the mackey, amount * 100, also the transaction ref
so you can create your receipt using the response code if 00 its successful etc



Navigate to my blog to view the getresponse() function details

http://overallheuristic.com/payment-system-integration-webpayinterswitch-with-php/



site : http://overallheuristic.com
twitter : @dplumptre
fb :https://www.facebook.com/

1 Like

Re: Payment System Integration Webpay(interswitch) With Php by spymybox: 3:40pm On Dec 18, 2015
please how can i generate The SHA 512 value productidtransactionreferencemackey. on my site can you help bro ?
Re: Payment System Integration Webpay(interswitch) With Php by ajirapsy(m): 11:13pm On Dec 19, 2015
spymybox:
please how can i generate The SHA 512 value productidtransactionreferencemackey. on my site can you help bro ?

I don't know the language you are using, but for Python, you should use the hashlib library.
Example: hashed_value = hashlib.sha512(productidtransactionreferencemackey).hexdigest()
I once used the above example for a client's project.
Re: Payment System Integration Webpay(interswitch) With Php by dplumptre(m): 12:00pm On Dec 22, 2015
spymybox:
please how can i generate The SHA 512 value productidtransactionreferencemackey. on my site can you help bro ?



like I explained earlier the $hash value we are trying get is the value in the form below

<input name=”hash” type=”hidden” value=”<?php echo $hash; ?>” />

inorder to do this, you will need to concatenate these values together , I intentionally made some of these values

constants so you can just include them in your file since they wont change .

I have explained how I got the values earlier.

$concatenation = $txnref.P_ID.P_I_ID.$amountwp.SITE_REDIRECT_URL.MAC_KEY;

then php comes with its own hash , below


$hash = hash(‘sha512’,$concatenation);

so this is the $hash value you add to the form below

<form name=”payform” id=”payform” action=”<?php echo INTERSWITCH_URL; ?>” method=”post”>
<input name=”product_id” type=”hidden” value=”<?php echo P_ID ; ?>” />
<input name=”amount” type=”hidden” value=”<?php echo $amountwp ; ?>” /> <!– adjusted amount to interswitch –>
<input name=”currency” type=”hidden” value=”566″ />
<input name=”site_redirect_url” type=”hidden” value=”<?php echo SITE_REDIRECT_URL; ?>” />
<input name=”site_name” type=”hidden” value=”<?php echo SITE_NAME; ?>” />
<input name=”txn_ref” type=”hidden” value=”<?php echo $txnref; ?>” />
<input name=”pay_item_id” type=”hidden” value=”<?php echo P_I_ID ; ?>” />
<input name=”hash” type=”hidden” value=”<?php echo $hash; ?>” /> <!-- add $hash here -->
<input name=”cust_name” type=”hidden” value=”<?php echo $name; ?>” /> <!– cust_name user fullname–>
<input name=”cust_id” type=”hidden” value=”<?php echo $email; ?>” /> <!– cust_id user email–>
</form>


if you noticed, I did not add any submit button ,thats because I used ajax , but you can add a manual submit

button as long as it goes to the url "INTERSWITCH_URL" which is this "https://stageserv.interswitchng.com/test_paydirect/pay"

if it goes well ,you will be redirected to the payment page , but you know you will be required to create a database to

store the values also , so that you can have a log incase you need to check or whatever but they actually made this

compulsory because, the interswitch guys will confirm this before moving you LIVE ,just put that in mind as a side

note

1 Like

Re: Payment System Integration Webpay(interswitch) With Php by topePhysics: 11:18am On Apr 18, 2019
Hi, please how do I sign up just for a test account to obtain the details above? Or do I have to fill the registration form in their docs

(1) (Reply)

What Kind Of App Does Nigeria Lack At The Moment? / Please Need Help With Writing These C++ Programmes Please This Is Really Urgent / How Can I Create An Embedded Database In A Desktop Application

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.