ahmedebead / cakephp-4-paymob
CakePHP 的 Paymob 插件
0.1
2021-07-24 14:45 UTC
Requires
- php: >=7.2
- cakephp/cakephp: ~4.2.0
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.3
README
paymob
paymob 支付网关 https://paymob.com
安装
composer require ahmedebead/cakephp-4-paymob
在 CakePHP 中的使用
启用插件
// src/Application.php public function bootstrap() { $this->addPlugin('CakephpLte', ['autoload' => true, 'bootstrap' => true, 'routes' => true]); }
或者,您可以使用 shell 命令来加载插件
$ bin/cake plugin load CakeRestApi
配置
// new config/cakephplte.php file return [ 'CakephpPaymob' => [ 'apiKey' => '{your-api-key-here-from-your-account}', 'card_integration_id' => 'card_integration_id', //https://accept.paymob.com/portal2/en/PaymentIntegrations 'mobile_wallet_integration_id' => 'mobile_wallet_integration_id', //https://accept.paymob.com/portal2/en/PaymentIntegrations ] ]; // config/bootstrap.php Configure::load('cakephppaymob', 'default');
使用方法
步骤 1
use CakephpPaymob\CakephpPaymob;
步骤 2
初始化新客户端
$client = new CakephpPaymob();
步骤 3
订单注册
$orderData = [ "delivery_needed" => "false", // Required -- Set it to be true if your order needs to be delivered by Accept's product delivery services. "amount_cents" => 100, // price * 100 Required "currency" => "EGP", // Required "merchant_order_id" => 5, "items" => [// Required [ "name" => "ASC1515", "amount_cents" => "500000", "description" => "Smart Watch", "quantity" => "1" ], [ "name" => "ERT6565", "amount_cents" => "200000", "description" => "Power Bank", "quantity" => "1" ] ], ]; $order = $client->OrderRegistrationAPI($orderData);
卡支付
use CakephpPaymob\PaymentTypes\Card; $card = new Card(); $PaymentKey = $card->PaymentKeyRequest([ 'amount_cents' => 150 * 100, //put your price 'currency' => 'EGP', 'order_id' => $order['id'],// From step 3 before "billing_data" => [ // put your client information "apartment" => "803", "email" => "claudette09@exa.com", "floor" => "42", "first_name" => "Clifford", "street" => "Ethan Land", "building" => "8028", "phone_number" => "+86(8)9135210487", "shipping_method" => "PKG", "postal_code" => "01898", "city" => "Jaskolskiburgh", "country" => "CR", "last_name" => "Nicolas", "state" => "Utah" ] ]); $this->set('PaymentKey',$PaymentKey);
最后创建视图并像这样使用您的 iframe(卡支付)
卡信息测试
卡号:4987654321098769
持卡人姓名:测试账户
有效期月份:05
有效期年份:21
CVV:123
<iframe width="100%" height="800" src="https://accept.paymob.com/api/acceptance/iframes/{{your_frame_id_here}}?payment_token=<?= $PaymentKey // from steps ?>"> <!-- https://accept.paymob.com/portal2/en/iframes -->