bcismariu/laravel-payments

Cashier 的替代品

v0.1.12 2018-03-07 21:31 UTC

This package is auto-updated.

Last update: 2024-09-13 05:49:09 UTC


README

Build Status Latest Stable Version License Total Downloads

一个非常基础的 Laravel Cashier 替代品,用于允许更轻量级的实现。

安装

使用 composer 安装该包。

composer require bcismariu/laravel-payments

编辑 config/app.php 并将以下行添加到 providers 列表中

Bcismariu\Laravel\Payments\PaymentsServiceProvider::class

发布包配置文件

php artisan vendor:publish --provider="Bcismariu\\Laravel\\Payments\\PaymentsServiceProvider" --tag="config" --force

迁移数据库

php artisan migrate

注意!

如果您计划使用 konnektive 驱动程序,也应要求其依赖项。

composer require hassletauf/konnektive-crm

将以下行添加到您的 .env 文件中

KONNEKTIVE_LOGIN=your-konnektive-loginId
KONNEKTIVE_PASSWORD=your-konnektive-password

用法

在您的 User 模型上添加 Billable 特性

use Bcismariu\Laravel\Payments\Billable;

class User
{
    use Billable;

将信用卡信息导入您的 User 对象并对其进行收费

$user->setCreditCard(new Card([
    'brand'     => 'visa',
    'number'    => '0000000000000000',
    'exp_month' => '02',
    'exp_year'  => '2017',
    'cvc_check' => '123', 
]));

$response = $user->charge(5, [
        'product_id'    => 1234
    ]);

处理订阅

// Import the Credit Card info into your User object:

$user->setCreditCard(new Card([
    'brand'     => 'visa',
    'number'    => '0000000000000000',
    'exp_month' => '02',
    'exp_year'  => '2017',
    'cvc_check' => '123', 
]));

// Register the subscription and charge a certain amount:

$subscription = $user->subscribe('plan-name', 5);

// Check if the user has subscribed to a given plan

$user->subscribed('plan-name');