pavlaq/przelewy24-bundle-fork

这是适用于 Symfony 3.3+ 的 P24 Bundle。

安装: 0

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 3

类型:symfony-bundle

v1.2.0 2021-10-07 10:34 UTC

This package is auto-updated.

Last update: 2024-09-26 01:21:22 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++(因为 Bundle 使用 Symfony Service Autowire)
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 以触发 Bundle 的 przelewy24.event.payment_success 事件。