承接 prometee/sylius-payum-stripe-checkout-session-plugin 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prometee/sylius-payum-stripe-checkout-session-plugin

Composer 安装命令:

composer require prometee/sylius-payum-stripe-checkout-session-plugin

包简介

Payum Stripe gateways plugin for Sylius.

README 文档

README

Sylius Logo

Payum Stripe Plugin

Latest Version on Packagist Total Downloads Software License Build Status

Official Sylius Plugin

Integration of Stripe with Sylius as a Payum gateway.

This plugin exposes two gateway flavors: Stripe Checkout Session (hosted checkout, with SCA support) and Stripe JS (Payment Intents with Stripe Elements), supporting one-time payments, authorized payments by placing a hold on a card, and refunds.

⚠️ This plugin targets Sylius 1.x. If you are looking for a Stripe integration for Sylius 2.x, please use the official Sylius/StripePlugin instead.

Features

It supports one time payment and authorized payment by placing a hold on a card.

Refund is also possible but disabled by default to avoid mistakes, use this config to enable it :

# config/packages/flux_se_sylius_payum_stripe.yaml

flux_se_sylius_payum_stripe:
    refund_disabled: false

See https://stripe.com/docs/payments/checkout for more information.

Installation

Install using Composer :

composer remove --dev stripe/stripe-php
composer require flux-se/sylius-payum-stripe-plugin

💡 If the flex recipe has not been applied then follow the next step.

Enable this plugin:

<?php

# config/bundles.php

return [
    // ...
    FluxSE\SyliusPayumStripePlugin\FluxSESyliusPayumStripePlugin::class => ['all' => true],    
    FluxSE\PayumStripeBundle\FluxSEPayumStripeBundle::class => ['all' => true],
    // ...
];

Create the file config/packages/flux_se_sylius_payum_stripe.yaml and add the following content

imports:
  - { resource: "@FluxSESyliusPayumStripePlugin/Resources/config/config.yaml" }

Configuration

Sylius configuration

Go to the admin area, log in, then click on the left menu item "CONFIGURATION > Payment methods". Create a new payment method type "Stripe Checkout Session (with SCA support)" :

Create a new payment method

Then a form will be displayed, fill-in the required fields :

1. the "code" field (ex: "stripe_checkout_session_with_sca").

💡 The code will be the gateway name, it will be needed to build the right webhook URL later (see Webhook key section for more info).

2. choose which channels this payment method will be affected to.

3. the gateway configuration (need info from here) :

Gateway Configuration

📖 NOTE1: You can add as many webhook secret keys as you need here, however generic usage need only one.

📖 NOTE2: the screenshot contains false test credentials.

4. give to this payment method a display name (and a description) for each language you need.

Finally, click on the "Create" button to save your new payment method.

API keys

We recommend installing the Sylius Stripe App - its Settings Page exposes both keys this plugin needs:

  • the publishable key (pk_test_… / pk_live_…) for the "Publishable key" field,
  • a Restricted API Key (rk_test_… / rk_live_…) for the "Restricted API key (recommended) or secret key" field.

The App ships with the minimum scopes the plugin needs, and the Restricted API Key will be the only supported option for the secret_key field in the next minor release (see UPGRADE.md).

Alternatively, you can pick both keys directly from the Stripe Dashboard:

https://dashboard.stripe.com/test/apikeys

In that case, paste a standard secret key (sk_test_… / sk_live_…) into the "Restricted API key (recommended) or secret key" field. Note that standard secret keys in this field are deprecated and will be removed in the next minor release.

Restricted API keys are Stripe's officially recommended replacement for standard secret keys, see Stripe's documentation on restricted API keys for the full rationale.

Webhook key

Got to :

https://dashboard.stripe.com/test/webhooks

Then create a new endpoint with those events:

Gateway stripe_checkout_session stripe_js
Webhook events - checkout.session.completed
- checkout.session.async_payment_failed
- checkout.session.async_payment_succeeded
- setup_intent.canceled (⚠️ Only when using setup mode)
- setup_intent.succeeded (⚠️ Only when using setup mode)
- payment_intent.canceled
- payment_intent.succeeded
- setup_intent.canceled (⚠️ Only when using setup mode)
- setup_intent.succeeded (⚠️ Only when using setup mode)

