PHP code example of vovanmix / laravel5-billing-braintree

1. Go to this page and download the library: Download vovanmix/laravel5-billing-braintree 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/ */

    

vovanmix / laravel5-billing-braintree example snippets


$planExternalId = 'test';
$planAddOns = [1, 2]; // IDs of  add ons, optional
$planDiscounts = [1, 2]; // IDs of discounts, optional
$removeAddOns = [3, 4]; // IDs of add ons that default for this plan but needed to be removed from it, optional
$removeDiscounts = [3, 4]; // IDs of discounts that default for this plan but needed to be removed from it, optional
$summary = \Billing::getPlanSummary($planExternalId, $planAddOns, $planDiscounts, $removeAddOns, $removeDiscounts);

$messageBag = new MessageBag();    // catching errors is optional but is a good practice
try {    
    $customerData = [        
        'first_name' => Input::get('first_name'),            
        'last_name' => Input::get('last_name'),           
        'nonce' => Input::get('nonce'),    // payment method nonce, obtained at the front end using Braintree Javascript library. See more in Braintree Docs        
        'address' => Input::get('address'),            
        'city' => Input::get('city'),            
        'state' => Input::get('state'),            
        'zip' => Input::get('zip')            
    ];        
    $customerId = \Billing::createCustomer($customerData);        
} catch (\Exception $e){    
    $messageBag->add('error', $e->getMessage());        
}

$messageBag = new MessageBag();    
try {   
    $planExternalId = 'test';
    $planAddOns = [1, 2]; // IDs of  add ons, optional
    $planDiscounts = [1, 2]; // IDs of discounts, optional
    $removeAddOns = [3, 4]; // IDs of add ons that default for this plan but needed to be removed from it, optional
    $removeDiscounts = [3, 4]; // IDs of discounts that default for this plan but needed to be removed from it, optional
    $subscriptionId = \Billing::createSubscription($customerId, $planExternalId, $planAddOns, $planDiscounts, $removeAddOns, $removeDiscounts);
} catch (\Exception $e){    
    $messageBag->add('error', $e->getMessage());        
}

$customerData = [        
    'first_name' => Input::get('first_name'),            
    'last_name' => Input::get('last_name'),           
    'nonce' => Input::get('nonce'),    // payment method nonce, obtained at the front end using Braintree Javascript library. See more in Braintree Docs      
    'address' => Input::get('address'),            
    'city' => Input::get('city'),            
    'state' => Input::get('state'),            
    'zip' => Input::get('zip')            
];  
$success = \Billing::updatePaymentMethod($subscriptionId, $customerData);

$subscriptionInfo = \Billing::getSubscriptionInfo($subscriptionId);

\Billing::checkIfSubscriptionIsEnabled($subscriptionId);

\Billing::checkIfSubscriptionIsActive($subscriptionId);

\Billing::checkIfSubscriptionWasSuccessfullyBilled($subscriptionId)

\Billing::checkIfSubscriptionIsPaid($subscriptionId);

\Billing::checkIfSubscriptionIsPastDue($subscriptionId);

\Billing::cancelSubscription($subscriptionId);
shell
php artisan vendor:publish