prometee / sylius-payum-stripe-checkout-session-plugin
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 Session。它支持 一次性支付 和通过 暂扣卡片 进行授权支付。
退款也是可能的,但默认情况下是禁用的,以避免错误。使用此配置来启用它。
# 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 Session”。
然后会显示一个表单,填写所需的字段。
1. “code”字段(例如:“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 命令行工具
: https://stripe.com/docs/stripe-cli 点击链接并安装 Stripe 命令行工具
,然后使用这些命令行来获取您的 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 平台)
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 会话网关
端点:GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration
将执行 Payum 的 Capture
或 Authorize
并返回 Stripe Checkout 会话 URL,如下所示
{ 'publishable_key': 'pk_test_1234567890', 'use_authorize': false, 'stripe_checkout_session_url': 'https://checkout.stripe.com/c/pay/cs_test...' }
由于此端点无法从您那里获取任何数据,可以将服务装饰以指定您需要的 Stripe Checkout 会话 success_url
。装饰此服务: flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session
以生成您自己的专用 URL。您将能够访问 Sylius 的 Payment
来决定 URL/路由及其参数。