PHP code example of baidouabdellah / cmi-payment-gateway
1. Go to this page and download the library: Download baidouabdellah/cmi-payment-gateway 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/ */
baidouabdellah / cmi-payment-gateway example snippets
return [
'merchant_id' => env('CMI_MERCHANT_ID'),
'client_id' => env('CMI_CLIENT_ID'),
'store_key' => env('CMI_STORE_KEY'),
'api_key' => env('CMI_API_KEY'),
'secret_key' => env('CMI_SECRET_KEY'),
'sandbox' => env('CMI_SANDBOX', true),
'base_uri' => env('CMI_BASE_URI', 'https://testpayment.cmi.co.ma/fim/est3Dgate'),
'ok_url' => env('CMI_OK_URL', 'http://localhost/cmi/ok'),
'fail_url' => env('CMI_FAIL_URL', 'http://localhost/cmi/fail'),
'shop_url' => env('CMI_SHOP_URL', 'http://localhost/checkout'),
'callback_url' => env('CMI_CALLBACK_URL', 'http://localhost/cmi/callback'),
'store_type' => env('CMI_STORE_TYPE', '3D_PAY_HOSTING'),
'tran_type' => env('CMI_TRAN_TYPE', 'PreAuth'),
'lang' => env('CMI_DEFAULT_LANG', 'fr'),
'currency' => env('CMI_DEFAULT_CURRENCY', '504'),
'hash_algorithm' => env('CMI_HASH_ALGORITHM', 'ver3'),
'encoding' => env('CMI_ENCODING', 'UTF-8'),
'auto_redirect' => env('CMI_AUTO_REDIRECT', true),
'callback_response' => env('CMI_CALLBACK_RESPONSE', true),
'session_timeout' => env('CMI_SESSION_TIMEOUT', 1800),
'transport' => env('CMI_TRANSPORT', 'hosted_form'), // hosted_form | server_api
'http_timeout' => env('CMI_HTTP_TIMEOUT', 15),
];
use Baidouabdellah\CmiPaymentGateway\CmiPayment;
class PaymentController extends Controller
{
public function makePayment(Request $request)
{
$payment = app(CmiPayment::class);
$response = $payment->pay(100.00, 'ORDER12345', 'Order payment', [
'email' => '[email protected] ',
'BillToName' => 'Customer Name',
]);
// $response['gateway_url'] => CMI endpoint
// $response['payload'] => fields to submit as POST form
// $response['hash'] => generated hash
return response()->json($response);
}
}
Route::post('/cmi/callback', [PaymentController::class, 'handleCallback'])->name('cmi.callback');
use Illuminate\Http\Request;
class PaymentController extends Controller
{
public function handleCallback(Request $request)
{
$service = app(\Baidouabdellah\CmiPaymentGateway\CmiPaymentService::class);
$isValid = $service->validateHash($request->all());
if ($isValid && $request->input('ProcReturnCode') === '00') {
return view('payment.success');
}
return view('payment.failed');
}
}
bash
php artisan vendor:publish --tag="cmi-config"