origami/stripe
Composer 安装命令:
composer require origami/stripe
包简介
Stripe PaymentIntents helper package
README 文档
README
This package is a helper for Laravel projects using Stripe's PaymentIntents API and manual confirmation SCA setup.
It was inspired by the SCA updates and logic on the Laravel Cashier package.
Installation
Install this package through Composer.
composer require origami/stripe
Requirements
This package is designed to work with Laravel >= 6.0 projects currently.
Setup
- You should add a your stripe keys to your
config/services.phpfile:
'stripe' => [
'secret' => env('STRIPE_SECRET'),
'key' => env('STRIPE_KEY'),
'webhook' => [
'secret' => env('STRIPE_WEBHOOK_SECRET'),
]
],
- Update your
.envfile with the key and secret:
STRIPE_KEY=
STRIPE_SECRET=
STRIPE_WEBHOOK_SECRET=
Usage
Payment object
// Make a Payment from a payment_intent ID. $payment = Origami\Stripe\Payment::find($id); // Or create a Payment as a new payment_intent $payment = Origami\Stripe\Payment::create([ 'amount' => 1000, 'currency' => 'gbp', 'payment_method' => $method, 'capture_method' => 'manual', 'payment_method_types' => ['card'], 'confirmation_method' => 'manual', 'confirm' => true, ]));
Available Methods
Get amount
Returns amount as Money\Money object using moneyphp/money
$payment->amount();
Check status
Returns a boolean:
public function hasStatus($status)
You can pass an array or a string:
$payment->hasStatus(['requires_confirmation','requires_capture']); $payment->hasStatus('requires_confirmation');
There are also helper methods for the PaymentIntent statuses:
$payment->requiresConfirmation(); $payment->requiresPaymentMethod(); $payment->requiresCapture(); $payment->requiresAction(); $payment->isCancelled(); $payment->isSucceeded(); $payment->isSuccessful(); // Alias for above
Validate PaymentIntent
See https://stripe.com/docs/payments/payment-intents/web-manual#creating-with-manual-confirmation
try { $payment = Origami\Stripe\Payment::create([ 'amount' => 1000, 'currency' => 'gbp', 'payment_method' => $method, 'capture_method' => 'manual', 'payment_method_types' => ['card'], 'confirmation_method' => 'manual', 'confirm' => true, ])); if (!$payment) { throw new Exception('Error fetching Stripe payment'); } $payment->validate(); // PaymentIntent is valid // capture_method: manual above means we need to capture in another controller // capture_method: automatic above means the payment was successully taken return response([ 'payment_intent_id' => $payment->id, 'success' => true, ]); } catch (Origami\Stripe\PaymentActionRequired $e) { // Action is required on the client end - see Stripe docs. return response()->json([ 'requires_action' => true, 'payment_intent_client_secret' => $e->payment->clientSecret(), 'success' => false, ], 200); } catch (Origami\Stripe\PaymentFailed $e) { // Payment failed - handle on the client end. return response()->json([ 'error' => $e->getMessage(), 'success' => false, ], 500); } catch (Stripe\Exception\CardException $e) { // Don't forget to handle Stripe's exceptions for declined cards, etc. return response()->json([ 'error' => $e->getMessage(), 'success' => false, ], 500); } catch (Exception $e) { // Something else went wrong. Log::error($e); return response()->json(['error' => 'Unexpected error', 'success' => false], 500); }
Author
License
origami/stripe 适用场景与选型建议
origami/stripe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.46k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 origami/stripe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 origami/stripe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-10