Package Data | |
---|---|
Maintainer Username: | NikJaySix |
Maintainer Contact: | hello@nikjaysix.com.au (Nicole Jay) |
Package Create Date: | 2017-07-08 |
Package Last Update: | 2018-02-18 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:00:54 |
Package Statistics | |
---|---|
Total Downloads: | 12,296 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This is a wrapper using the chargley chargify SDK v0.1.4. It creates a service provider and facade for autoloading into laravel.
Install the nikjaysix/laravel-chargify
package
$ composer require nikjaysix/laravel-chargify
Update config/app.php
to activate the LaravelChargify package
# 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
)
Generate a Chargify config file
$ php artisan vendor:publish
Update app/config/chargify.php
with your chargify API credentials
return array(
'hostname' => '****.chargify.com',
'api_key' => 'chargify api key',
'shared_key' => 'chargify shared key'
);
Creating subscriptions with v1 of the API
$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
}
Retrieve a user's subscription
$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]);
}