atacante / cashier-authorizenetpaisa
Laravel Cashier-Authorize 提供了访问 Authorize.net 订阅计费服务的表达性、流畅的接口。
Requires
- php: >=5.5.9
- authorizenet/authorizenet: ^1.9.2
- dompdf/dompdf: ^0.6.1
- illuminate/container: ^5.2|^5.1
- illuminate/database: ~5.1
- illuminate/support: ~5.1
- nesbot/carbon: ~1.0
- symfony/http-kernel: ~2.7|~3.0
Requires (Dev)
- goetas/xsd-reader: 2.*@dev
- goetas/xsd2php: 2.0.x-dev#fdc2ab0bb3f2b3ab796ca567cf8c0f3446a7ea3a
- illuminate/http: ~5.1
- illuminate/routing: ~5.1
- illuminate/view: ~5.1
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
- vlucas/phpdotenv: ~2.0
This package is not auto-updated.
Last update: 2024-09-18 21:04:45 UTC
README
简介
Laravel Cashier-Authorize 提供了访问 Authorize.net 订阅计费服务的表达性、流畅的接口。它处理了你可能讨厌编写的大部分模板化订阅计费代码。除了基本的订阅管理外,Cashier-Authorize 还可以处理取消宽限期,甚至生成发票 PDF。
基本设置
请阅读以下内容以进行基本设置。
Composer 设置
composer require atacante/cashier-authorizenetpaisa
.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 的差异在于它是一个稍微慢一些且限制更多的订阅提供商。这意味着你不能进行像交换订阅或更改订阅数量这样的操作。你需要取消订阅并创建新的订阅来处理这些变化。
你可以执行以下操作
用户:
- 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() (此方法应添加到 User 模型中,并定义用户的税率,例如: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许可证许可。