定制 remp/crm-stripe-module 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

remp/crm-stripe-module

Composer 安装命令:

composer require remp/crm-stripe-module

包简介

CRM Stripe Module

README 文档

README

Installation

We recommend using Composer for installation and update management. To add CRM Stripe extension to your REMP CRM application use following command:

composer require remp/crm-stripe-module

Enable installed extension in your app/config/config.neon file:

extensions:
	# ...
	- Crm\StripeModule\DI\StripeModuleExtension

Seed Stripe payment gateway and its configuration:

php bin/command.php application:seed

Configuration & API keys

Enter Stripe API keys to CRM

  • Visit to CRM admin settings (gear icon) - Payments
  • Enter Stripe publishable key
  • Enter Stripe secret key

Keys can be found at Stripe Dashboard. If you don't have the account already, you'll need to create one.

Using module

Stripe Checkout

Stripe Checkout is the most secure and robust scenario of processing payments with Stripe. User is redirected to Stripe's checkout page where he/she enters card details and submits the payment.

We recommend using this scenario as Stripe optimizes the page for various devices. Stripe Checkout is the default flow when this module is enabled.

If you use remp2020/crm-salesfunnel-module, all you need to do is to enable both Stripe and Stripe Recurrent gateways in your sales funnels (CRM Admin - Sales funnels - Detail - Payment gateways). You can test the integration with our sample funnel, which will display the new gateways right away after you enable them.

Stripe Checkout

Stripe Elements

Stripe Elements provide a secure way how to collect card data directly in your sales funnel. To use Stripe elements, include following snippets to your sales funnel.

Include Stripe JS library.

<script src="https://js.stripe.com/v3/"></script>

Add elements that will be initialized to collect the data.

<div>
    <label>Card holder</label>
    <input id="cardholder-name" class="form-control mb-4" type="text">
    <!-- placeholder for Elements -->
    <div id="card-element" class="form-control"></div>

    <!-- Used to display form errors -->
    <div id="card-errors" role="alert"></div>

    <!-- Used to store generated payment method ID as payment metadata -->
    <input type="hidden" name="payment_metadata[payment_method_id]" id="stripePaymentMethodId">
</div>

Initialize Stripe Elements and use your Stripe publishable key instead of the placeholder we prepared.

<script type="text/javascript">
    var stripe = Stripe('-- INCLUDE YOUR PUBLISHABLE KEY HERE --');
    var elements = stripe.elements();

    var cardElement = elements.create("card");
    cardElement.mount("#card-element");
    cardElement.addEventListener('change', function(event) {
        var displayError = document.getElementById('card-errors');
        if (event.error) {
            displayError.textContent = event.error.message;
        } else {
            displayError.textContent = '';
        }
    });
</script>

Attach Stripe handlers to the form submission process.

function processStripe(form) {
    var paymentMethodIdField = $('#stripePaymentMethodId');
    var cardholderName = $('#cardholder-name');
    var selectedGateway = $('input[name=payment_gateway]').val();

    if (selectedGateway === 'stripe') {
        stripe.createPaymentMethod('card', cardElement, {
            billing_details: {name: cardholderName.value }
        }).then(function(result) {
            if (result.error) {
                alert(result.error.message);
            } else {
                paymentMethodIdField.val(result.paymentMethod.id);
                debugger;
                form.submit();
            }
        });
        return false;
    }

    if (selectedGateway === 'stripe_recurrent') {
        $.post('/api/v1/stripe/setup-intent', function($data) {
            stripe.confirmCardSetup(
                $data['client_secret'],
                {
                    payment_method: {
                        card: cardElement,
                        billing_details: {
                            name: cardholderName.value,
                        },
                    }
                },
            ).then(function(result) {
                if (result.error) {
                    alert(result.error.message);
                } else {
                    paymentMethodIdField.val(result.setupIntent.payment_method);
                    form.submit();
                }
            });
        }, 'json');
        return false;
    }
}

$(form).submit(function() {
    processStripe();
});

Stripe Module also seeded funnel example with Stripe Elements usage. You can find it in CRM Admin - Sales Funnels - stripe-elements-sample. To make it work, search for -- INCLUDE YOUR PUBLISHABLE KEY HERE -- and replace it with the Stripe publishable key available at your Stripe Dashboard.

Stripe Elements 3D secure

Wallet payments (ApplePay/GooglePay) - Stripe Payment Request Button

For using ApplePay or GooglePay you have to use StripeWallet payment gateway. Configuration in CRM is the same as with Stripe Elements, but you can setup one more config - Stripe Display Name. This text is used as name of merchant, used as label for total amount in payment window.

This payment gateway handles ApplePay and GooglePay via the exact implementation where Stripe shows the correct payment button in the end.

RECOMMENDATION: In the sales funnel, please use javascript from documentation and enable/disable this payment method based on client browser support. It doesn't make sense to show the customer ApplePay/GooglePay as a valid payment option if it is unavailable. You can use javascript from official documentation - Stripe Payment Request Button

It looks like this:

var stripe = Stripe("you-public-key", {
    apiVersion: "2020-08-27",
});

var paymentRequest = stripe.paymentRequest({
    country: "SK",
    currency: "eur",
    total: {
        label: "something",
        amount: 100, // 1 eur is OK right now
    },
});

const elements = stripe.elements();
const prButton = elements.create('paymentRequestButton', {
    paymentRequest: paymentRequest,
});

// Check the availability of the Payment Request API first.
paymentRequest.canMakePayment().then(function(result) {
    if (result) {
        if (result.applePay == true) {
            // applePay is available
            // you can unhide payment method
        } else if (result.googlePay == true) {
            // googlePay is available
            // you can unhide payment method
        }
    } else {
        // no wallet payment method is available
        // you shoud hide payment methods here, but i recommend to keep it hidden by default
    }
});

Known limitation:

  1. You have to copy your stripe public key to each sale funnel where you would like to check the support of wallet payment options.
  2. We don't support:
    • Importing shipping addresses from wallets (but it's possible).
    • Importing email of the customer from wallets (but it's possible).
    • Recurrent payments (but it looks possible).
    • Use of StripeWallet in our CRM ProductsModule (eshop).

remp/crm-stripe-module 适用场景与选型建议

remp/crm-stripe-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.95k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 remp/crm-stripe-module 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-18