cometcult / braintree-bundle
Braintree PHP 客户端库的 Symfony 2 扩展包
0.1.0
2015-12-11 13:47 UTC
Requires
- php: >=5.3.2
- braintree/braintree_php: *
Requires (Dev)
- phpspec/phpspec: dev-master
- symfony/framework-bundle: >=2.2,<2.3-dev
This package is not auto-updated.
Last update: 2024-09-11 10:19:01 UTC
README
Braintree PHP 客户端库的 Symfony 2 扩展包
安装
Composer
只需将以下内容添加到您的 composer.json 文件中
{ "require": { "cometcult/braintree-bundle": "dev-master" } }
应用内核
将扩展包添加到您应用的内核中
// app/AppKernel.php public function registerBundles() { return array( // ... new CometCult\BraintreeBundle\CometCultBraintreeBundle(), // ... ); }
配置
# app/config/config.yml # ... comet_cult_braintree: environment: sandbox merchant_id: your_merchant_id public_key: your_public_key private_key: your_private_key
有关配置变量的更多信息,请参阅 Braintree 文档
用法
Braintree PHP 客户端库附带了一组用于 Braintree API 的服务。它们通常以 Braintree_
为前缀。要查看所有可用的 Braintree 服务,请访问 braintree_php 或 官方文档。
工厂
获取所需服务的一种方法是调用 BraintreeFactory
的 get
方法
// in your controller $factory = $this->get('comet_cult_braintree.factory'); $customerService = $factory->get('customer');
定义一个服务
您可以直接在您的扩展包中定义一个自定义服务,而不是调用工厂
# ../services.yml services: customer_custom_service: class: Braintree_Customer factory_service: comet_cult_braintree.factory factory_method: get arguments: ["customer"]
然后,在您的控制器中,您可以这样做:
$customerService = $this->get('customer_custom_service');