如果您願意,可以跳過付款方式,直接直接進行快速結賬(或您想要的方式)。
相反表示,並以類似於該一個動作接收形式的數據:
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 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;
}
非常感謝。我只是想指出,我確實需要更改線$ '$ em-> flush();' 到 '$ em-> flush($ order);' – wrenchimp
快速的問題。如果我在訂單上打折,那麼結帳參數似乎有問題。在這種情況下是否有特定的參數? – wrenchimp