dominservice/laravel-stripe 问题修复 & 功能扩展

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

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

dominservice/laravel-stripe

最新稳定版本:1.5.1

Composer 安装命令:

composer require dominservice/laravel-stripe

包简介

Laravel integration for Stripe.

README 文档

README

Packagist Latest Version Total Downloads Software License

Stripe integration for laravel 10+ on PHP 8.1+

Installation

composer require dominservice/laravel-stripe

Add your stripe credentials in .env:

STRIPE_KEY=pk_live_XxxXXxXXX
STRIPE_SECRET=sk_live_XxxXXxXXX
STRIPE_WEBHOOK_CHECKOUT=whsec_XxxXXxXXX

Publish config:

php artisan vendor:publish --tag=stripe

Publish migrations:

php artisan vendor:publish --tag=stripe-migrations

Configuration

In the configuration file you can change the list of allowed currencies. Check if your currency is on this list, and if it is not there, add it, otherwise you will not be able to use this package.

Also check if your User model is the same as the model specified in the config/stripe.php file

Usage

Routing

You must attach middleware stripe.verify:{name} to routes that have a reference to payments webhook so that the paths are secured.

Route::group(['middleware' => ['stripe.verify:checkout'], 'namespace' => '\App\Http\Controllers'], function () {
    Route::get('/webhook/payments', 'WebhookController@payments');
    
    (...)

{name} indicates which webhook key should be used. In the above example, it is checkout.

This means that config("stripe.webhooks.signing_secrets.checkout") will be used to verify webhook.

For direct Checkout Session line_items.price_data payloads, the package also accepts uppercase currency codes declared in config/stripe.php and normalizes them to Stripe's expected lowercase format before the request is sent.

Stripe Connect

The package supports the base repositories required for Stripe Connect onboarding:

  • accounts()
  • accountLinks()
  • loginLinks()

Typical platform flow:

use Dominservice\LaraStripe\Client as StripeClient;

$stripe = new StripeClient();

$account = $stripe->accounts()
    ->setType('express')
    ->setCountry('PL')
    ->setEmail($expert->email)
    ->setCapabilities([
        'transfers' => ['requested' => true],
    ])
    ->create($expert);

$onboarding = $stripe->accountLinks()
    ->setAccount($account->id)
    ->setRefreshUrl(route('expert.billing.refresh'))
    ->setReturnUrl(route('expert.billing.return'))
    ->setType('account_onboarding')
    ->create();

$loginLink = $stripe->loginLinks()->create($account->id);

For marketplace split payments handled on the platform account, create Checkout Sessions with:

  • payment_intent_data.application_fee_amount
  • payment_intent_data.transfer_data.destination

This allows the platform to collect its fee and transfer the remaining amount to the connected expert account.

Code

use Dominservice\LaraStripe\Client as StripeClient;

(...)

$stripe = (new StripeClient());

// Create product with price
$product = \App\Models\Product::find(1);
$productStripe = $stripe->products()
    ->setName($product->name)
    ->setActive(true)
    ->setExtendPricesCurrency('pln')
    ->setExtendPricesUnitAmount((float)$amount)
    ->setExtendPricesBillingScheme('per_unit')
    ->setExtendPricesRecurring(['interval' => 'month'])
    ->create($product);

// Create customer
$customer = $stripe->customers()
    ->setName($user->name)
    ->setEmail($user->email)
    ->setPhone($user->phone)
    ->setAddress([
        'country' => 'PL',
        'city' => 'Warszawa',
        'postal_code' => '00-000',
        'line1' => 'ul. kopernika 1/2',
    ])
    ->create($user);

// Checkout session
$session = $stripe->checkoutSessions()
    ->setSuccessUrl(route('payment.afterTransaction', $order->ulid) . '?session_id={CHECKOUT_SESSION_ID}')
    ->setCancelUrl(route('payment.canceled', $order->ulid))
    ->setMode('subscription')
    ->setClientReferenceId($order->ulid)
    ->setCustomer($customer->id)
    ->setLineItems([
        [
            'price' => $productStripe->default_price->id,
            'quantity' => 1,
        ]
     ])
     ->create();

To be continued... ;)

This repo is not finished

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固