avro/stripe-bundle
Composer 安装命令:
composer require avro/stripe-bundle
包简介
Symfony2 Bundle for managing user subscriptions and payments with Stripe.
README 文档
README
A symfony2 bundle for interacting with the awesome Stripe payment service.
Features:
- Allow users to pay and receive money
- Subscribe a user to a plan
- Update a users plan
- View/print invoices & charges
- Create coupons
- Create plans
Status
WIP
Step 1: Download AvroStripeBundle using composer
Add AvroStripeBundle in your composer.json:
{ "require": { "jdewit/stripe-bundle": "*" } }
Now tell composer to download the bundle by running the command:
$ php composer.phar update jdewit/stripe-bundle
Step 2: Enable the bundle
Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Avro\StripeBundle\AvroStripeBundle(), ); }
Step 3: Update your user class
<?php namespace Application\UserBundle\Document; use FOS\UserBundle\Document\User as BaseUser; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** * @ODM\Document */ class User extends BaseUser { /** * @ODM\Id(strategy="auto") */ protected $id; /** * @ODM\String */ protected $stripeCustomerId; /** * @ODM\Boolean */ protected $isStripeCustomerActive; /** * @ODM\String */ protected $stripeAccessToken; /** * @ODM\String */ protected $stripePublishableKey; /** * @ODM\ReferenceOne(targetDocument="Avro\StripeBundle\Document\Plan") */ protected $plan; public function __construct() { parent::__construct(); // your own logic } public function getStripeAccessToken() { return $this->stripeAccessToken; } public function setStripeAccessToken($stripeAccessToken) { $this->stripeAccessToken = $stripeAccessToken; return $this; } public function getStripePublishableKey() { return $this->stripePublishableKey; } public function setStripePublishableKey($stripePublishableKey) { $this->stripePublishableKey = $stripePublishableKey; return $this; } public function getStripePublishableKey() { return $this->stripePublishableKey; } public function setStripePublishableKey($stripePublishableKey) { $this->stripePublishableKey = $stripePublishableKey; return $this; } public function getStripeCustomerId() { return $this->stripeCustomerId; } public function setStripeCustomerId($stripeCustomerId) { $this->stripeCustomerId = $stripeCustomerId; return $this; } public function getIsStripeCustomerActive() { return $this->isStripeCustomerActive; } public function setIsStripeCustomerActive($isStripeCustomerActive) { $this->isStripeCustomerActive = $isStripeCustomerActive; return $this; } public function getPlan() { return $this->plan; } public function setPlan(\Avro\StripeBundle\Document\Plan $plan) { $this->plan = $plan; return $this; } /** * Get user information to prefill stripe signup form */ public function getStripeConnectionParameters() { return array( 'stripe_user[email]' => $user->getEmail() ?: '', //'stripe_user[url]' => $user->getWebsite() ?: '', //'stripe_user[phone_number]' => $user->getPhone() ?: '', //'stripe_user[business_name]' => $user->getCompany() ?: '', //'stripe_user[first_name]' => $user->getFirstName() ?: '', //'stripe_user[last_name]' => $user->getLastName() ?: '', //'stripe_user[street_address]' => $user->getAddress() ?: '', //'stripe_user[city]' => $user->getCity() ? $user->getCity()->getName() : '', //'stripe_user[state]' => $user->getProvince() ? $user->getProvince()->getName() : '', //'stripe_user[country]' => $user->getCountry() ? $user->getCountry()->getName() : '', //'stripe_user[zip]' => $user->getPostalCode() ?: '', ); } }
Step 5: Extend the bundle
Create a bundle skeleton that extends this bundle
namespace Application\StripeBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class ApplicationStripeBundle extends Bundle { public function getParent() { return 'AvroStripeBundle'; } }
Step 6: Create a plan class
The plan class is a superclass which needs to be extended. This allows you to add custom methods such as usage limits etc...
<?php //Application/StripeBundle/Document/Plan namespace Application\StripeBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Symfony\Component\Validator\Constraints as Assert; use Avro\StripeBundle\Document\Plan as BasePlan; /** * @ODM\Document */ class Plan extends BasePlan { /** * @ODM\Id(strategy="none") */ public $id; // customize to your needs, not required // /** // * @ODM\Int // */ // protected $limit; // // /** // * @ODM\Boolean // */ // protected $phoneSupport = false; /** * Get id * * @return id $id */ public function getId() { return $this->id; } public function setId($id) { $this->id = $id; } }
Step 7: Configure your application's security.yml
Make sure the routes are accessible only to authenticated users
# app/config/security.yml security: access_control: - { path: ^/stripe/, role: ROLE_USER }
Step 8: Configure the AvroStripeBundle
Add your Stripe API keys to your config.yml
# app/config/config.yml avro_stripe: #required client_id: %stripe_client_id% // define these in your parameters.yml and parameters_prod.yml secret_key: %stripe_secret_key% publishable_key: %stripe_publishable_key% #optional db_driver: mongodb # other storage is yet to be implemented by... you? hooks_enabled: false #use bundles default hook events (send emails etc...) prorate: false #prorate updated subscription charges redirect_routes: #set routes to redirect to, default is to redirect to homepage customer_new: application_user_settings_payment customer_update: application_user_settings_payment customer_disable: application_user_settings_payment subscription_update: application_user_settings_subscription account_confirm: application_user_settings_payment account_disconnect: application_user_settings_payment
Step 9: Import AvroStripeBundle routing files
Import the AvroStripeBundle routing files.
In YAML:
# app/config/routing.yml avro_stripe: resource: "@AvroStripeBundle/Resources/config/routing/routing.yml"
Step 10: Update your database schema
Now that the bundle is configured, the last thing you need to do is update your database schema.
For MongoDB, you can run the following command to create the indexes.
$ php app/console doctrine:mongodb:schema:create --index
Hooks
The bundle receives hooks at "/stripe/hook" and dispatches the event which you can listen for
for example.
the 'charge.succeeded' event is dispatched as 'avro_stripe.charge.succeeded' by the HookController
###Notes
If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config.
# app/config/config.yml framework: translator: ~
In order to use the built-in email functionality, you must activate and configure the SwiftmailerBundle.
Next Steps
avro/stripe-bundle 适用场景与选型建议
avro/stripe-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 386 次下载、GitHub Stars 达 16, 最近一次更新时间为 2012 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「subscription」 「billing」 「credit card」 「plan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 avro/stripe-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 avro/stripe-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 avro/stripe-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Integration with Cielo gateway.
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Laravel Cashier provides an expressive, fluent interface to Braintree's subscription billing services.
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
统计信息
- 总下载量: 386
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-16