arturwwl/przelewy24-bundle

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

安装: 65

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 0

分支: 3

类型:symfony-bundle

1.1.4 2020-02-25 07:32 UTC

This package is auto-updated.

Last update: 2024-09-25 18:16:26 UTC


README

这是一个非常容易使用的 Przelewy24 Bundle,内置了 Symfony Events。

安装

composer require arturwwl/przelewy24-bundle

然后更新你的 AppKernel.php

// ...
class AppKernel extends Kernel
// ...
    public function registerBundles()
    {
        $bundles = [
		// ...
            new Arturwwl\Przelewy24Bundle\ArturwwlPrzelewy24Bundle(),
		// ...
        ];
	}

然后将以下内容添加到你的 routing.yml 文件中

#app/config/routing.yml
arturwwl_przelewy24:
    resource: "@ArturwwlPrzelewy24Bundle/Resources/config/routing.xml"

如果你想要访问测试工具,将以下内容添加到 routing_dev.yml

#app/config/routing_dev.yml
arturwwl_przelewy24:
    resource: "@ArturwwlPrzelewy24Bundle/Resources/config/routing_dev.xml"

要求

Symfony 3.3++(因为包使用了 Symfony Service Autowire)
Guzzle ^6.3(已在 composer.json 中包含)

配置

将以下行添加到你的配置文件中

#app/config/config.yml
arturwwl_przelewy24:
    sandbox: true #or false
    merchant_id: <your-merchant-id>
    crc_key: <your-crc>

使用方法

1. 创建你的超级自定义操作

在你的控制器中。

// ...

use Arturwwl\Przelewy24Bundle\Factory\ProcessFactory;
use Arturwwl\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 Arturwwl\Przelewy24Bundle\Event\PaymentEventInterface;

class PaymentSuccessListener
{
    // ..
    
    public function onPrzelewy24EventPaymentSuccess(PaymentEventInterface $event)
    {
        $token = $event->getPayment()->getSessionId();

	// ..

    }
}

开发者工具

测试连接

要访问测试,你必须将 @ArturwwlPrzelewy24Bundle/Resources/config/routing_dev.xml 添加到你的 rounting_dev.yml 文件中。(查看安装章节)

之后,你可以访问 arturwwl_przelewy24_test 路由,或者更简单,直接访问 /p24-test 路径来查看结果。

模拟支付成功

由于 Przelewy24 的原生 API,你无法在本地主机上获取成功响应,但你可以使用模拟支付成功工具来模拟它。

要访问模拟,你必须将 @ArturwwlPrzelewy24Bundle/Resources/config/routing_dev.xml 添加到你的 rounting_dev.yml 文件中。(查看安装章节)

之后,你可以直接访问 /p24-fake-success/{sessionId} 路径或重定向到路由 arturwwl_przelewy24_fake_success 来触发包的 przelewy24.event.payment_success 事件。