我已经在Symfony2.3项目中安装了这些用于Paypal集成的捆绑软件。

“ jms / payment-core-bundle”:“ 1.0.*@dev”
“ jms / payment-paypal-bundle”:“ dev-master”

我已遵循此链接http://jmsyst.com/bundles/JMSPaymentPaypalBundle进行配置。我有实体和数据库,但无法获得表单和视图。

我的问题是如何使用这些捆绑包获得付款页面?
有什么形式吗?如果是这样,我怎么能得到它?

最佳答案

您需要付款操作才能呈现具有以下内容的表单:

 * @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));
    }


该代码中的重要部分是创建显示贝宝选项的表单,您可以通过呈现该表单并将其嵌入到付款页面中,然后在付款操作中检查其有效性,然后继续执行该代码。

我现在在当前网站上以不同的方式进行操作,而无需使用默认格式。

给您一些链接,您可以在其中获得更多信息:

http://symfony2.ylly.fr/how-to-set-up-jmspayment-bundle-and-add-the-paypal-plugin-sebastien/

http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage

遗憾的是,JMS官方网站没有提供有关此文件的文档...但是仍然很容易理解它是如何工作的,因此我想这就是他们不打扰的原因。

关于php - Symfony2中的JMS付款核心和付款 Paypal 集成,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29531456/

10-12 06:58