Trouble with HTTP POS REQUEST HASH KEY

322 Views Asked by At

i'm trying to connect to payment gateway and i have this form below to be sent as http post:

<form name="submit2gtpay_form" action="" target="_self" method="post">
   <input type="hidden" name="gtpay_mert_id" value="17" />
   <input type="hidden" name="gtpay_tranx_id" value="" />
   <input type="hidden" name="gtpay_tranx_amt" value="5000" />
   <input type="hidden" name="gtpay_tranx_curr" value="566" />
   <input type="hidden" name="gtpay_cust_id" value="458742" />
   <input type="hidden" name="gtpay_cust_name" value="Test Customer" />
   <input type="hidden" name="gtpay_tranx_memo" value="Mobow" />
   <input type="hidden" name="gtpay_no_show_gtbank" value="yes" />
   <input type="hidden" name="gtpay_echo_data" value="TEST" />
   <input type="hidden" name="gtpay_gway_name" value="" />
   <input type="hidden" name="gtpay_tranx_hash" value="" />
   <input type="hidden" name="gtpay_tranx_noti_url" value="" />
   <input type="submit" value="Pay Via GTPay" name="btnSubmit"/>
   <input type="hidden" name="gtpay_echo_data" value="">
 </form>

I'm required to perform a sha512 hash of [gtpay_tranx_id + gtpay_tranx_amt +gtpay_tranx_noti_url + hashkey]

The transaction amount should be in kobo and all the strings should be concatenated together with the hashkey before getting the sha512 hash of the entire string.

but the value of gtpay_tranx_hash was to be a variable, how do i do that becuase when i echo it, i get missing value

please any help will be appreciated

<?php 
  //the has key requested
 $key = hash('sha512','664879809+500000+myurl+thekeytheysupply');
  //create array of data to be posted
  $post_data['gtpay_mert_id'] = 3649;
  $post_data['gtpay_tranx_id'] = 664879809;
  $post_data['gtpay_tranx_amt'] = 500000;
  $post_data['gtpay_tranx_curr'] =  566;
  $post_data['gtpay_cust_id'] = 458742;
  $post_data['gtpay_cust_name'] = 'Test Customer';
  $post_data['gtpay_tranx_memo'] = 'Mobow';
  $post_data['gtpay_no_show_gtbank'] = 'yes';
  $post_data['gtpay_echo_data'] ='TEST';
  $post_data['gtpay_tranx_hash'] = $key; 
  $post_data['gtpay_tranx_noti_url'] =  'mynotificationurl';

//traverse array and prepare data for posting (key1=value1)
 foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
     }

   //create the final string to be posted using implode()
   $post_string = implode ('&', $post_items);

  //usrl
   $url = 'thebankurl';

    $ch = curl_init(); //initialize curl handle

    // enable below 2 linesfor https sites
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($ch, CURLOPT_URL, $url); //set the url

    //curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable

    //curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_setopt($ch, CURLOPT_POST, 1); //set POST method

   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //set the POST variables

    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

    $response = curl_exec($ch); //run the whole process and return the response

    curl_close($ch); //close the curl handle
0

There are 0 best solutions below