jclee100/lunar-stripe 问题修复 & 功能扩展

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

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

jclee100/lunar-stripe

Composer 安装命令:

composer create-project jclee100/lunar-stripe

包简介

Stripe payment driver for Lunar.

README 文档

README

This addon enables Stripe payments on your Lunar storefront.

Alpha Release

This addon is currently in Alpha, whilst every step is taken to ensure this is working as intended, it will not be considered out of Alpha until more tests have been added and proved.

Tests required:

  • Successful charge response from Stripe.
  • Unsuccessful charge response from Stripe.
  • Test manual config reacts appropriately.
  • Test automatic config reacts appropriately.
  • Ensure transactions are stored correctly in the database
  • Ensure that the payment intent is not duplicated when using the same Cart
  • Ensure appropriate responses are returned based on Stripe's responses.
  • Test refunds and partial refunds create the expected transactions
  • Make sure we can manually release a payment or part payment and handle the different responses.

Requirements

  • Lunar >= 0.1
  • A Stripe account with secret and public keys
  • Laravel Livewire (if using frontend components)
  • Alpinejs (if using frontend components)

Installation

Require the composer package

composer require getcandy/stripe

Publish the configuration

This will publish the configuration under config/getcandy/stripe.php.

php artisan vendor:publish --tag=getcandy.stripe.config

Publish the views (optional)

Lunar Stripe comes with some helper components for you to use on your checkout, if you intend to edit the views they provide, you can publish them.

php artisan vendor:publish --tag=getcandy.stripe.components

Enable the driver

Set the driver in config/getcandy/payments.php

<?php

return [
    // ...
    'types' => [
        'card' => [
            // ...
            'driver' => 'stripe',
        ],
    ],
];

Add your Stripe credentials

Make sure you have the Stripe credentials set in config/services.php

'stripe' => [
    'key' => env('STRIPE_SECRET'),
    'public_key' => env('STRIPE_PK'),
],

Keys can be found in your Stripe account https://dashboard.stripe.com/apikeys

Configuration

Below is a list of the available configuration options this package uses in config/getcandy/stripe.php

Key Default Description
policy automatic Determines the policy for taking payments and whether you wish to capture the payment manually later or take payment straight away. Available options manual or automatic

Backend Usage

Creating a PaymentIntent

use \Lunar\Stripe\Facades\Stripe;

Stripe::createIntent(\Lunar\Models\Cart $cart);

This method will create a Stripe PaymentIntent from a Cart and add the resulting ID to the meta for retrieval later. If a PaymentIntent already exists for a cart this will fetch it from Stripe and return that instead to avoid duplicate PaymentIntents being created.

$cart->meta->payment_intent;

Fetch an existing PaymentIntent

use \Lunar\Stripe\Facades\Stripe;

Stripe::fetchIntent($paymentIntentId);

Both these methods will return a Stripe\PaymentIntent object.

Storefront Usage

This addon provides some useful components you can use in your Storefront, they are built using Laravel Livewire and AlpineJs so bear that in mind.

If you are using the Demo Store, this is already set up for you so you can refer to the source code to see what's happening.

Set up the scripts

Place this in the <head> of your Storefront.

@stripeScripts

Add the payment component

Wherever you want the payment form to appear, add this component:

@livewire('stripe.payment', [
  'cart' => $cart,
  'returnUrl' => route('checkout.view'),
])

The returnUrl is where we want Stripe to redirect us afer they have processed the payment on their servers.

Do NOT point this to the order confirmation page, as you'll see below

Process the result

You'll notice above we've told Stripe to redirect back to the checkout page, this is because although Stripe has either taken payment or allocated funds based on your policy, we still need Lunar to process the result and create the transactions it needs against the order.

When Stripe redirects us we should have two parameters passed in the query string. payment_intent_client_secret and payment_intent. We can then check for these values and pass them off using Lunar's Payments driver.

So, assuming we are using Livewire and on a CheckoutPage component (like on the Demo Store)

if ($request->payment_intent) {
    $payment = \Lunar\Facades\Payments::driver('card')->cart($cart)->withData([
        'payment_intent_client_secret' => $request->payment_intent_client_secret,
        'payment_intent' => $request->payment_intent,
    ])->authorize();

    if ($payment->success) {
        redirect()->route('checkout-success.view');
        return;
    }
}

And that should be it, you should then see the order in Lunar with the correct Transactions.

If you have set your policy to manual you'll need to go into the Hub and manually capture the payment.

Contributing

Contributions are welcome, if you are thinking of adding a feature, please submit an issue first so we can determine whether it should be included.

Testing

Currently we use a manual MockClient to mock the responses the Stripe API will return. This is likely to be improved upon as tests are written, but it should be apparent what this is doing, so feel free to add your own responses.

jclee100/lunar-stripe 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-02