1. Go to this page and download the library: Download zfr/zfr-cash 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/ */
zfr / zfr-cash example snippets
use ZfrCash\Entity\BillableInterface;
use ZfrCash\Entity\BillableTrait;
use ZfrCash\Entity\CustomerInterface;
use ZfrCash\Entity\CustomerTrait;
class User implements CustomerInterface, BillableInterface
{
use CustomerTrait;
use BillableTrait;
}
use ZfrCash\Entity\CustomerInterface;
use ZfrCash\Entity\CustomerTrait;
class User implements CustomerInterface
{
use CustomerTrait;
}
use ZfrCash\Entity\BillableInterface;
use ZfrCash\Entity\BillableTrait;
class Project implements BillableInterface
{
use BillableTrait;
}
/**
* @ORM\Entity(repositoryClass="User\Repository\UserRepository")
*/
class User implements CustomerInterface
{
use CustomerTrait;
}
namespace User\Repository;
use Doctrine\ORM\EntityRepository;
use ZfrCash\Repository\CustomerRepositoryInterface;
class UserRepository extends EntityRepository implements CustomerRepositoryInterface
{
public function findOneByStripeId($stripeId)
{
return $this->findOneBy(['stripeId' => $stripeId]);
}
}
namespace Application\Listener;
use ZfrCash\Controller\WebhookListenerController;
use ZfrCash\Event\WebhookEvent;
class CustomStripeListener extends AbstractListenerAggregate
{
public function attachAggregate(EventManagerInterface $eventManager)
{
$sharedManager = $eventManager->getSharedManager();
$sharedManager->attach(WebhookListenerController::class, WebhookEvent::WEBHOOK_RECEIVED, [$this, 'handleStripeEvent']);
}
/**
* @param WebhookEvent $event
*/
public function handleStripeEvent(WebhookEvent $event)
{
$stripeEvent = $event->getStripeEvent(); // This is the full Stripe event
switch ($stripeEvent['type']) {
case 'invoice.payment_failed':
// Do something...
break;
}
}
}
class UserController extends AbstractActionController
{
public function createAction()
{
// Create your user... that implements CustomerInterface
$cardToken = $this->params()->fromQuery('card_token');
$discount = $this->params()->fromQuery('discount');
$user = $this->customerService->create($user, [
'card' => $cardToken, // If Stripe API version is older than 2015-02-18
'source' => $cardToken, // If Stripe API version is newer or equal than 2015-02-18
'discount' => $discount,
'email' => $user->getEmail()
]);
}
}