定制 navneetrai/laravel-subscription 二次开发

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

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

navneetrai/laravel-subscription

Composer 安装命令:

composer require navneetrai/laravel-subscription

包简介

Subscription Billing manager for Laravel 5.2

README 文档

README

Build Status Coverage Status Total Downloads Latest Stable Version Latest Unstable Version License

laravel-subscription is a simple laravel 5 library for creating subscription billing and handling server notifications. It is primarily meant for people outside countries like US, UK and Canada where Stripe, Paypal Payments Pro are not available.

If you want to handle non-recurring payments, you can use Omnipay for one-time payments and token billing.

Supported services

The library supports Paypal and credit card processors 2Checkout, PayFast and CCNow. More services will be implemented soon.

Included service implementations:

  • Paypal
  • 2Checkout
  • PayFast
  • CCNow
  • more to come!

Installation

Add laravel-subscription to your composer.json file:

"require": {
  "navneetrai/laravel-subscription": "^1.0"
}

Use composer to install this package.

$ composer update

Registering the Package

Register the service provider within the providers array found in config/app.php:

'providers' => [
  // ...
  
  Userdesk\Subscription\SubscriptionServiceProvider::class,
]

Add an alias within the aliases array found in config/app.php:

'aliases' => [
  // ...
  
  'Subscription'     => Userdesk\Subscription\Facades\Subscription::class,
]

Configuration

There are two ways to configure laravel-subscription.

Option 1

Create configuration file for package using artisan command

$ php artisan vendor:publish --provider="Userdesk\Subscription\SubscriptionServiceProvider"

Option 2

Create configuration file manually in config directory config/subscription.php and put there code from below.

<?php
return [ 
  
  /*
  |--------------------------------------------------------------------------
  | Subscription Config
  |--------------------------------------------------------------------------
  */

  /*
  |--------------------------------------------------------------------------
  | Subscription Services
  |--------------------------------------------------------------------------
  |
  | This file is for storing the credentials for subscription services such
  | as Paypal, CCNow, PayFast, 2Checkout, and others. This file provides a sane
  | default location for this type of information, allowing packages
  | to have a conventional place to find your various credentials.
  |
  */
  'services' => [
    'paypal'=>[
      'email'=>'', 
      'logo'=>'',
      'auth'=>''
    ],
  ]

];

Credentials

Add your credentials to config/subscription.php (depending on which option of configuration you choose)

Usage

Basic usage

Just follow the steps below and you will be able to get a processor:

$paypal = Subscription::processor('Paypal');

Getting Processor Informationation

You can get basic Information for any processor by:

$processor = Subscription::processor($proc);

$info = $processor->info();

The value returned is a ProcessorInfo object. You can call getName, getLogo and getUrl methods on this processor to display Processor Name, Logo and Website Url for display purposes.

For getLogo method to work correctly you'll need to copy package assets to your project using

$ php artisan vendor:publish --provider="Userdesk\Subscription\SubscriptionServiceProvider"

Completing Subscription

Once you have the processor object you can call:

$processor = Subscription::processor($proc);

$processor->complete($id, $product, $consumer);

Complete method redirects to source processor so that your user can complete his payment.

$id is your unique Order ID. $product and $consumer are objects implementing SubscriptionProductContract and SubscriptionConsumerContract respectively.

A basic implementation of SubscriptionProductContract and SubscriptionConsumerContract are included with source in form of Classes\SubscriptionProduct and Classes\SubscriptionConsumer respectively.

Handling Processor Notifications

You can handle Processor Notifications and Processor Cart Return Data by forwarding them to ipn and pdt functions respectively.

Both these function excpects only one input with request data as array and returns TransactionResult object.

public function cartComplete(Request $request, $proc){
	$processor = Subscription::processor($proc);
	try{
		$result = $processor->pdt($request->all());
	}catch(TransactionException $exception){
		Log::error($exception->getMessage());	
	}
	
	if(!empty($result)){
		$cartId = $result->getId();
	  	if(!empty($cartId)){
	  		$action = $result->getAction();    
			if($action=='signup'){
				//Handle successful Signup
			}
		}else{
			Log::error('Cart Not Found For PDT', ['proc'=>$proc, 'data'=>$request->all()]);	
		}
	}
}
public function handleIpn(Request $request, $proc){
	$processor = Subscription::processor($proc);
	try{
	  	$result = $processor->ipn($request->all());
	}catch(Userdesk\Subscription\Exceptions\TransactionException $exception){
	  	//Handle Exceptions
	  	Log::error($exception->getMessage());  
	}

	if(!empty($result)){
	  	$cartId = $result->getId();
	  	if(!empty($cartId)){
		    $action = $result->getAction();        

		    if($action=='signup'){
		      //Handle Signup Code
		    }else if($action=='payment'){          
		      $transactionId = $result->getIdent();
		      $amount = $result->getAmount();
		      //Handle successful payments
		    }else if($action=='refund'){          
		      $transactionId = $result->getIdent();
		      $amount = $result->getAmount();
		      //Handle refunds
		    }else if($action=='cancel'){
		      //Handle cancellations;
		    }
		}else{
		    Log::error('Cart Not Found For IPN', ['proc'=>$proc, 'data'=>$request->all()]); 
		}
	}   
}

It is important to remember that IPN notifications are generally delivered via POST. So, you should add post method and remove csrf check for any route handling ipn notifications.

navneetrai/laravel-subscription 适用场景与选型建议

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

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

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

围绕 navneetrai/laravel-subscription 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 333
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-21