mysho / comgate-bundle
1.0.8
2024-08-27 09:01 UTC
Requires
- php: ^7.3|^8.0|^8.1
- guzzlehttp/guzzle: 7.7.*
- symfony/framework-bundle: 6.0.*
- symfony/yaml: ^6.1
README
Comgate支付的symfony包
安装
步骤 1: 使用composer下载MyshoComgateBundle
使用composer Composer 需要 mysho/comgate-bundle
。
$ composer require mysho/comgate-bundle
步骤 2: 启用包
在kernel中启用该包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Mysho\ComgateBundle\MyshoComgateBundle(), // ... ); }
步骤 3: 配置MyshoComgateBundle
以下是使用MyshoComgateBundle
在应用程序中进行配置的必要最小示例
# .env ###> mysho/comgate-bundle ### MERCHANT_ID="your merchant id" SECRET_KEY="secret key from comgate dashboard" TEST_MODE=false ###< mysho/comgate-bundle ###
步骤 4: 使用MyshoComgateBundle
# CartController /** * @Route("/cart/payment", name="cart_payment") * @param ComgateConnector $comgate * @param Request * @return Response */ public function payment(ComgateConnector $comgate): Response { $payment = new CreatePayment('PRICE', 'Your order ID', $this->getUser()->getEmail(), 'Some product'); // to create payment on background according to API requirements $payment->setPrepareOnly(true); $response = $comgate->send($payment); if($response->getMessage()=="OK"){ // do something with cart return $this->redirect($response->getRedirectUrl()); } return $this->render('cart/payment.html.twig', []); }