flux-se/sylius-payum-stripe-plugin

Sylius的Payum Stripe网关插件。

安装次数: 209,950

依赖关系: 0

建议者: 0

安全: 0

星星: 53

关注者: 6

分支: 23

开放问题: 6

类型:sylius-plugin


README

Latest Version on Packagist Software License Build Status

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会话”

Create a new payment method

然后会显示一个表单,填写所需字段

1. “代码”字段(例如:“stripe_checkout_session_with_sca”)。

💡 代码将是 网关名称,在稍后构建正确的webhook URL时需要它(有关更多信息,请参阅Webhook密钥部分)。

2. 选择此支付方式将影响的哪些渠道。

3. 网关配置(需要从这里获取信息

Gateway Configuration

Gateway Configuration

📖 备注1:您可以根据需要添加任意数量的webhook密钥,但通用用法只需一个。

📖 备注2:截图包含虚假的测试凭据。

4. 为您需要的每种语言提供此支付方式的显示名称(以及描述)。

最后,点击“创建”按钮以保存您的新支付方式。

API密钥

在您的Stripe仪表板中获取您的publishable_keysecret_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 CLIhttps://stripe.com/docs/stripe-cli 点击链接并安装Stripe CLI,然后使用以下命令行获取您的webhook密钥

首先登录到您的Stripe账户(每90天需要一次)

stripe login

然后开始监听Stripe事件(这里使用的是最小的事件集),将请求转发到您的本地服务器

  1. 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
  2. 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的CaptureAuthorize,并返回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的CaptureAuthorize,并返回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/路由及其参数。