ether/web-payments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ether/web-payments

Composer 安装命令:

composer require ether/web-payments

包简介

Use the Web Payments API and Google / Apply Pay to vastly improve your checkout process!

README 文档

README

Web Payments

Web Payments for Craft Commerce

Use the Web Payments API and Apply & Google Pay to vastly improve your checkout process!

Usage

Setup

After installing the plugin:

  1. Create a Stripe payment gateway.
  2. Select the gateway in the plugin options.
  3. Register your domain with Stripe and Apple Pay (Simply add your domain here).
  4. Output the button where ever you want using the template tag below.
  5. ???
  6. Profit.

{{ craft.webPayments.button(options) }}

Place this twig where you want the payments button to appear.

Options

Pass a twig object as the only parameter to configure the button.

items

An array of items to buy. Use this OR cart.

items[x].id

The ID of the purchasable.

items[x].qty

The Qty being purchased.

cart

A Craft Commerce Order (i.e. the current cart). Use this OR items.

requestShipping

A boolean or string. If true a shipping address will be required. Can also be set to one of: 'shipping', 'delivery', 'pickup', true, false (default). This will also change how the UI refers to the shipping of the products. For example, in English speaking countries you would say "pizza delivery" not "pizza shipping". Setting this to true will default the working to "shipping".

requestDetails

An array of additional details to request. Any of: name, email (email is always collected, so you don't need to add it), phone.

onComplete

An object of events to trigger once the payment is complete.

onComplete.redirect

A URL to redirect to once the payment is completed. Can include {number}, which will output the order number.

onComplete.js

JavaScript that will be executed once the payment is complete. Has access to the cwp object. Currently this only has cwp.number (the order number).

js

The variable the button will be set to in JS. Useful if you want to dynamically update the items in the virtual cart.

style

Customize the appearance of the button:

{
    type: 'default' | 'donate' | 'buy', // default: 'default'
    theme: 'dark' | 'light' | 'light-outline', // default: 'dark'
    height: '64px', // default: '40px', the width is always '100%'
}

Example

{{ craft.webPayments.button({
    items: [
        { 
            id: product.defaultVariant.id, 
            qty: 1,
            options: {
                giftWrapped: 'yes',
            },
         },
    ],
    requestShipping: 'delivery',
    js: 'window.pay_item_' ~ product.id,
}) }}
{{ craft.webPayments.button({
    cart: craft.commerce.carts.cart,
    requestDetails: ['name', 'phone'],
    onComplete: {
        redirect: '/thanks?number={number}',
        js: 'window.paymentCompleted(cwp.number);',
    },
}) }}

Dynamic Updating

You can dynamically update the button via JS.

Use the js option to define the variable you want the button to be bound to:

{{ craft.webPayments.button({
    items: [{ id: 1, qty: 1 }],
    js: 'window.payButton',
}) }}

You can then get the current items and update them:

const items = [ ...window.payButton.items ];
items[0].options = { giftWrapped: 'yes' };
window.payButton.items = items;

You can't update the items directly (i.e. window.payButton.items[0].id = 2). The items are immutable, and therefore must be set to a new array if you want to update them. Above we are cloning the existing items into a new array before modifying them.

If you passed in a cart you can simply call refresh() to update the button with the latest contents of the cart.

window.payButton.refresh();

Note that you can't update the button while the payment dialog is active.

If you need to reload the button (i.e. if the DOM has changed) you can use the reload() function.

window.payButton = window.payButton.reload();

reload() will return a new instance of the button, so you'll want to replace your existing variable with that new instance.

TODO

  • When using a cart, actually use the cart to keep fields / options persistent
    • Remove cart option (if items isn't set, use active cart)
    • Remove clear cart option
  • Support line item options when using items
  • On payment complete event (i.e. clear active cart, redirect to thanks)
  • JS hooks to update items (if not using commerce cart)
  • JS hook to refresh cart data (if using commerce cart)
  • Option to use default Apple / Google Pay buttons (rather that Stripe's button)
  • Use billing address from Stripe (don't set billing address to shipping)
  • Make shipping address optional
  • Settings:
    • Select Stripe gateway
    • Button config defaults
    • Map request details (name, phone) to order fields
  • Write setup instructions
  • Browser test JS
  • Test with Commerce Lite
  • Add flag to order marking this as an order completed via web payments
  • Add subscription support

ether/web-payments 适用场景与选型建议

ether/web-payments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.85k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2019 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ether/web-payments 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2019-04-18