flux-se / sylius-payum-stripe-plugin
Sylius的Payum Stripe网关插件。
Requires
- flux-se/payum-stripe-bundle: ^2.0
- sylius/sylius: ^1.9
Requires (Dev)
- ext-json: *
- behat/behat: ^3.7
- dbrekelmans/bdi: ^1.2
- dmore/behat-chrome-extension: ^1.4
- dmore/chrome-mink-driver: ^2.8
- friends-of-behat/mink: ^1.9
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0
- friends-of-behat/mink-extension: ^2.5
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.1
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan-doctrine: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- phpstan/phpstan-webmozart-assert: ^1.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- robertfausk/behat-panther-extension: ^1.1
- sylius-labs/coding-standard: ^4.1
- sylius-labs/suite-tags-extension: ^0.2.0
- symfony/browser-kit: ^5.4|^6.4
- symfony/debug-bundle: ^5.4|^6.4
- symfony/dotenv: ^5.4|^6.4
- symfony/http-client: ^5.4|^6.4
- symfony/intl: ^5.4|^6.4
- symfony/runtime: ^5.4|^6.4
- symfony/web-profiler-bundle: ^5.4|^6.4
- symfony/webpack-encore-bundle: ^1|^2
README
Sylius Payum Stripe网关插件
此插件旨在为Payum添加一个新的网关以支持Stripe Checkout会话。它支持一次性支付和通过对卡进行预留进行授权支付。
退款也是可能的,但默认禁用以避免错误,使用此配置来启用它
# config/packages/flux_se_sylius_payum_stripe.yaml flux_se_sylius_payum_stripe: refund_disabled: false
有关更多信息,请参阅https://stripe.com/docs/payments/checkout
安装
使用Composer安装
composer remove --dev stripe/stripe-php composer require flux-se/sylius-payum-stripe-plugin
💡 如果尚未应用flex配方,请遵循下一步。
启用此插件
<?php # config/bundles.php return [ // ... FluxSE\SyliusPayumStripePlugin\FluxSESyliusPayumStripePlugin::class => ['all' => true], FluxSE\PayumStripeBundle\FluxSEPayumStripeBundle::class => ['all' => true], // ... ];
创建文件 config/packages/flux_se_sylius_payum_stripe.yaml
并添加以下内容
imports: - { resource: "@FluxSESyliusPayumStripePlugin/Resources/config/config.yaml" }
配置
Sylius配置
转到管理区域,登录,然后点击左侧菜单项“配置 > 支付方式”。创建一个新的支付方式类型“带有SCA支持的Stripe Checkout会话”
然后会显示一个表单,填写所需字段
1. “代码”字段(例如:“stripe_checkout_session_with_sca”)。
💡 代码将是
网关名称
,在稍后构建正确的webhook URL时需要它(有关更多信息,请参阅Webhook密钥部分)。
2. 选择此支付方式将影响的哪些渠道。
3. 网关配置(需要从这里获取信息)
📖 备注1:您可以根据需要添加任意数量的webhook密钥,但通用用法只需一个。
📖 备注2:截图包含虚假的测试凭据。
4. 为您需要的每种语言提供此支付方式的显示名称(以及描述)。
最后,点击“创建”按钮以保存您的新支付方式。
API密钥
在您的Stripe仪表板中获取您的publishable_key
和secret_key
https://dashboard.stripe.com/test/apikeys
Webhook密钥
转到
https://dashboard.stripe.com/test/webhooks
然后创建一个具有这些事件的新端点
要填写的URL是命名路由 payum_notify_do_unsafe
,其中gateway
参数等于网关名称
(支付方式代码),以下是一个示例
https://localhost/payment/notify/unsafe/stripe_checkout_session_with_sca
📖 如您所见,此示例中的URL是针对
localhost
的,您需要向Stripe提供一个公共主机名,以便使webhook正常工作。
📖 使用此命令以了解
payum_notify_do_unsafe
路由的确切结构bin/console debug:router payum_notify_do_unsafe
📖 使用此命令以了解您的网关的确切名称,或只需检查Sylius管理员支付方式索引中支付方式的
code
。bin/console debug:payum:gateway
测试或开发环境
Stripe在其服务器上触发webhook,并将其发送到您的服务器。如果服务器位于私有网络中,Stripe将无法访问您的服务器。
Stripe提供了一个捕获这些webhook事件的替代方法,您可以使用Stripe CLI
: https://stripe.com/docs/stripe-cli 点击链接并安装Stripe CLI
,然后使用以下命令行获取您的webhook密钥
首先登录到您的Stripe账户(每90天需要一次)
stripe login
然后开始监听Stripe事件(这里使用的是最小的事件集),将请求转发到您的本地服务器
- 以
stripe_checkout_session_with_sca
作为网关名称的示例stripe listen \ --events checkout.session.completed,checkout.session.async_payment_failed,checkout.session.async_payment_succeeded \ --forward-to https://localhost/payment/notify/unsafe/stripe_checkout_session_with_sca
- 以
stripe_js_with_sca
作为网关名称的示例stripe listen \ --events payment_intent.canceled,payment_intent.succeeded \ --forward-to https://localhost/payment/notify/unsafe/stripe_js_with_sca
💡 将--forward-to参数值替换为您需要的正确值。
当命令执行完毕后,会显示webhook密钥,将其复制到Sylius管理后台的支付方式中。
⚠️ 使用
stripe trigger checkout.session.completed
命令将始终导致500错误
,因为测试对象将不会嵌入任何可用的元数据。
还有其他内容吗?
请在此处查看文档: https://github.com/FLUX-SE/PayumStripe/blob/master/README.md
API(Sylius Api Platform)
Stripe JS网关
端点:GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration
将执行Payum的Capture
或Authorize
,并返回Stripe支付意向客户端密钥,如下所示
{ 'publishable_key': 'pk_test_1234567890', 'use_authorize': false, 'stripe_payment_intent_client_secret': 'a_secret' }
调用此端点后,您将能够使用Stripe Elements显示Stripe支付表单,就像此模板所做的那样: https://github.com/FLUX-SE/PayumStripe/blob/master/src/Resources/views/Action/stripeJsPaymentIntent.html.twig。更多信息请在此处查看:https://docs.stripe.com/payments/payment-element
Stripe Checkout Session网关
端点:GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration
将执行Payum的Capture
或Authorize
,并返回Stripe Checkout Session URL,如下所示
{ 'publishable_key': 'pk_test_1234567890', 'use_authorize': false, 'stripe_checkout_session_url': 'https://checkout.stripe.com/c/pay/cs_test...' }
由于此端点无法从您那里获取任何数据,可以将一个服务装饰起来以指定所需的Stripe Checkout Session success_url
。装饰此服务:flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session
以生成您自己的专用URL。您将能够访问Sylius的Payment
以决定URL/路由及其参数。