creatydev / authorize-billing
Laravel Cashier-Authorize提供了一组表达性、流畅的接口来访问Authorize.net的订阅计费服务。
Requires
- php: >= 7.2.0
- authorizenet/authorizenet: ^2.0
- dompdf/dompdf: ^0.8.2
- laravel/framework: ~5.8.0|~6.0|~6.2.0
- nesbot/carbon: ~2.0
- symfony/http-kernel: ^4.3|^5.0
Requires (Dev)
- illuminate/http: ~5.8.0|^6.0|^7.0
- illuminate/routing: ~5.8.0|^6.0|^7.0
- illuminate/view: ~5.8.0|^6.0|^7.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.5|^8.0
- vlucas/phpdotenv: ~4.0
This package is auto-updated.
Last update: 2024-09-07 07:15:27 UTC
README
简介
Laravel Cashier-Authorize提供了一组表达性、流畅的接口来访问Authorize.net的订阅计费服务。它处理了几乎您讨厌编写的所有样板订阅计费代码。除了基本的订阅管理外,Cashier-Authorize还可以处理宽限期,甚至生成发票PDF。
基本设置
请阅读以下基本设置。
.env
ADN_ENV= ADN_LOG=authorize.log
ADN_API_LOGIN_ID= ADN_TRANSACTION_KEY= ADN_SECRET_KEY=Simon
ADN_ENV可以是以下之一:sandbox、production
迁移
您需要创建以下迁移
Schema::table('users', function ($table) { $table->string('authorize_id')->nullable(); $table->string('authorize_payment_id')->nullable(); $table->string('card_brand')->nullable(); $table->string('card_last_four')->nullable(); });
Schema::create('subscriptions', function ($table) { $table->increments('id'); $table->integer('user_id'); $table->string('name'); $table->string('authorize_id'); $table->string('authorize_payment_id'); $table->text('metadata'); $table->string('authorize_plan'); $table->integer('quantity'); $table->timestamp('trial_ends_at')->nullable(); $table->timestamp('ends_at')->nullable(); $table->timestamps(); });
发布
您需要发布此包的资产。
php artisan vendor:publish --provider="Laravel\CashierAuthorizeNet\CashierServiceProvider"
配置
以下是用于与Authorize.net兼容的订阅的示例配置。您可以在该配置中定义您的订阅。
'monthly-10-1' => [ 'name' => 'main', 'interval' => [ 'length' => 1, // number of instances for billing 'unit' => 'months' //months, days, years ], 'total_occurances' => 9999, // 9999 means without end date 'trial_occurances' => 0, 'amount' => 9.99, 'trial_amount' => 0, 'trial_days' => 0, 'trial_delay' => 0, // days you wish to delay the start of billing ]
'config/services.php'
您需要在'config/services.php'文件中添加以下内容,请确保模型与您的应用程序的用户类匹配
'authorize' => [ 'model' => App\User::class, ],
您也可以使用以下.env变量设置此值:ADN_MODEL
基本用法
与Stripe等服务相比,Authorize.net有一些不同。Authorize.net是一个稍微慢一些且限制更多的订阅服务提供商。这意味着您不能进行像交换订阅或更改订阅数量这样的操作。您需要取消订阅并创建新的订阅来处理这些变化。
您可以进行以下操作
用户:
- charge($amount, array $options = [])
- hasCardOnFile
- newSubscription($subscription, $plan)
- onTrial($subscription = 'default', $plan = null)
- onGenericTrial()
- subscribed($subscription = 'default', $plan = null)
- subscription($subscription = 'default')
- subscriptions()
- updateCard($card) // $card = ['number' => '', 'expriation' => '']
- subscribedToPlan($plans, $subscription = 'default')
- onPlan($plan)
- hasAuthorizeId()
- createAsAuthorizeCustomer($creditCardDetails)
- upcomingInvoice($plan)
- findInvoice($invoiceId)
- findInvoiceOrFail($id)
- downloadInvoice($id, array $data, $storagePath = null)
- getSubscriptionFromAuthorize($subscriptionId)
- invoices($plan)
- deleteAuthorizeProfile()
- preferredCurrency()
- taxPercentage() (此方法应添加到用户模型中,并定义用户的税率,例如:return 10;)
交易详情
启用API以启用交易详情API
- 登录到https://account.authorize.net的商家界面。
- 在左侧主菜单中,选择“账户”下的“设置”。
- 在安全设置部分中单击“交易详情API”链接。打开交易详情API屏幕。
- 如果您尚未启用交易详情API,请输入您的密保问题答案,然后单击“启用交易详情API”。
- 成功启用交易详情API后,将显示设置页面。
CRON作业
您需要启用以下CRON作业来检查用户订阅的状态。这可以按照您的喜好运行,并会确认您的用户订阅是否处于活动状态。如果状态更改为已取消或暂停,系统将本地禁用他们的订阅。您的团队需要与Authorize.net解决付款问题,然后继续前进。
protected $commands = [ \Laravel\CashierAuthorizeNet\Console\SubscriptionUpdates::class, ];
$schedule->command('subscription:update')->hourly();
限制
另一个限制与时间相关。由于Authorize.net使用SOAP结构为其API,在将具有信用卡的客户添加到其系统以及添加订阅到该用户之间需要时间延迟。这可以通过在您的应用中让用户输入他们的信用卡信息,然后允许他们确认他们希望购买的订阅作为另一个动作来实现。这个时间可以短至一秒,但迄今为止所有立即添加订阅的测试都无法正常工作,所以请在设计应用时注意这个限制。
许可
Laravel Cashier-Authorize是开源软件,受MIT许可证授权 "# cashier-authorize"。