Note:
This bundle is still in active development and is not ready for production. Both the documentation for this bundle and the bundle itself are still very much a work in progress. More information coming soon
The FridgeSubscriptionBundle provides everything you need to implement subscription plans and recurring payments in your Symfony2 application.
- This bundle requires PHP 5.4+
- This bundle requires you have a stripe account
- This bundle requires that you are using the Doctrine ORM
- Download FridgeSubscriptionBundle using composer
- Enable the Bundle
- Create association between your User class and a StripeProfile
- Configure the FridgeSubscriptionBundle
- Import FridgeSubscriptionBundle webhook routing
- Update your database schema
Add FridgeSubscriptionBundle in your composer.json:
{
"require": {
"fridge/subscription-bundle": "dev-master",
}
}Now tell composer to download the bundle by running the command:
$ php composer.phar update fridge/subscription-bundleComposer will install the bundle to your project's vendor/fridge directory.
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Fridge\SubscriptionBundle\FridgeSubscriptionBundle(),
);
}This bundle assumes that you already have implemented your own User class. If you have not then a good place to look is the FOSUserBundle.
This bundle provides a StripeProfile entity that has a one-to-one association with your User. As the User must have the owning side of the association you must add this.
If you use annotations:
<?php
/**
* @ORM\OneToOne(targetEntity="Fridge\SubscriptionBundle\Entity\StripeProfile", cascade={"all"})
* @ORM\JoinColumn(name="stripe_profile_id", referencedColumnName="id")
*/
protected $stripeProfile;If you use yaml:
oneToOne:
stripeProfile:
targetEntity: Fridge\SubscriptionBundle\Entity\StripeProfile
cascade: all
joinColumn:
name: stripe_profile_id
referencedColumnName: idFinally add a getter/setter for the stripe profile to your user entity:
public function setStripeProfile(StripeProfile $stripeProfile)
{
$this->stripeProfile = $stripeProfile;
return $this;
}
public function getStripeProfile()
{
if(!$this->stripeProfile) {
$this->setStripeProfile(new StripeProfile);
}
return $this->stripeProfile;
}
This bundle needs to be aware of your User class.
Full configuration options coming soon.
# app/config/config.yml
fridge_subscription:
user_class: Fridge\UserBundle\Entity\User
stripe_sk: YourLiveStripeKey
# app/config/config_dev.yml
fridge_subscription:
user_class: Fridge\UserBundle\Entity\User
stripe_sk: YourTestStripeKey
# app/config/config_test.yml
fridge_subscription:
user_class: Fridge\UserBundle\Entity\User
stripe_sk: YourTestStripeKey
Now that you have activated and configured the bundle, all that is left to do is import the FridgeSubscriptionBundle webhook routing.
By importing the routing files you will allow stripe to call your server to inform it of events such as invoice payment failures, and allow the bundle to take action such as cancelling users subscriptions.
In YAML:
# app/config/routing.yml
fridge_subscription_routing:
resource: "@FridgeSubscriptionBundle/Resources/config/routing.yml"
type: restOr if you prefer XML:
<!-- app/config/routing.xml -->
<import resource="@FridgeSubscriptionBundle/Resources/config/routing.yml" type="rest" />Now that the bundle is configured, the last thing you need to do is update your database schema to add the FridgeSubscriptionBundle entities are create the association with your User entity.
For ORM run the following command.
$ php app/console doctrine:schema:update --forceMore information coming soon
