Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,697 members, 7,809,636 topics. Date: Friday, 26 April 2024 at 12:20 PM |
Nairaland Forum / Science/Technology / Webmasters / Howto Query Webpayinterswitch Transaction Status Using Wordpress(wp_remote_get) (1780 Views)
Reasons To Stop Using Wordpress Internal Linking Plugins / Learn How To Build Your E-commerce Website Like Jumia Using Wordpress For Free / Learn How To Create A Simple Forum Like Nairaland Using Wordpress (2) (3) (4)
(1) (Reply)
Howto Query Webpayinterswitch Transaction Status Using Wordpress(wp_remote_get) by dwebdesign(m): 9:31am On Oct 20, 2015 |
for fellow developers on the wordpress platform, beginner, advance and pro level developers. we know that in PHP , its possible to send server request and a response will be sent in an array , $response=array(); containing the headers of the response, the body of the response , $response['body']. Using procedural php, we can use the two functions php makes available which is the 'curl' function and the 'file_get_contents()' function. But do you also know that you can query an api using wordpress function called 'wp_remote_get' , with the transport GET? just to show how is that possible for those that this tutorial will be useful for, if you know hot to develop a wordpress plugin, fill in your header with the right information as you want ********************************************** /** plugin name: query interswitch trans status plugin URL: http://www.1st-websitedesign.com Author : your name here, mine is oluwaseun Author URL: http://www.1st-websitedesign.com version:1.0.0 and other info like the description here */ create and index file, name it query_trans.php, this is a quick one, if you can't get through, do reply via this thread. put this code inside it : function interswitch_page(){ // this function add a new admin menu page you see on the left of your wordpress dashboard. add_menu_page( 'interswitch transation status check', 'Interswitch payment status', 'manage_options', 'interswitch_check_transaction_status', 'interswitch_cb', ''); } add_action('admin_menu', 'interswitch_page'); function interswitch_cb(){// this is the callback function that display a form in your dashboard to collect the product ID, transaction reference, amount paid ?> <div class="wrap"> <h3>Please Provide your Product ID, the transaction reference of product and amount paid to get payment status.</h3> <form method="post" action=""> <input type="text" name="product_id" placeholder="Your Product ID" /> </p> <input type="text" name="transactionreference" Placeholder="Enter Trans. Ref." /> </p> <input type="text" name="amount" placeholder="Amount Paid"/> </p> <input type="submit" name="submit" value="Query Payment Status" class="button-primary" /> </p> </form> </div> <?php if (!empty($_POST['product_id'])) // function that calculates hash and if correct, sends a request to the interswitch server to get request { $total= $_POST['amount']; $txnref=$_POST['transactionreference']; $product_id = $_POST['product_id']; $mac_key = "D3D1D05AFE42AD50818167EAC73C109168A0F108F32645C8B59E897FA930DA44F9230910 DAC9E20641823799A107A02068F7BC0F4CC41D2952E249552255710F"; $query_url = 'https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json'; $url = "$query_url?productid=$product_id&transactionreference=$txnref&amount=$total"; $hash= $product_id.$txnref.$mac_key; $hash = hash('sha512' , $hash); $headers = array( 'Hash' =>$hash, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); $args = array( 'timeout' => 30, 'headers' => $headers ); $response = wp_remote_get( $url, $args ); $response = json_decode($response['body'], true); print_r($hash); //var_dump($response); if (var_dump($response['amount'])==NULL){ echo 'No payment was made'; } else{ echo 'Paid:' .var_dump($response['amount']); } } } if you can't get through, here is the full source code: *********************************************************************************** <?php /** * @package Interswitch payment status and transation status checks * @version 1.0 */ /* Plugin Name: Interswitch webpay Transactions status Plugin URI: http://1st-websitedesign.com/ Description:This plugins query the interswitch webservice to get transation status using the transation details Author: Oluwaseun Paul Version: 1.0 Author URI: http://www.facebook.com/oluwaseunceo */ function interswitch_page(){ add_menu_page( 'interswitch transation status check', 'Interswitch payment status', 'manage_options', 'interswitch_check_transaction_status', 'interswitch_cb', ''); } add_action('admin_menu', 'interswitch_page'); function interswitch_cb(){ ?> <div class="wrap"> <h3>Please Provide your Product ID, the transaction reference of product and amount paid to get payment status.</h3> <form method="post" action=""> <input type="text" name="product_id" placeholder="Your Product ID" /> </p> <input type="text" name="transactionreference" Placeholder="Enter Trans. Ref." /> </p> <input type="text" name="amount" placeholder="Amount Paid"/> </p> <input type="submit" name="submit" value="Query Payment Status" class="button-primary" /> </p> </form> </div> <?php if (!empty($_POST['product_id'])) { $total= $_POST['amount']; $txnref=$_POST['transactionreference']; $product_id = $_POST['product_id']; $mac_key = "D3D1D05AFE42AD50818167EAC73C109168A0F108F32645C8B59E897FA930DA44F9230910 DAC9E20641823799A107A02068F7BC0F4CC41D2952E249552255710F"; $query_url = 'https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json'; $url = "$query_url?productid=$product_id&transactionreference=$txnref&amount=$total"; $hash= $product_id.$txnref.$mac_key; $hash = hash('sha512' , $hash); $headers = array( 'Hash' =>$hash, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); $args = array( 'timeout' => 30, 'headers' => $headers ); $response = wp_remote_get( $url, $args ); $response = json_decode($response['body'], true); print_r($hash); //var_dump($response); if (var_dump($response['amount'])==NULL){ echo 'No payment was made'; } else{ echo 'Paid:' .var_dump($response['amount']); } } } i hope this helps. |
Re: Howto Query Webpayinterswitch Transaction Status Using Wordpress(wp_remote_get) by ladiaj: 5:38pm On Jun 09, 2016 |
Thanks bro. Your code on Howto Query Webpayinterswitch Transaction Status Using Wordpress worked like magic. I was trying to pass through the last hurdle of getting website approved and switch from demo to live. I used the Woocomemerce Interswitch Plugin and I now upgraded by buying the Interswitch Webpay Transaction Log. However there was a requirement that there should be a way to query a transaction to know the status. I googled and your post came up. I simple created a folder, created a .php text file and copied your code inside it. Uploaded as a Plugin, logged into wordpress. Voila! It appeared right there as a plugin and I simply activated it. I tested it and it returned a valid response. It was able to query the Interswtich webpay. Thanks, you're life saver and I must appreciate you. Would like to get in touch perhaps, you're a PHP programmer or something and we might have projects to work together on. Please Email me at: support@inventrium.net Thanks Dipo |
(1) (Reply)
Buy Your Socks Proxy / If You Are A Ghanaian, Come And Collect This Ghana Adsense For #19,999 / I Need A Forum Website
(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 |