PHP code example of navneetrai / laravel-subscription

1. Go to this page and download the library: Download navneetrai/laravel-subscription library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

navneetrai / laravel-subscription example snippets


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

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


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'=>''
    ],
  ]

];

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

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

$info = $processor->info();

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

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

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()]); 
		}
	}   
}
config/app.php
config/app.php

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

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