2017 © Pedro Peláez
 

library laravel-subscription

Subscription Billing manager for Laravel 5.2

image

navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  • Tuesday, June 6, 2017
  • by navneetrai
  • Repository
  • 3 Watchers
  • 15 Stars
  • 169 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 22 Versions
  • 6 % Grown

The README.md

Subscription Billing for Laravel 5

Build Status Coverage Status Total Downloads Latest Stable Version Latest Unstable Version License, (*1)

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., (*2)

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


Supported services

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

Included service implementations:, (*5)

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

Installation

Add laravel-subscription to your composer.json file:, (*6)

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

Use composer to install this package., (*7)

$ composer update

Registering the Package

Register the service provider within the providers array found in config/app.php:, (*8)

'providers' => [
  // ...

  Userdesk\Subscription\SubscriptionServiceProvider::class,
]

Add an alias within the aliases array found in config/app.php:, (*9)

'aliases' => [
  // ...

  'Subscription'     => Userdesk\Subscription\Facades\Subscription::class,
]

Configuration

There are two ways to configure laravel-subscription., (*10)

Option 1

Create configuration file for package using artisan command, (*11)

$ 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., (*12)

<?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), (*13)

Usage

Basic usage

Just follow the steps below and you will be able to get a processor:, (*14)

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

Getting Processor Informationation

You can get basic Information for any processor by:, (*15)

$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., (*16)

For getLogo method to work correctly you'll need to copy package assets to your project using, (*17)

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

Completing Subscription

Once you have the processor object you can call:, (*18)

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

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

Complete method redirects to source processor so that your user can complete his payment., (*19)

$id is your unique Order ID. $product and $consumer are objects implementing SubscriptionProductContract and SubscriptionConsumerContract respectively., (*20)

A basic implementation of SubscriptionProductContract and SubscriptionConsumerContract are included with source in form of Classes\SubscriptionProduct and Classes\SubscriptionConsumer respectively., (*21)

Handling Processor Notifications

You can handle Processor Notifications and Processor Cart Return Data by forwarding them to ipn and pdt functions respectively., (*22)

Both these function excpects only one input with request data as array and returns TransactionResult object., (*23)

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., (*24)

The Versions

06/06 2017

dev-master

9999999-dev https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/06 2017

v1.1.2-beta

1.1.2.0-beta https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/06 2017

v1.1-beta

1.1.0.0-beta https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/06 2017

v1.1.1-beta

1.1.1.0-beta https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

01/12 2016

1.0.13

1.0.13.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

26/11 2016

1.0.12

1.0.12.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

25/10 2016

1.0.11

1.0.11.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

21/10 2016

1.0.10

1.0.10.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

21/10 2016

1.0.9

1.0.9.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

21/10 2016

1.0.8

1.0.8.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

21/10 2016

1.0.7

1.0.7.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/09 2016

1.0.6

1.0.6.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/09 2016

1.0.5

1.0.5.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

06/09 2016

1.0.4

1.0.4.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

04/05 2016

1.0.3

1.0.3.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

04/05 2016

v1.0.2

1.0.2.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

30/04 2016

v1.0.1

1.0.1.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

30/04 2016

v1.0

1.0.0.0 https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

26/04 2016

v0.4-beta

0.4.0.0-beta https://github.com/navneetrai/laravel-subscription

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Navneet Rai

laravel 2checkout paypal subscription billing

26/04 2016

v0.3-beta

0.3.0.0-beta

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Navneet Rai

laravel 2checkout paypal subscription billing

26/04 2016

v0.2-beta

0.2.0.0-beta

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Navneet Rai

laravel 2checkout paypal subscription billing

21/04 2016

v0.1-beta

0.1.0.0-beta

Subscription Billing manager for Laravel 5.2

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Navneet Rai

laravel 2checkout paypal subscription billing