我已经在我的Symfony2.3项目中为paypal集成安装了这些软件包。
" jms / payment-core-bundle":" 1.0。* @ dev" " jms / payment-paypal-bundle":" dev-master"
我已按照此链接http://jmsyst.com/bundles/JMSPaymentPaypalBundle进行配置。我有实体和数据库,但我无法获得表单和视图。
我的问题是如何使用这些捆绑包获取付款页面? 那有什么形式吗?如果是这样,我怎么能得到它?
答案 0 :(得分:1)
您需要付款操作才能使用以下内容呈现表单:
* @Route("/{id}", name="paiement")
* @Template()
*/
public function paymentAction($id=0) // this is a personnal ID i pass to the controler to identify the previous shopping cart
{
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $order->getPrice(),
'currency' => 'EUR',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array()
));
if ('POST' === $this->request->getMethod()) {
$form->bindRequest($this->request);
$order = new Order();
$this->em->persist( $order);
$this->em->flush( $order);
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $order->getPrice(),
'currency' => 'EUR',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->router->generate('payment_complete', array(
'id' =>$order->getId()
), true),
'cancel_url' => $this->router->generate('payment_cancel', array(
'id' => $order->getId()
), true)
),
),
));
$form->bindRequest($this->request);
// Once the Form is validate, you update the order with payment instruction
if ($form->isValid()) {
$instruction = $form->getData();
$this->ppc->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$this->em->persist($order);
$this->em->flush($order);
// now, let's redirect to payment_complete with the order id
return new RedirectResponse($this->router->generate('payment_complete', array('id' => $order->getId() )));
}
}
return $this->render('YourBundle:Paiement:paymentChooseTemplate.html.twig',array('form' => $form->createView() , 'id' => $id));
}
此代码中的重要部分是表单创建,它显示了PayPal的选择,您可以通过呈现它,然后在付款操作中检查其有效性,将此表单嵌入您的付款页面,然后继续执行代码。< / p>
我现在在不使用默认表格的情况下现在这样做的方式不同。
给你一些链接,你可以获得更多信息:
http://symfony2.ylly.fr/how-to-set-up-jmspayment-bundle-and-add-the-paypal-plugin-sebastien/
http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage
令人遗憾的是官方JMS网站有关于此的文档......但仍然很容易理解它是如何工作的,所以我想这就是为什么他们没有打扰。