baka / cashier
Phalcon Cashier 为 Stripe 的订阅计费服务提供了一种表达式丰富的流畅接口。
dev-master
2020-07-17 17:21 UTC
Requires
- php: >=7.1
- baka/auth: ~0.2
- baka/database: ~0.1
- dompdf/dompdf: ^0.6.1
- nesbot/carbon: ~1.0
- stripe/stripe-php: ~6.0
- vlucas/phpdotenv: ^2.4
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-18 02:41:47 UTC
README
简介
Phalcon Cashier 为 Stripe 的订阅计费服务提供了一种表达式丰富的流畅接口。它几乎处理了您讨厌编写的所有订阅计费代码。除了基本的订阅管理外,Cashier 还可以处理优惠券、交换订阅、订阅“数量”、取消宽限期,甚至生成发票 PDF。
测试设置
您需要在本地以及您的 Stripe 账户中设置以下详细信息以进行测试
本地
数据库配置
CREATE TABLE `companies` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(45) DEFAULT NULL, `profile_image` varchar(45) DEFAULT NULL, `website` varchar(45) DEFAULT NULL, `users_id` int(11) NOT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL, `is_deleted` int(11) DEFAULT NULL ); CREATE TABLE `apps` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(45) DEFAULT NULL, `description` varchar(45) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL, `is_deleted` int(11) DEFAULT NULL ); CREATE TABLE `subscriptions` ( `id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `name` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `stripe_id` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `stripe_plan` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `quantity` int(11) NOT NULL, `trial_ends_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `ends_at` timestamp NULL DEFAULT NULL ); ALTER TABLE `subscriptions` ADD PRIMARY KEY (`id`); ALTER TABLE `subscriptions` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12; /*To execute this commands a users table must be created*/ IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'users')) BEGIN ALTER TABLE `users` ADD `stripe_id` VARCHAR(200) NULL; ALTER TABLE `users` ADD `card_brand` VARCHAR(200) NULL; ALTER TABLE `users` ADD `card_last_four` VARCHAR(200) NULL; ALTER TABLE `users` ADD `trial_ends_at` timestamp NULL DEFAULT NULL; ALTER TABLE `users` ADD `active_subscription_id` VARCHAR(200) NULL DEFAULT NULL; END
在 config.php 中添加一些参数,如下所示
'stripe' => [ 'model' => 'App\Models\Users', 'secretKey' => null, 'publishKey' => null ]
模型设置
将可计费模型添加到用户模型
use Phalcon\Cashier\Billable; class User extends Authenticatable { use Billable; }
Stripe
计划
* monthly-10-1 ($10)
* monthly-10-2 ($10)
优惠券
* coupon-1 ($5)
官方文档
您可以在这里了解如何使用它。此外,它受到 Laravel 的启发,因此您可以查看Laravel 网站。
贡献
感谢您考虑为 Cashier 贡献。您可以在这里阅读贡献指南。
许可证
Phalcon Cashier 是开源软件,采用MIT 许可证授权。