PHP code example of lordjoo / laraapigee

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

    

lordjoo / laraapigee example snippets


// fetch all developers
\Lordjoo\LaraApigee\Facades\LaraApigee::edge()->developers()->get();


// create a developer
$dev = new \Lordjoo\LaraApigee\Api\Edge\Entities\Developer();
$dev->setFirstName('Ammar')->setLastName("Agha")->setEmail('[email protected]')->setUserName('ammar');

$dev = \Lordjoo\LaraApigee\Facades\LaraApigee::edge()->developers()->create($dev);

// update a developer
$dev->setFirstName('Ammar')->setLastName("Aghaa");
$dev = \Lordjoo\LaraApigee\Facades\LaraApigee::edge()->developers()->update($dev->getEmail(), $dev);


$mint = \Lordjoo\LaraApigee\Facades\LaraApigee::monetization();

// List monetization packages (wrapper keeps totalRecords metadata)
$packages = $mint->apiPackages()->list(['page' => 1, 'size' => 20]);

// Add a product to a package (pass product-specific rate plans only when needed)
$mint->apiPackages()->addProduct('package-id', 'product-id');

// Find monetization information for a developer
$developer = $mint->developers()->find('[email protected]');

// Create a package rate plan
$ratePlan = new \Lordjoo\LaraApigee\Api\Monetization\Edge\Entities\RatePlan([
    'name' => 'standard-plan',
    'displayName' => 'Standard Plan',
]);
$mint->ratePlans()->createForPackage('package-id', $ratePlan);

// Issue a credit (query-parameter based API)
$credit = (new \Lordjoo\LaraApigee\Api\Monetization\Edge\ValueObjects\IssueCreditRequest())
    ->setBillingMonth('JULY')
    ->setBillingYear(2024)
    ->setCurrencyId('usd')
    ->setDeveloperId('developer-id')
    ->setTransactionAmount('25.00')
    ->setTransactionNote('Promotional credit');

$mint->credits()->issueToDeveloper('package-id', 'plan-id', $credit);

// Search transaction activity
$criteria = new \Lordjoo\LaraApigee\Api\Monetization\Edge\Entities\MintCriteria([
    'billingMonth' => 'JULY',
    'billingYear' => '2024',
]);
$transactions = $mint->reports()->searchTransactions($criteria, ['page' => 1, 'size' => 50]);

$monetization = \Lordjoo\LaraApigee\Facades\LaraApigee::monetization();

// List rate plans for a product
$plans = $monetization->ratePlans('my-product')->list();

// Create a developer subscription
$subscription = new \Lordjoo\LaraApigee\Api\Monetization\ApigeeX\Entities\DeveloperSubscription([
    'apiproduct' => 'organizations/my-org/apiproducts/my-product',
    'startTime' => (string) (time() * 1000),
]);

$monetization->developerSubscriptions('[email protected]')->create($subscription);

// Enable monetization at the organization level
$monetization->addons()->setMonetizationEnabled(true);