nacholibre/braintree-bundle

安装: 185

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 1

开放问题: 0

类型:symfony-bundle

0.1.7 2017-06-21 09:03 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:19 UTC


README

Braintree的PHP客户端库的Symfony 2 Bundle

安装

Composer

安装

composer require nacholibre/braintree-bundle

应用程序内核

将bundle添加到您的应用程序内核中

// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new nacholibre\BraintreeBundle\nacholibreBraintreeBundle(),
        // ...
    );
}

配置

# app/config/config.yml
# ...
nacholibre_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('braintree.factory');
$customerService = $factory->get('customer');

定义服务

您可以在自己的bundle中定义一个自定义服务,而不是调用工厂

# ../services.yml
services:
    customer_custom_service:
        class:            Braintree_Customer
        factory_service:  braintree.factory
        factory_method:   get
        arguments: ["customer"]

然后,在您的控制器中,您可以这样做:

$customerService = $this->get('customer_custom_service');