tear / moip-bundle
MoIP 与 Symfony PHP 的集成
1.0.1
2017-10-24 14:31 UTC
Requires
- moip/moip-sdk-php: ^2.1
- symfony/config: ^2.7|^3.1
- symfony/dependency-injection: ^2.7|^3.1
- symfony/http-kernel: ^2.7|^3.1
Requires (Dev)
- phpunit/phpunit: ^5.6
This package is auto-updated.
Last update: 2024-09-04 21:57:57 UTC
README
安装
composer require tear/moip-bundle
添加到您的 appKernel
// app/AppKernel.php public function registerBundles() { return [ // ... new LeonnLeite\MoipBundle\MoipBundle(), // ... ]; }
##配置:初始配置,只需放置 token 和 key
// app/config/config.yml moip: credential: token: 01010101010101010101010101010101 key: ABABABABABABABABABABABABABABABABABABABAB
如果您通过 OAuth 连接
对于 OAuth,不需要 key。Token 变成 accessToken 的角色
// app/config/config.yml moip: credential: token: 01010101010101010101010101010101 authentication_mode: OAuth
如果您想上线生产环境
放置参数 production: true
// app/config/config.yml moip: credential: token: 01010101010101010101010101010101 key: ABABABABABABABABABABABABABABABABABABABAB production: true
使用方法
使用服务 moip
//... class AcmeController extends Controller { public function indexAction() { try { $customer = $this->get('moip') ->customers()->setOwnId(uniqid()) ->setFullname('Fulano de Tal') ->setEmail('fulano@email.com') ->setBirthDate('1988-12-30') ->setTaxDocument('22222222222') ->setPhone(11, 66778899) ->addAddress('BILLING', 'Rua de teste', 123, 'Bairro', 'Sao Paulo', 'SP', '01234567', 8) ->addAddress('SHIPPING', 'Rua de teste do SHIPPING', 123, 'Bairro do SHIPPING', 'Sao Paulo', 'SP', '01234567', 8) ->create(); print_r($customer); } catch (Exception $e) { printf($e->__toString()); } //...
创建一个与刚创建的买家相关的订单
在这个例子中,有多个产品,还指定了运费、附加价值和折扣价值。
try { $order = $this->get('moip')->orders()->setOwnId(uniqid()) ->addItem("bicicleta 1",1, "sku1", 10000) ->addItem("bicicleta 2",1, "sku2", 11000) ->addItem("bicicleta 3",1, "sku3", 12000) ->addItem("bicicleta 4",1, "sku4", 13000) ->addItem("bicicleta 5",1, "sku5", 14000) ->addItem("bicicleta 6",1, "sku6", 15000) ->addItem("bicicleta 7",1, "sku7", 16000) ->addItem("bicicleta 8",1, "sku8", 17000) ->addItem("bicicleta 9",1, "sku9", 18000) ->addItem("bicicleta 10",1, "sku10", 19000) ->setShippingAmount(3000)->setAddition(1000)->setDiscount(5000) ->setCustomer($customer) ->create(); print_r($order); } catch (Exception $e) { printf($e->__toString()); }
创建付款
在创建订单后,只需在订单中创建一个付款即可。在这个例子中,我们使用信用卡付款。
try { $payment = $order->payments()->setCreditCard(12, 21, '4073020000000002', '123', $customer) ->execute(); print_r($payment); } catch (Exception $e) { printf($e->__toString()); }