allset / przelewy24-bundle
这是 Symfony 3.3+ P24 Bundle。
Requires
- php: ^5.5.9 || ^7.0
- guzzlehttp/guzzle: ^6.3
This package is not auto-updated.
Last update: 2023-04-12 03:24:04 UTC
README
这是一个使用内置 Symfony 事件的 非常容易使用 的 Przelewy24 Bundle。
安装
composer require allset/przelewy24-bundle
然后更新你的 AppKernel.php
// ... class AppKernel extends Kernel // ... public function registerBundles() { $bundles = [ // ... new Allset\Przelewy24Bundle\AllsetPrzelewy24Bundle(), // ... ]; }
然后将以下内容添加到你的 routing.yml
文件中
#app/config/routing.yml allset_przelewy24: resource: "@AllsetPrzelewy24Bundle/Resources/config/routing.xml"
如果你想要访问测试工具,请将以下内容添加到 routing_dev.yml
#app/config/routing_dev.yml allset_przelewy24: resource: "@AllsetPrzelewy24Bundle/Resources/config/routing_dev.xml"
要求
Symfony 3.3++ (因为包使用 Symfony 服务自动装配)
Guzzle ^6.3 (已包含在 composer.json 中)
配置
将以下行添加到你的配置文件中
#app/config/config.yml allset_przelewy24: sandbox: true #or false merchant_id: <your-merchant-id> crc_key: <your-crc>
用法
1. 创建你的超级自定义操作
在你的控制器中。
// ... use Allset\Przelewy24Bundle\Factory\ProcessFactory; use Allset\Przelewy24Bundle\Model\Payment; // ... class AppController extends Controller { // ... public function processAction(ProcessFactory $processFactory) { $order = // ... - You are creating your order here $payment = new Payment(); $payment ->setCurrency('PLN') ->setSessionId($order->geToken()) //VERY IMPORTANT some unique id from your order in your db ->setAmount($order->getAmount()) ->setDescription($order->getDesc()) ->setEmail($order->getEmail()) ->setReturnUrl($this->generateUrl('return', [], 0)); // use following syntax to genreate absolute url $processFactory->setPayment($payment); $url = $processFactory->createAndGetUrl(); return $this->redirect($url); } // ... }
2. 注册支付成功事件监听器
#app/config/services.yml AppBundle\EventListener\Przelewy24\PaymentSuccessListener: tags: - { name: kernel.event_listener, event: przelewy24.event.payment_success }
3. 用你的成功支付做你想要的事情
namespace AppBundle\EventListener\Przelewy24; use Allset\Przelewy24Bundle\Event\PaymentEventInterfce; class PaymentSuccessListener { // .. public function onPrzelewy24EventPaymentSuccess(PaymentEventInterfce $event) { $token = $event->getPayment()->getSessionId(); // .. } }
开发者工具
测试连接
要访问测试,你必须将 @AllsetPrzelewy24Bundle/Resources/config/routing_dev.xml
添加到你的 rounting_dev.yml
文件中。(查看安装章节)
之后,你可以访问 allset_przelewy24_test
路由,或者更简单的方法是访问 /p24-test
路径,查看结果。
模拟支付成功
由于 Przelewy24 本地 API,你无法在本地主机上获取成功响应,但你可以使用模拟支付成功工具来模拟。
要访问模拟,你必须将 @AllsetPrzelewy24Bundle/Resources/config/routing_dev.xml
添加到你的 rounting_dev.yml
文件中。(查看安装章节)
之后,你可以简单地访问 /p24-fake-success/{sessionId}
路径,或者重定向到路由 allset_przelewy24_fake_success
,以触发 przelewy24.event.payment_success
事件。