PHP code example of miracode / stripe-bundle

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

    

miracode / stripe-bundle example snippets

 php
// app/AppKernel.php
public function registerBundles()
{
  $bundles = array(
    // [...]
    new Miracode\StripeBundle\MiracodeStripeBundle(),
  );
}
 php
// config/bundles.php
return [
    // [...]
    Miracode\StripeBundle\MiracodeStripeBundle::class => ['all' => true],
];
 php
$customer = \Stripe\Customer::create([
    'email' => '[email protected]'
]);
 php
// src/EventListener/StripeSubscriber.php

namespace App\EventListener;

use Miracode\StripeBundle\Event\StripeEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class StripeSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            'stripe.charge.succeeded' => 'onChargeSucceededEvent',
        ];
    }

    //[...]
    
    public function onChargeSucceededEvent(StripeEvent $event)
    {
        $stripeEvent = $event->getEvent(); //Stripe event object (instanceof \Stripe\Event)
        $charge = $event->getObjectData(); //Stripe charge object (instanceof \Stripe\Charge)
    }
}
 php
// src/Entity/Charge.php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Miracode\StripeBundle\Model\AbstractChargeModel;

/**
 * @ORM\Entity()
 * @ORM\Table(name="stripe_charge")
 */
class Charge extends AbstractChargeModel
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @var int
     */
    protetced $id;
}