PHP code example of nikjaysix / laravel-chargify

1. Go to this page and download the library: Download nikjaysix/laravel-chargify 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/ */

    

nikjaysix / laravel-chargify example snippets


    # Add `LaravelChargifyServiceProvider` to the `providers` array
    'providers' => array(
        ...
        NikJaySix\LaravelChargify\LaravelChargifyServiceProvider::class,
    )

    # Add the `LaravelChargifyFacade` to the `aliases` array
    'aliases' => array(
        ...
        'Chargify' => NikJaySix\LaravelChargify\LaravelChargifyFacade::class
    )
    

    return array(
        'hostname' => '****.chargify.com',
        'api_key' => 'chargify api key',
        'shared_key' => 'chargify shared key'
    );
    


$chargify = App::make('chargify');
  
// $handle is the subscription handle created in chargify
$new_subscription = $chargify->subscription()
    ->setProductHandle($handle)
    ->setCustomerAttributes([
        'first_name' => $user->first_name,
        'last_name' => $user->last_name,
        'email' => $user->email,
        'reference' => $user->id
    ])
    ->create();
  
if($new_subscription->isError()) {
    $errors = $new_subscription->getErrors();
    // handle errors
}

 

$chargify = App::make('chargify');  
  
$subscription = $chargify->subscription();
  
// $user_subscription->subscription_id is the subscription ID generated by chargify
$subscription->read($user_subscription->subscription_id);
  
if($subscription->isError()) {
    $errors = $subscription->getErrors();
    // handle errors
}
  
// store subscription data in session
foreach ($subscription as $key => $value) {
    session(['subscription_' . $key => $value]);
}
shell
    $ php artisan vendor:publish