cmdconfig / robokassa-bundle
为symfony2提供的robokassa支持
dev-master
2018-04-16 15:01 UTC
Requires
- php: >=5.3.2
- symfony/form: ~2.1
- symfony/framework-bundle: ~2.1
- twig/twig: ~1.5
This package is not auto-updated.
Last update: 2024-10-02 08:26:31 UTC
README
当前版本仅支持POST方法
安装
php composer.phar require jh9/robokassa-bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new jh9\RobokassaBundle\jh9RobokassaBundle(), ); }
# app/config/config.yml jh9_robokassa: login: %login% password1: %password1% password2: %password2% test: %test% # default to true
用法
在你的模板中(生成“支付”按钮)
#pay_order.html.twig {{ jh9_robokassa_form(order.id, order.price {# (optional) , { "template": "jh9RobokassaBundle:Twig:payForm.html.twig", {# default #} "Desc": "my description", {# default null #} "IncCurrLabel": "WMZM", {# default null #} "Encoding": "utf-8" {# default #} } #} ) }}
在你的结果操作中
/** * @Route("/ResultUrl") * @Methods({"POST"}) */ public function resultAction(Request $request) { $manager = $this->get('jh9.robokassa.manager'); $result = $manager->handleResult($request); if ($result->isValid()) { // ... // your success logic, such as set your order as paid /* $em = $this->get('doctrine.orm.default_entity_manager'); $order = $em->find('jh9ShopProductBundle:Order', $result->getInvId()); if (! $order) { return $this->createNotFoundException(); } $order->setStatus(OrderTypes::STATUS_PAYED); */ return new Response(); } else { return new Response('Not valid', 500); } }
在你的成功操作中你可以做
/** * @Route("/SuccessUrl") * @Methods({"POST"}) */ public function robokassaSuccessAction(Request $request) { $manager = $this->get('jh9.robokassa.manager'); $payResult = $manager->handleSuccess($request); if (! $payResult->isValid()) { return new Response('not valid', 400); } return new Response( "Your order with id = " . $payResult->getInvId() . " is paid" . " , amount = " $payResult->getOutSum() . " your language is" . $payResult->getCulture() ); }
在你的失败操作中
/** * @Route("/payment/fail") * @Methods({"POST"}) */ public function robokassaFailAction(Request $request) { $payResult = $this->get('jh9.robokassa.manager')->handleFail($request); return new Response( " Your order with id " . $payResult->getInvId() . " is not paid" . " amount: " . $payResult->getOutSum() ); }
模板
要重写默认模板,请将您自己的模板放置到 app/Resources/jh9RobokassaBundle/views/Twig/payForm.html.twig
# app/Resources/jh9RobokassaBundle/views/Twig/payForm.html.twig {{ form_start(form) }} {{ form_widget(form) }} <div> <button type="submit" class="btn btn-primary"> ROBOKASSA </button> </div> {{ form_end(form) }}
或在robokassa表单调用中设置'template'选项
{{ jh9_robokassa_form( order.id, order.price, { 'template': "AcmeBundle:RobokassaTemplate:myTemplate.html.twig } }}