php - Symfony2 中的 JMS payment-core 和 payment-paypal 集成

标签 php symfony paypal symfony-forms jmspaymentpaypalbundle

我已经在我的 Symfony2.3 项目中安装了这些用于 paypal 集成的包。

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

我已点击此链接 http://jmsyst.com/bundles/JMSPaymentPaypalBundle用于配置。我获得了实体和数据库,但无法获得表单和 View 。

我的问题是如何使用这些 bundle 获取付款页面? 有什么表格吗?如果是这样,我怎样才能得到它?

最佳答案

你需要一个支付 Action 来渲染一个像这样的表单:

 * @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 选择的表单创建,您可以通过渲染将此表单嵌入您的支付页面,然后在您的支付操作中检查其有效性,然后继续代码。

我现在在我们当前的网站上以不同的方式执行此操作,而不使用默认表单也是可能的。

给你一些链接,你可以获得更多信息:

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 payment-core 和 payment-paypal 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29531456/

相关文章:

Symfony 4 启用使用 Monolog 的 Redis 处理程序进行日志记录

缺少 PAYPAL IPN 自定义字段

php - paypal, php - 将 paypal 支付集成到网站中

ruby-on-rails - 通过 PayPal REST API 进行信用卡支付而不符合 PCI

symfony - 是否可以在 Twig 中创建一个对象?

php - 从我的论坛中获取他们在 medoo 中的子论坛的所有主题

javascript - 将 PHP 代码转换为 Javascript(内爆、打包和解包)

php - PHP 是否具有类似于 .NET 的数据集的结构?

symfony - TWIG:带有变量的字符串翻译?

javascript - 如何在不使用 Google map 的情况下将当前纬度和经度与折线匹配