PHP code example of owlgrin / cashew
1. Go to this page and download the library: Download owlgrin/cashew 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/ */
owlgrin / cashew example snippets
"owlgrin/cashew": "dev-master"
...
'Owlgrin\Cashew\CashewServiceProvider'
...
...
'Cashew' => 'Owlgrin\Cashew\CashewFacade',
...
Cashew::create(Auth::user()->id, array('trial_end' => 'now', 'coupon' => 'earlybird'));
if(Auth::attempt($username, $password))
{
Cashew::user(Auth::user()->id);
}
Cashew::card('tok_o48H37h8eh');
Cashew::card('tok_o48H37h8eh', array('trial_end' => 'now'));
Cashew::coupon('20OFF');
Cashew::toPlan('premium');
Cashew::toPlan('premium', false); // no prorate
Cashew::toPlan('premium', true, false); // stop trial period immediately
Cashew::increment();
Cashew::decrement();
Cashew::increment(3);
Cashew::update(array('plan' => 'new-plan', 'coupon' => 'yipee'));
Cashew::cancel();
Cashew::cancelNow();
Cashew::resume();
Cashew::resume(array('plan' => 'premium', 'quantity' => 3));
Cashew::resume(array('plan' => 'premium'), 'tok_dff38rm347gBYF7');
Cashew::expire();
Cashew::expireCustomer($customerId);
if($user->birthday == Carbon\Carbon::today() && Cashew::hasCard())
{
// send birthday cake
}
Cashew::invoices();
// fetch from API
Cashew::invoices(false);
// fetch 25 invoices
Cashew::invoices(true, 25);
Cashew::nextInvoice();
if(Cashew::status() === 'active')
{
$user->sendGift();
}
if( ! Cashew::active())
{
Redirect::to(...);
}
if( ! Cashew::subscribed())
{
Redirect::to('billing.plans');
}
if(Cashew::inactive())
{
Offer::send(...);
}
if(Cashew::hasCard())
{
Redirect::to(...);
}
if(Cashew::onTrial())
{
// send them coupon code
}
if(Cashew::onGrace())
{
// show alert
}
if(Cashew::expired())
{
Redirect::to('billing');
}
if(Cashew::canceled())
{
Redirect::to('billing.upgrade');
}
if(Cashew::onPlan('gold'))
{
$allowReferral = true;
}
Route::post('hooks/stripe', 'Owlgrin\Cashew\CashewHookController@handle');
Event::listen('cashew.payment.success', function($id, $invoice)
{
User::find($id)->sendReceipt($invoice);
});
php artisan config:publish owlgrin/cashew
php artisan cashew:expire