Skip to content
Advertisement

How to Integrate n genius payment gateway to Laravel

Please Guide me How to integrate ngenius-payment gateway to laravel app Their documentation not enough to integrate with laravel. i am planing to choose with making payments from their websites, and return back to us with a return URL.

Below php code i got from their documentation. but confused to integrate in laravel.

 <?php



$postData = new StdClass(); 

$postData->action = "SALE"; 
$postData->amount = new StdClass();
$postData->amount->currencyCode = "AED"; 
$postData->amount->value = 100; 

 $outlet = "my-oulet-id";
$token = token_key(); //to ken generatig

$json = json_encode($postData);
$ch = curl_init(); 


   curl_setopt($ch, CURLOPT_URL, 'https://api-gateway-uat.ngenius- 
   payments.com/transactions/outlets/".$outlet."/orders'); 
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(
   "Authorization: Bearer ".$token, 
   "Content-Type: application/vnd.ni-payment.v2+json", 
    "Accept: application/vnd.ni-payment.v2+json")); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
   curl_setopt($ch, CURLOPT_POST, 1); 
   curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 

  $output = json_decode(curl_exec($ch)); 
  $order_reference = $output->reference; 
   $order_paypage_url = $output->_links->payment->href; 

  curl_close ($ch);

function token_key(){
$apikey = "api-key";        // enter your API key here
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://identity-uat.ngenius- 
payments.com/auth/realms/ni/protocol/openid-connect/token"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Basic ".$apikey, 
"Content-Type: application/x-www-form-urlencoded")); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,  
http_build_query(array('grant_type' => 
'client_credentials'))); 
$output = json_decode(curl_exec($ch)); 
$access_token = $output->access_token;
return $access_token;
 }
?>

Advertisement

Answer

****Below Code May Help You .. It works for me Up to their payment window****
public function make_payment(){

$outletRef   = "your-outlet-id";                                                                       // set your outlet reference/ID value here (example only)
$apikey      = "your-application-key";       // set your service account API key (example only)


$idServiceURL  = "https://identity-uat.ngenius-payments.com/auth/realms/ni/protocol/openid-connect/token";           // set the identity service URL (example only)
$txnServiceURL = "https://api-gateway-uat.ngenius-payments.com/transactions/outlets/".$outletRef."/orders";             // set the transaction service URL (example only)


$tokenHeaders  = array("Authorization: Basic ".$apikey, "Content-Type: application/x-www-form-urlencoded");
$tokenResponse = invokeCurlRequest("POST", $idServiceURL, $tokenHeaders, http_build_query(array('grant_type' => 'client_credentials')));
$tokenResponse = json_decode($tokenResponse);

$access_token = $tokenResponse->access_token;

$order = new StdClass();

$order->action = "AUTH";                                        // Transaction mode ("AUTH" = authorize only, no automatic settle/capture, "SALE" = authorize + automatic settle/capture)
$order->amount->currencyCode = "AED";                           // Payment currency ('AED' only for now)
$order->amount->value = 01*100;                                   // Minor units (1000 = 10.00 AED)
$order->language = "en";                                        // Payment page language ('en' or 'ar' only)
$order->merchantOrderReference = time();                                        // Payment page language ('en' or 'ar' only)
//$order->merchantAttributes->redirectUrl = "http://premizer.com/test/pp.php";     // A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http://192.168.0.111:8080/n-genius/pp.php";     // A redirect URL to a page on your site to return the customer to
$order->merchantAttributes->redirectUrl = "your page url wich u want to redirect after payment success"; 
// A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http:// 192.168.0.111:8080/n-genius/pp.php";     // A redirect URL to a page on your site to return the customer to
$order = json_encode($order);  


$orderCreateHeaders  = array("Authorization: Bearer ".$access_token, "Content-Type: application/vnd.ni-payment.v2+json", "Accept: application/vnd.ni-payment.v2+json");
$orderCreateResponse = invokeCurlRequest("POST", $txnServiceURL, $orderCreateHeaders, $order);

$orderCreateResponse = json_decode($orderCreateResponse);
$paymentLink           = $orderCreateResponse->_links->payment->href;     // the link to the payment page for redirection (either full-page redirect or iframe)
$orderReference      = $orderCreateResponse->reference;              // the reference to the order, which you should store in your records for future interaction with this order

header("Location: ".$paymentLink);                              // execute redirect
//die();

function invokeCurlRequest($type, $url, $headers, $post) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     

    if ($type == "POST") {

        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

    }

    $server_output = curl_exec ($ch);
    // print_r($server_output);
    // exit();
    curl_close ($ch);

    return $server_output;

}

}

Email them to get a valid test card details .. and check . all the very best .yo you

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement