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
- Previous Post