PHP code example of frangeris / biller

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

    

frangeris / biller example snippets


return new \Phalcon\Config([
    'database' => [
        'adapter' => 'Mysql',
        'host' => '127.0.0.1',
		// ...
    ],
    // ------------- ADD THIS -------------
    'biller' => [
    	'key' => '<YOUR STRIPE KEY>', // the stripe key
    	'custom_id' => 'id', // primary key of your user model, default 'id'
    	'custom_email' => 'email', // email field to use from user model for customers, default 'email'
    ]
]);

/*
 * Read the configuration file
 */
$config = \Biller\Gateway::me($config);

class User extends \Phalcon\Mvc\Model
{
    use Biller\Behavior\IsCustomer;

    // ...
}

// Get an user
$user = User::findFirst();

// create a new customer with pro plan using object attributes as metadata in stripe
$customer = $user->toCustomer($this->request->getPost('stripeToken'), 'pro', ['name', 'age', 'phone']);

// get customer stripe object
$user->customer('default_source');

// start a pro subscription with 14 days of trial
$user->subscription()->trial(14)->go('pro');

// get date when trial ends
$user->trial(14)->trial_end;

// go pro plan without trial
$user->subscription()->go('pro');

// change to enterprise plan
$user->subscription()->go('enterprise');

// go pro using a coupon
$user->subscription()->withCoupon('coupon')->go('pro');

// cancel the current subscription
$user->subscription()->cancel();

// verify if the user is subscribed
$user->subscribed();

// verify if the user has cancelled a subscription
$user->cancelled();

// verify if the user subscription is pro plan
$user->onPlan('pro');

// verify if the user is on a trial period
$user->onTrial();

sh
curl -sS https://getcomposer.org/installer | php
bash
./vendor/bin/phpunit tests/Biller/GatewayTest.php