dimanche 22 septembre 2019

Random String in merchantTransactionId posted to payment processer API

I need to randomly generate a string to be sent to a payment processor to be stored as the Merchant Transaction ID. I am using CodeIgniter PHP framework. Peach Payments API docs says i must use "merchantTransactionId"

Ok so I have added "merchantTransactionId=" to the payment API request and tried to add GenerateRandomString to the API request and ive tried millions of other varaibles too, to no avail. The only time this works for me is if i use $amount, then the amount being paid shows up in the payment processors admin console, but i want a random identifier to show as Transaction ID as i cannot have the paid amounts.

Here is the API request code:

function paymentGateway($amount) {
$url = "https://oppwa.com/v1/checkouts";
$data = "entityId=8ac7a4c96afd0574016afd649e36013f" . "&amount=" . $amount . "&currency=ZAR" . "&paymentType=DB" . "&merchantTransactionId=amarechat_" .  $generateRandomString(24);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:Bearer 
OGFjN2E0Yzk2YWZkMDU3NDAxNmFmZDY0OTk0NDAxMzl8em5KNlBEZnBKRQ=='));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);// this should be set to 
true in production
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
if(curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $responseData;
}


function request($amount) {
    $url = "https://oppwa.com/v1/checkouts";
    $data = "entityId=8acda4cc6b26d8dc016b4654710208e3" .
    "&amount=" . $amount .
    "&currency=ZAR" .
    "&merchantTransactionId=amarechat_" . $generateRandomString .
    "&paymentType=DB";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Authorization:Bearer OGFjZGE0Yzk2YjI2YjMwODAxNmI0NjU0M2UwNDY5ZGF8Q3c3aE1uN0t0Yw=='));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);// this should be set to true in production
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $responseData = curl_exec($ch);
    if(curl_errno($ch)) {
    return curl_error($ch);
    }
    curl_close($ch);
    return $responseData;
}

so where you see &merchantTransactionId" in the above code, i require a random string of text/numbers to be generated and sent off to the payment processor.

This is the code of the front page that generates the payment form based on te amount the user has chosen to deposit: (this works perfectly fine. Only merchantTransactionId doesnt work...

<?php
$responseData = request($amount);
$a = json_decode($responseData, true);
//  print_r($responseData);

?>

<script src="https://oppwa.com/v1/paymentWidgets.js?checkoutId=<?=$a['id']?>"></script>




Aucun commentaire:

Enregistrer un commentaire