PHP code example of feexpay / feexpay-php

1. Go to this page and download the library: Download feexpay/feexpay-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

feexpay / feexpay-php example snippets


   
   ut Composer: pay\FeexpayPhp\FeexpayClass("shop's id", "token key API", "callback_url", "mode (LIVE, SANDBOX)");

   // Using the mobile network payment method (MTN, MOOV, MTN CG, ...)
   // paiementLocal(amount, phoneNumber, network, fullname, email, callback_info, custom_id, otp = "")
   // phoneNumber: country code + local number, e.g. Benin 229 + 0166000000 => "2290166000000"
   $reference = $skeleton->paiementLocal(100, "2290166000000", "MTN", "Jon Doe", "[email protected]", "order 123", "my-ref-123");

   if ($reference === null) {
       // The API refused the payment: show the real reason
       $error = $skeleton->getLastError();
       echo $error["message"];      // message returned by the API
       var_dump($error["response"]); // full API response, useful for support
   } else {
       $status = $skeleton->getPaiementStatus($reference);
       var_dump($status);
   }
   

   
   $status = $skeleton->getPaiementStatus($reference);
   // [
   //     "amount"    => 100,
   //     "clientNum" => "2290166000000",
   //     "status"    => "SUCCESSFUL",   // or "PENDING", "FAILED"
   //     "reference" => "63ecaff1-7572-413d-93bb-8cba92bb8c2c",
   // ]
   

   
   // requestToPayWeb(amount, phoneNumber, network, fullname, email, callback_info, custom_id, cancel_url, return_url)
   $response = $skeleton->requestToPayWeb(100, "2250700000000", "network", "Jon Doe", "[email protected]", "order 123", "my-ref-124", "https://your-site.com/cancel", "https://your-site.com/return");

   if ($response === false || empty($response["payment_url"])) {
       echo "Payment could not be initialized";
   } else {
       // $response["reference"] and $response["order_id"] identify the payment
       header("Location: " . $response["payment_url"]);
       exit();
   }
   

   
   // paiementCard(amount, currency, firstName, lastName, email, phoneNumber, city, zip, country) - all arguments are "BJ");

   if ($responseCard !== null) {
       // $responseCard["reference"] identifies the payment
       header("Location: " . $responseCard["payment_url"]);
       exit();
   } else {
       // The API refused the payment: show the real reason
       echo $skeleton->getLastError()["message"];
   }
   

   
    50;
   $id = "shop's id";
   $token = "token key API";
   $callback_url = 'https://www.google.com';
   $mode = 'LIVE';
   $feexpayclass = new Feexpay\FeexpayPhp\FeexpayClass($id, $token, $callback_url, $mode);
   $result = $feexpayclass->init($price, "button_payee");
   

   Route::controller(YourController::class)->group(function () {
       Route::get('feexpay', 'feexpay')->name('feexpay');
       Route::get('feexpay-card', 'feexpayCard')->name('feexpay-card');
   });
   

   

   namespace App\Http\Controllers;
   use Feexpay\FeexpayPhp\FeexpayClass;
   use Illuminate\Http\Request;

   class YourController extends Controller
   {
       // Using the mobile network payment method (MTN, MOOV, MTN CG, ...)
       public function feexpay()
       {
            $skeleton = new FeexpayClass("shop's id", "token key API", "callback_url", "mode (LIVE, SANDBOX)");
            $reference = $skeleton->paiementLocal(100, "2290166000000", "MTN", "Jon Doe", "[email protected]", "order 123", "my-ref-123");
            if ($reference === null) {
                return response($skeleton->getLastError()["message"])->setStatusCode(422);
            }
            $status = $skeleton->getPaiementStatus($reference);
            return response()->json($status);
       }

       // Using the card payment method (VISA, MASTERCARD)
       public function feexpayCard()
       {
            $skeleton = new FeexpayClass("shop's id", "token key API", "callback_url", "mode (LIVE, SANDBOX)");
            $responseCard = $skeleton->paiementCard(100, "XOF", "Jon", "Doe", "[email protected]", "2290166000000", "Cotonou", "00229", "BJ");

            if ($responseCard !== null) {
                return redirect()->away($responseCard["payment_url"]);
            } else {
                // The API refused the payment: show the real reason
                return response($skeleton->getLastError()["message"])->setStatusCode(422);
            }
       }
   }
   

Route::controller(YourController::class)->group(function () {
    Route::get('payment', 'payment')->name('payment') ;
}) ;
   


namespace App\Http\Controllers;
use Feexpay\FeexpayPhp\FeexpayClass;
use Illuminate\Http\Request;

class YourController extends Controller
{
     public function payment()
    {
            $data['price']          =  $price = 50;
            $data['id']             =  $id= "shop's id";
            $data['token']          =  $token= "token key API";
            $data['callback_url']   =  $callback_url= 'https://www.google.com';
            $data['mode']           =  $mode='LIVE';
            $data['feexpayclass']   =  $feexpayclass = new FeexpayClass($id, $token, $callback_url, $mode);
            $data['result']         =  $result = $feexpayclass->init($price, "button_payee");

            return view('welcome', $data);
    }
}
   

   composer 

   composer update feexpay/feexpay-php
   

   git clone https://github.com/La-Vedette-Media/feexpay-php-sdk.git
   

   composer