2

我已经集成了捆绑包JMSPaymentCoreBundle及其插件,JMSPaymentPaypalBundle. 然而,第一个捆绑包给出的形式迫使用户选择他/她希望使用的支付方式。就我而言,我没有多种选择,只有 Paypal。遗憾的是,用户仍然需要单击单选按钮以确认他希望使用 Paypal,然后才能被重定向到 Paypal 的站点。我想从流程中删除这一步。

这是我使用的表格:

$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
            'amount'   => $orderPrice,
            'currency' => 'CAD',
            'default_method' => 'payment_paypal', // Optional
            'predefined_data' => array(
                'paypal_express_checkout' => array(
                    'return_url' => $this->router->generate('paiement_complete', array(
                        'id' =>$order->getId()
                    ), true),
                    'cancel_url' => $this->router->generate('paiement_annule', array(), true)
                ),
            ),
        ));

有什么办法可以修改这个表单以删除选择,还是我需要实现一个新表单?

谢谢你。

4

1 回答 1

2

如果您愿意,您可以绕过付款方式选择,直接进行快速结帐(或您想要的方式)。

而不是在类似于以下的操作中显示和接收表单数据:

public function detailsAction(Order $order)
{
    // Your form

    if ('POST' === $this->request->getMethod())
    {
        $form->bindRequest($this->request);

        if ($form->isValid())
        {
            $this->ppc->createPaymentInstruction($instruction = $form->getData());

            $extendedData = $instruction->getExtendedData();

            $extendedData->set(
                'checkout_params', array(
                    'L_PAYMENTREQUEST_0_NAME0' => 'My cool article',
                    'L_PAYMENTREQUEST_0_DESC0' => 'this is a description for my article',
                )
            );

            $order->setPaymentInstruction($instruction);
            $this->em->persist($order);
            $this->em->flush($order);

            return new RedirectResponse($this->router->generate('payment_frontpage'));
         }
      }
}

您可以直接构造支付指令,并在操作中进行Paypal:

/**
 * Paypal Express Checkout
 *
 * @Route("/{orderNumber}/checkout", name="payment_checkout")
 * @Template
 */
public function checkoutAction(Order $order)
{
    $em = $this->get('doctrine.orm.entity_manager');
    $router = $this->get('router');

    // Create the extended data object
    $extendedData = new ExtendedData();

    // Complete payment return URL
    $extendedData->set('return_url',
        $router->generate('payment_complete', array(
            'orderNumber' => $order->getOrderNumber(),
        ), true)
    );

    // Cancel payment return URL
    $extendedData->set('cancel_url',
        $router->generate('payment_cancel', array(
            'orderNumber' => $order->getOrderNumber(),
        ), true)
    );

    // Checkout parameters
    $checkout_params = $this->generateCheckoutParameters($order);
    $this->get('logger')->info(print_r($checkout_params, 1));

    // Add checkout information to the exended data
    $extendedData->set('checkout_params', $checkout_params);

    // Create the payment instruction object
    $instruction = new PaymentInstruction(
        $order->getAmount(), 'EUR', 'paypal_express_checkout', $extendedData
    );

    // Validate and persist the payment instruction
    $this->get('payment.plugin_controller')->createPaymentInstruction($instruction);

    // Update the order object
    $order->setPaymentInstruction($instruction);
    $em->persist($order);
    $em->flush($order);

    // Continue with payment
    return new RedirectResponse($router->generate('payment_complete', array(
        'orderNumber' => $order->getOrderNumber(),
    )));
}

__

protected function generateCheckoutParameters(Order $order)
{
    // Checkout parameters
    $checkout_params = array();

    // Include items data in the order
    foreach ($order->getItems() as $in=>$item)
    {
        $checkout_params = array_merge(
            $checkout_params,
            array(
                sprintf('L_PAYMENTREQUEST_0_NAME%d', $in)   => $item->getName(),
                sprintf('L_PAYMENTREQUEST_0_DESC%d', $in)   => $item->getDescription(),
                sprintf('L_PAYMENTREQUEST_0_AMT%d', $in)    => $item->getPrice(),
                sprintf('L_PAYMENTREQUEST_0_QTY%d', $in)    => 1,
            )
        );
    }

    // Include payments data in the order
    $checkout_params = array_merge(
        $checkout_params,
        array(
            'PAYMENTREQUEST_0_DESC'     => "Order #".$order->getOrderNumber(),
            'PAYMENTREQUEST_0_INVNUM'   => $order->getOrderNumber(),
        )
    );

    return $checkout_params;
}
于 2013-11-10T10:09:43.140 回答