承接 craft-unit/craft-stripe-express-checkout 相关项目开发

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

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

craft-unit/craft-stripe-express-checkout

Composer 安装命令:

composer require craft-unit/craft-stripe-express-checkout

包简介

Adding the Stripe Express Checkout to Commerce-Stripe.

README 文档

README

Adding the Stripe Express Checkout Element to Commerce-Stripe.

Table of Contents

Features

  • Adds the Stripe Express Checkout Element to your Craft Commerce site.
  • Checkout products and carts with a single click.
  • Supports Apple Pay, Google Pay, PayPal and much more.
  • Supports shipping address and phone number requirements.
  • Supports all the options from the Stripe Express Checkout Element.
  • Intercept request through event hooks.
  • Automatically adjusts costs based on configured shipping rules.
  • Restrict deliveries to allowed countries in your Commerce settings.

Showcase

TODO: Add gif/webm of the express checkout; Maybe a YouTube Video showcasing the plugin would be neat

Requirements

Installation

You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store

e Go to the Plugin Store in your project’s Control Panel and search for “Stripe Express Checkout”. Then press “Install”.

With Composer

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/my-project.test

# tell Composer to load the plugin
composer require craft-unit/craft-stripe-express-checkout

# tell Craft to install the plugin
./craft plugin/install stripe-express-checkout

Setup

  1. Create a Stripe Account or use an existing one.
  2. Install Craft Commerce and the Stripe Gateway Plugin.
  3. Follow the setup instruction for the Stripe Gateway Plugin.
  4. Go to the plugin settings in the sidebar and select the gateway you just created.
  5. Render the buttons on your products and cart page.
  6. Be sure to handle the order complete event. You can use the fetch API to ask for the order and return it to the success page. See the Order complete section for more information.

Products page

products/_product.twig

{{ craft.expressCheckout.buttons({
    itemsId: product.defaultVariant.id
}) | raw }}

