Skip to content

Commit

Permalink
Update to version 1.0.3 with support for multiple Laravel versions
Browse files Browse the repository at this point in the history
  • Loading branch information
baidou5 committed Oct 3, 2024
1 parent 474e5c8 commit 4fa3cc3
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 71 deletions.
69 changes: 61 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
{
{
"name": "baidouabdellah/cmi-payment-gateway",
"description": "CMI Payment Gateway for Laravel",
"description": "Laravel package to integrate with the CMI payment gateway",
"version": "1.0.3",
"keywords": ["laravel", "payment", "gateway", "CMI", "integration"],
"version": "1.0.2",
"type": "library",
"homepage": "https://github.com/baidouabdellah/cmi-payment-gateway",
"license": "MIT",
"authors": [
{
"name": "Abdellah Baidou",
"email": "baidou.abd@gmail.com",
"role": "Developer"
}
],
"require": {
"php": "^7.4|^8.0",
"illuminate/support": "^8.0|^9.0|^10.0"
"php": "^8.1",
"php": "^7.4|^8.0|^8.1|^8.2",
"spatie/laravel-package-tools": "^1.9.2",
"illuminate/support": "^7.4|^7.5|^8.0|^9.0|^10.0|^11.0",
"illuminate/contracts": "^7.4|^7.5|^8.0|^9.0|^10.0|^11.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0|^8.0",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0"
},
"autoload": {
"psr-4": {
"Baidouabdellah\\CMIPaymentGateway\\": "src/"
"Baidouabdellah\\CmiPaymentGateway\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Baidouabdellah\\CmiPaymentGateway\\Tests\\": "tests"
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint",
"format-v": "vendor/bin/pint -v"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"Baidouabdellah\\CmiPaymentGateway\\CmiServiceProvider"
],
"aliases": {
"Cmi": "Baidouabdellah\\CmiPaymentGateway\\Facades\\Cmi"
}
}
},
"license": "MIT"
"minimum-stability": "dev",
"prefer-stable": true
}
22 changes: 14 additions & 8 deletions config/cmi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
*
* This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
*/

phpreturn [
'merchant_id' => env('CMI_MERCHANT_ID'),
'api_key' => env('CMI_API_KEY'),
'secret_key' => env('CMI_SECRET_KEY'),
'sandbox' => env('CMI_SANDBOX', true),
'callback_url' => env('CMI_CALLBACK_URL', 'your_callback_url'),
];

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', 'your_ok_url'),
'fail_url' => env('CMI_FAIL_URL', 'your_fail_url'),
'shop_url' => env('CMI_SHOP_URL', 'your_shop_url'),
'callback_url' => env('CMI_CALLBACK_URL', 'your_callback_url'),
];
103 changes: 60 additions & 43 deletions src/CmiPaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,71 @@
*
* This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
*/
namespace baidouabdellah\CMIPaymentGateway;
namespace baidouabdellah\CMIPaymentGateway;

use GuzzleHttp\Client;
use GuzzleHttp\Client;

class CmiPaymentService
{
protected $merchantId;
protected $apiKey;
protected $secretKey;
protected $sandbox;
protected $callbackUrl;
class CmiPaymentService
{
protected $merchantId;
protected $clientId;
protected $storeKey;
protected $apiKey;
protected $secretKey;
protected $sandbox;
protected $baseUri;
protected $okUrl;
protected $failUrl;
protected $shopUrl;
protected $callbackUrl;

public function __construct()
{
$this->merchantId = config('cmi.merchant_id');
$this->apiKey = config('cmi.api_key');
$this->secretKey = config('cmi.secret_key');
$this->sandbox = config('cmi.sandbox');
$this->callbackUrl = config('cmi.callback_url');
}
public function __construct()
{
$this->merchantId = config('cmi.merchant_id');
$this->clientId = config('cmi.client_id');
$this->storeKey = config('cmi.store_key');
$this->apiKey = config('cmi.api_key');
$this->secretKey = config('cmi.secret_key');
$this->sandbox = config('cmi.sandbox');
$this->baseUri = config('cmi.base_uri');
$this->okUrl = config('cmi.ok_url');
$this->failUrl = config('cmi.fail_url');
$this->shopUrl = config('cmi.shop_url');
$this->callbackUrl = config('cmi.callback_url');
}

public function createPayment($amount, $orderId, $description)
{
$endpoint = $this->sandbox ? "https://sandbox.cmi.co.ma/api" : "https://cmi.co.ma/api";
public function createPayment($amount, $orderId, $description)
{
$endpoint = $this->sandbox ? "https://sandbox.cmi.co.ma/api" : $this->baseUri;

// Build the order for payment
$data = [
'merchant_id' => $this->merchantId,
'amount' => $amount,
'order_id' => $orderId,
'description' => $description,
'callback_url' => $this->callbackUrl,
];
// Build the order for payment
$data = [
'merchant_id' => $this->merchantId,
'client_id' => $this->clientId,
'store_key' => $this->storeKey,
'amount' => $amount,
'order_id' => $orderId,
'description' => $description,
'callback_url' => $this->callbackUrl,
'ok_url' => $this->okUrl,
'fail_url' => $this->failUrl,
'shop_url' => $this->shopUrl,
];

// Send the request using Guzzle
return $this->sendRequest($endpoint, $data);
}
// Send the request using Guzzle
return $this->sendRequest($endpoint, $data);
}

protected function sendRequest($url, $data)
{
$client = new Client();
$response = $client->post($url, [
'form_params' => $data,
'headers' => [
'Authorization' => 'Bearer ' . $this->apiKey,
],
]);
protected function sendRequest($url, $data)
{
$client = new Client();
$response = $client->post($url, [
'form_params' => $data,
'headers' => [
'Authorization' => 'Bearer ' . $this->apiKey,
],
]);

return json_decode($response->getBody(), true);
}
}
return json_decode($response->getBody(), true);
}
}
24 changes: 12 additions & 12 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
*
* This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
*/
if (!function_exists('cmi_generate_order_id')) {
function cmi_generate_order_id()
{
return 'ORD-' . strtoupper(uniqid());
}
}
if (!function_exists('cmi_generate_order_id')) {
function cmi_generate_order_id()
{
return 'ORD-' . strtoupper(uniqid());
}
}

if (!function_exists('cmi_format_amount')) {
function cmi_format_amount($amount)
{
return number_format($amount, 2, '.', '');
}
}
if (!function_exists('cmi_format_amount')) {
function cmi_format_amount($amount)
{
return number_format($amount, 2, '.', '');
}
}

0 comments on commit 4fa3cc3

Please sign in to comment.