PHP code example of c975l / purchasecredits-bundle
1. Go to this page and download the library: Download c975l/purchasecredits-bundle 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/ */
c975l / purchasecredits-bundle example snippets
use c975L\PurchaseCreditsBundle\Exception\InsufficientCreditsException;
use c975L\PurchaseCreditsBundle\Service\CreditServiceInterface;
public function __construct(private readonly CreditServiceInterface $creditService) {}
// What is left
$balance = $this->creditService->getBalance($user);
// Takes credits, or writes nothing at all
try {
$this->creditService->spend($user, 5, 'Short link /abc', (string) $shortcut->getId());
} catch (InsufficientCreditsException $exception) {
// $exception->balance, $exception->amount
}
// Gives credits: a sign-up bonus from the site's own registration code, a gift
$this->creditService->grant($user, 3, 'Welcome credits', 'signup');