定制 tbleckert/laramill 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tbleckert/laramill

Composer 安装命令:

composer require tbleckert/laramill

包简介

LaraMill is a Laravel package that provides a powerful bridge to Paymill that makes it easy to handle payments and subscriptions

README 文档

README

Note: Special thanks to @hostianer for the new name!

LaraMill is a Laravel package that provides a powerful bridge to Paymill that makes it easy to handle payments and subscriptions

Install

Simply add LaraMill to your composer.json:

"tbleckert/laramill": "1.0-beta.2"

...and run composer install tbleckert/laramill. This will install the package. You also have to add 'Tbleckert\LaraMill\LaraMillServiceProvider' to your providers array.

Update users table

LaraMill saves and uses two database columns, these are: subscription_id (string/varchar) and client_id (string/varchar). This means you have to manually make a migration that adds these columns to your user table.

Setup model

To use LaraMill you have to update your User model to something like this:

use Tbleckert\LaraMill\LaraMillInterface;
use Tbleckert\LaraMill\LaraMillTrait;

class User extends Eloquent implements LaraMillInterface {

    use LaraMillTrait;

}

Configure

To start using LaraMill you need to publish the config files:

php artisan config:publish tbleckert/laramill

Then fill in your public and private Paymill keys in your new config located at app/config/packages/tbleckert/laramill/config.php

Offers

To add Paymill offers/plans you open the config file (see above) and fill the offers array as follows:

'offers'  => array(
	'Basic' => array(
		'monthly'  => 'offer_key',
		'annually' => 'offer_key'
	),
	'Special' => array(
		'daily'  => 'offer_key',
		'weekly' => 'offer_key'
	)
)

Each offer has a name and an array containing offer keys for each payment interval that the offer supports. As an example, you would use this code to subscribe a user to the basic plan with annual payment:

$user = User::find(1);
$user->subscription('Basic', 'annually')->create($token);

More about subscriptions further down.

Clients

Each user needs a client in Paymill. I suggest that you set up a client in the user registration step (even if you support free accounts). This way, you have the user prepared for subscriptions and payments.

Create client

The email column will be used by default as the client email.

$user->client()->create();

To set a different email, you can just pass it as a parameter in the create method:

$user->client()->create('myemail@domain.com');

You can also add an optional description text

$user->client()->create('myemail@domain.com', 'Client description');

Update client

Updating a client is very similar to creating one:

$user->client()->update('myemail@domain.com', 'Client description');

Remove client

To remove a client from paymill, simply use the remove method:

$user->client()->remove();

Payments

For any subscription or transaction, the client needs a payment. To create a payment we need to use the Paymill Bridge. The Bridge generates a token that we need when creating our payment.

Create payment

For the token generation, please have a look at the official Paymill documentation. Then, for the back-end:

$token = Input::get('paymillToken');
$user->payment($token)->create();

Update payment

There's no functionality for updating a payment, since that makes no sense. Instead, just create a new one and if you want, remove the old one.

Remove payment

$user->payment(false, 'payment_id')->remove();

Payment details

The details for a payment can give you information like card type, last four card numbers and more.

$user->payment(false, 'payment_id')->details();

List all payments

To get all payments created for a user, use the all method:

$user->payment()->all();

Subscriptions

Subscriptions connects a client to an offer with a payment. Paymill handles the payments automatically on the given interval.

Create subscription

For a subscription to work, the client needs a payment. You can either pass a payment id to the subscription method or let LaraMill automatically set the last registered payment. If the user already have a subscription, the create method will throw an exception.

$user->subscription('Basic', 'annually')->create(); // Alternative 1
$user->subscription('Basic', 'annually', 'payment_id')->create(); // Alternative 2

Subscription details

Since the subscription id is saved to the database, you don't have to pass any parameter.

$user->subscription()->details();

Swap subscription

To move the client to a new subscription plan you can use the swap method. Set the new subscription (just like the create method) and call swap.

$user->subscription('Basic', 'monthly')->swap();

Pause subscription

Pausing a subscription requires no parameters and you can use resume to resume the subscription at any time.

$user->subscription()->pause();

Resume subscription

When a subscription is paused you can use this method to activate it again.

$user->subscription()->resume();

Remove subscription

Removing a subscription will delete it completely from Paymill and removes the subscription id from the database. Check the cancel method to only cancel the subscription.

$user->subscription()->remove();

Cancel subscription

When you cancel a subscription it will remain in your database and in Paymill, but it will not be active. Therefor it can be activated again manually in the Paymill admin. To completely remove it, see the remove method.

$user->subscription()->cancel();

List all subscriptions

At the moment, LaraMill only supports 1 subscription per user, but the all method still exists:

$user->subscription()->all();

Transactions

Transactions are one off payments and can be made against a stored payment.

Create transaction

For a transaction to work, the client needs a payment. You can either pass a payment id to the transaction method or let LaraMill automatically set the last registered payment.

$transaction = $user->transaction('payment_id', false, 1000)->create();

Transaction details

The details for a transaction can give you information like card type, last four card numbers and more.

$transaction = $user->transaction(false, 'transaction_id')->details();

tbleckert/laramill 适用场景与选型建议

tbleckert/laramill 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 11, 最近一次更新时间为 2015 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payments」 「laravel」 「billing」 「paymill」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tbleckert/laramill 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tbleckert/laramill 我们能提供哪些服务?
定制开发 / 二次开发

基于 tbleckert/laramill 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-04-19