{# or... #}

{{ craft.expressCheckout.buttons({
    items: [{
      id: product.defaultVariant.id,
      qty: 1,
    }],
}) | raw }}

Product Page

Cart page

cart.twig

{{ craft.expressCheckout.buttons({ 
  cart: craft.commerce.carts.cart,
 }) | raw }}

Cart Page

Order complete

After the order is completed, the user will be redirected to the success_url you set in the options. At this point in time your order might not be completed in Craft Commerce hence why you won't see the completed order. You can use fetch to ask for the order and return it to the success page. Use the number query parameter to get the order number.

// Get the order number from the query parameter
const orderNumber = new URLSearchParams(window.location.search).get('number');
const order = await fetch(`/actions/commerce/stripe-express-checkout/get-order?number=${orderNumber}`);

Configuration

Configuration can be done globally in the plugin settings or locally by passing settings to the craft.expressCheckout.buttons function. Passing the settings to the function will override the global settings. You can find all the options in the Stripe documentation.

Setting Name Description
items List of item object with and id and qty.
itemId ID of the variant to sell.
gatewayId Select the gateway through which payments will be processed.
shippingAddressRequired Checking this will prompt the user for their shipping address.
phoneNumberRequired Checking this box will prompt the user for their phone number.
restrictCountries Checking this will restrict the Stripe 'allowedCountries' to your country list in Commerce -> Store Settings -> Store -> Country List.
successUrl The URL that Stripe redirects to after a successful transaction. The 'successUrl' gets a query parameter called 'number' that contains the order number.
loaderTemplate The path to the loader template.
buttonHeight The height of the buttons.
applePayTheme The theme of the Apple Pay button.
googlePayTheme The theme of the GooglePay button.
paypalTheme The theme of the PayPal button.
applePayType The type of the Apple Pay button.
googlePayType The type of the GooglePay button.
paypalType The type of the PayPal button.
maxColumns The maximum number of columns.
maxRows The maximum number of rows.
overflow Choose how the overflow should be handled.
paymentMethodOrder The order of the payment methods.
showApplePay Show the Apple Pay button.
showGooglePay Show the GooglePay button.
phoneField Map the phone number to plain text on the order field layout. This will only take effect if you enable 'Phone Number Required'.

Global Settings

Stripe Express Checkout Settings Page

Local settings

{% set settings  = {
    name: product.slug ~ '-express-checkout',
    shippingAddressRequired: true,
    phoneNumberRequired: false,
    paymentMethodOrder: ['paypal', 'googlePay', 'link'],
    buttonTheme: {
      paypal: 'blue',
    },
    buttonHeight: 55,
    buttonType: {
      paypal: 'pay',
      googlePay: 'order',
    },
    wallets: {
      applePay: 'always',
      googlePay: 'always',
    }
    {# and more... #}
} %}

Extending and Customizing

Event Hooks

Class Event
Variable EVENT_MODIFY_BUTTON_OPTIONS
StripeController EVENT_BEFORE_UPDATE_SHIPPING_RATE
StripeController EVENT_AFTER_UPDATE_SHIPPING_RATE
StripeController EVENT_UPDATE_SHIPPING_ADDRESS_ORDER_BEFORE_SAVE
StripeController EVENT_UPDATE_SHIPPING_ADDRESS_ORDER_AFTER_SAVE
ProcessStripeWebhook EVENT_MODIFY_ORDER_DETAILS
ProcessStripeWebhook EVENT_BEFORE_SAVE_SHIPPING_ADDRESS
ProcessStripeWebhook EVENT_AFTER_SAVE_SHIPPING_ADDRESS
ProcessStripeWebhook EVENT_BEFORE_SAVE_BILLING_ADDRESS
ProcessStripeWebhook EVENT_AFTER_SAVE_BILLING_ADDRESS
ProcessStripeWebhook EVENT_BEFORE_SET_ORDER_CUSTOMER
ProcessStripeWebhook EVENT_WEBHOOK_FAILED
ProcessStripeWebhook EVENT_RECEIVED_WEBHOOK
ProcessStripeWebhook EVENT_BEFORE_UPDATE_ORDER_WITH_ORDER_DETAILS

Variable::EVENT_MODIFY_BUTTON_OPTIONS

Fired right before the buttons are rendered. Modify $event->options to override the options passed to the client side StripeExpressCheckout.init() call. Setting paymentMethodConfiguration lets you control which payment methods the Express Checkout Element displays (e.g. a different set than the regular onsite checkout):

use craftunit\craftstripeexpresscheckout\events\ModifyButtonOptionsEvent;
use craftunit\craftstripeexpresscheckout\web\Variable;
use craft\helpers\App;
use yii\base\Event;

Event::on(
    Variable::class,
    Variable::EVENT_MODIFY_BUTTON_OPTIONS,
    function (ModifyButtonOptionsEvent $event) {
        if ($pmc = App::env('STRIPE_EXPRESS_PMC')) {
            $event->options['paymentMethodConfiguration'] = $pmc;
        }
    }
);

Frontend JS

Each button uses the StripeExpressCheckout class. This class is responsible for creating the Stripe Element and handling the payment intent. The instance gets added to the window.stripeExpressCheckouts object. You can give your express checkout buttons a custom name by passing the name option to the craft.expressCheckout.buttons function. You can then access the instance by calling window.stripeExpressCheckouts['your-custom-name'] or StripeExpressCheckout.getByName('your-custom-name').

Take a look at the StripeExpressCheckout class to see all the available events and methods.

Events

Event Description
stripe-express-checkout:init Called after instance was created and added to window object
stripe-express-checkout:success Called after successful onConfirm
stripe-express-checkout:error Called after failure in onConfirm

All Events get dispatched on the window object. You can listen to them by adding an event listener to the window object.

window.addEventListener('stripe-express-checkout:init', event => {
  const {name, instance} = event.detail;
  console.log(name, instance);
});

Public Methods

Method Name Parameters Description
setItemQty qty: number, id?: number Set the quantity of an item. If id is omitted, the first item is used.

Example

Below is a example showing how to manipulate the quantity of a product in the cart using the setItemQty method.

<div class="quantity">
  <input type="number" name="qty" value="1" min="1">
</div>

{% set params = requiredParams | merge(optionalParams) %}
{{ craft.expressCheckout.buttons({
  name: 'foo',
  items: [{
    id: variant.id,
    qty: 1,
  }]
}) | raw }}

<script>
  // Wait for the express checkout to initialize
  window.addEventListener('stripe-express-checkout:init', event => {
    // Get the instance by name
    const {name, instance} = event.detail;
    if (name !== 'product-express-checkout') return;

    const quantityInput = document.querySelector('.quantity input');
    quantityInput.addEventListener('input', event => {
      const qty = parseInt(event.target.value, 10);
      // Set the quantity of the item
      instance.setItemQty(qty, {{ variant.id }});
    });
  });
</script>

craft-unit/craft-stripe-express-checkout 适用场景与选型建议

craft-unit/craft-stripe-express-checkout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 craft-unit/craft-stripe-express-checkout 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 19
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-09-29