idci/payment-bundle

Symfony支付组件

安装次数:3,172

依赖项: 0

建议者: 0

安全: 0

星级: 1

关注者: 4

分支: 1

开放问题: 0

类型:symfony-bundle

v6.0.2 2024-05-13 10:03 UTC

README

这个Symfony组件通过网关规范化支付流程,为集成支付解决方案提供帮助。每个使用的网关都必须有一个配置来设置其参数。

示例控制器

<?php

$paymentContext = $this->paymentManager->createPaymentContextByAlias('stripe_test'); // raw alias

$payment = $paymentContext->createPayment([
    'item_id' => 5,
    'amount' => 500,
    'currency_code' => 'EUR',
]);

return $this->render('@IDCIPayment/payment.html.twig', [
    'view' => $paymentContext->buildHTMLView(),
]);

此组件提供一组命令来管理网关配置和事务。

安装

在您的composer.json文件中添加依赖项

"require": {
    ...,
    "idci/payment-bundle": "^4.0",
}

使用composer在您的应用程序中安装此新依赖项

$ composer update

在您的应用程序内核中启用组件

<?php
// config/bundles.php
return [
    // ...
    new IDCI\Bundle\PaymentBundle\IDCIPaymentBundle(),
];

将以下内容添加到您的config.yml文件中

# config/packages/idci_payment.yaml
imports:
    - {resource: '@IDCIPaymentBundle/Resources/config/config.yml'}

# Enable monolog logging using event subscriber plugged on transaction state changes
idci_payment:
    enabled_logger_subscriber: true

(可选)如果您想自定义支付日志记录器,默认情况下,它将输出到主处理器

# config/packages/monolog.yaml
monolog:
    handlers:
        # ...
        payment_log:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            channels: ['payment']

在您的config/routes/idci_payment.yaml文件中安装路由

# config/routes/idci_payment.yaml
idci_payment:
    resource: '@IDCIPaymentBundle/Resources/config/routing.yml'
    prefix:   /

idci_payment_api:
    resource: '@IDCIPaymentBundle/Resources/config/routing_api.yml'
    prefix:   /api

以下教程可能有助于您自定义此组件

支持的网关

测试目的

命令

支付网关配置
# To create a PaymentGatewayConfiguration
$ php bin/console app:payment-gateway-configuration:create

# To show the list of PaymentGatewayConfiguration
$ php bin/console app:payment-gateway-configuration:list

# To update a PaymentGatewayConfiguration
$ php bin/console app:payment-gateway-configuration:update

# To delete a PaymentGatewayConfiguration
$ php bin/console app:payment-gateway-configuration:delete
交易
# Remove all the aborted transaction created 1 day ago
$ php bin/console app:transaction:clean

测试

添加测试路由

# config/routes/dev/idci_payment.yaml

_test_payment:
    resource: '@IDCIPaymentBundle/Resources/config/routing_test.yml'
    prefix:   /_test/

现在您可以在 /_test/payment-gateway/select 上测试网关(请确保已创建一个或多个网关配置)

资源

UML 图

UML Diagram