The URL to fill is the route named payum_notify_do_unsafe with the gateway param equal to the gateway name (Payment method code), here is an example :

https://localhost/payment/notify/unsafe/stripe_checkout_session_with_sca

📖 As you can see in this example the URL is dedicated to localhost, you will need to provide to Stripe a public host name in order to get the webhooks working.

📖 Use this command to know the exact structure of payum_notify_do_unsafe route

bin/console debug:router payum_notify_do_unsafe

📖 Use this command to know the exact name of your gateway, or just check the code of the payment method in the Sylius admin payment method index.

bin/console debug:payum:gateway

Test or dev environment

Webhooks are triggered by Stripe on their server to your server. If the server is into a private network, Stripe won't be allowed to reach your server.

Stripe provide an alternate way to catch those webhook events, you can use Stripe cli : https://stripe.com/docs/stripe-cli Follow the link and install Stripe cli, then use those command line to get your webhook key :

First login to your Stripe account (needed every 90 days) :

stripe login

Then start to listen for the Stripe events (minimal ones are used here), forwarding request to your local server :

  1. Example with stripe_checkout_session_with_sca as gateway name:
    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. Example with stripe_js_with_sca as gateway name:
    stripe listen \
       --events payment_intent.canceled,payment_intent.succeeded \
       --forward-to https://localhost/payment/notify/unsafe/stripe_js_with_sca

💡 Replace the --forward-to argument value with the right one you need.

When the command finishes a webhook secret key is displayed, copy it to your Payment method in the Sylius admin.

⚠️ Using the command stripe trigger checkout.session.completed will always result in a 500 error, because the test object will not embed any usable metadata.

More?

See documentation here.

API (Sylius API Platform)

Stripe JS gateway

The endpoint : GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration will make a Payum Capture or an Authorize and respond with the Stripe Payment Intent client secret, like this :

{
 'publishable_key':  'pk_test_1234567890',
 'use_authorize': false,
 'stripe_payment_intent_client_secret': 'a_secret'
}

After calling this endpoint your will be able to use Stripe Elements to display a Stripe Payment form, the same as this template is doing it: https://github.com/FLUX-SE/PayumStripe/blob/master/src/Resources/views/Action/stripeJsPaymentIntent.html.twig. More information here : https://docs.stripe.com/payments/payment-element

Stripe Checkout Session gateway

The endpoint : GET /api/v2/shop/orders/{tokenValue}/payments/{paymentId}/configuration will make a Payum Capture or an Authorize and respond with the Stripe Checkout Session url, like this :

{
 'publishable_key':  'pk_test_1234567890',
 'use_authorize': false,
 'stripe_checkout_session_url': 'https://checkout.stripe.com/c/pay/cs_test...'
}

Since this endpoint is not able to get any data from you, a service can be decorated to specify the Stripe Checkout Session success_url you need. Decorate this service : flux_se.sylius_payum_stripe.api.payum.after_url.stripe_checkout_session to generate your own dedicated url. You will have access to the Sylius Payment to decide what is the url/route and the parameters of it.

Security issues

If you think that you have found a security issue, please do not use the issue tracker and do not post it publicly. Instead, all security issues must be sent to security@sylius.com

Community

For online communication, we invite you to chat with us and other users on Sylius Slack.

Authors

This plugin was originally created by:

Harman Professional, Inc.    Flux:: Sound and Picture Development

Kudos to Prometee and all contributors 🙏

License

This plugin is released under the MIT License.

prometee/sylius-payum-stripe-checkout-session-plugin 适用场景与选型建议

prometee/sylius-payum-stripe-checkout-session-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.04k 次下载、GitHub Stars 达 61, 最近一次更新时间为 2020 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「checkout」 「gateway」 「session」 「stripe」 「sylius」 「payum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 prometee/sylius-payum-stripe-checkout-session-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 prometee/sylius-payum-stripe-checkout-session-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 prometee/sylius-payum-stripe-checkout-session-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 61
  • 点击次数: 24
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 61
  • Watchers: 4
  • Forks: 27
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-27