如果您愿意,您可以绕过付款方式选择,直接进行快速结帐(或您想要的方式)。
而不是在类似于以下的操作中显示和接收表单数据:
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;
}