我正在尝试实现JSMPayment和EtspaymentogOneBundle,而无需成功。
我会收到错误:" 控制器必须返回响应"。我同意这一点,但文档中写得这一点。所以我有些不对还是文档中的错误/错误。
错误可能是此错误,但它是在Doc ...
中写的。return array(
'form' => $form->createView()
);
现在,如果我更改此行并返回到树枝模板,我只会获取一个广播按钮。为什么?
任何帮助都会对我有很大帮助,因为我真的迷路了。
我的所有控制器
/**
*
*/
class PaymentController extends Controller
{
/** @DIInject */
private $request;
/** @DIInject */
private $router;
/** @DIInject("doctrine.orm.entity_manager") */
private $em;
/** @DIInject("payment.plugin_controller") */
private $ppc;
/**
*
* @param CTCBundleOrderBundleControllerOrder $order
* @return RedirectResponse
*/
public function detailsAction(Order $order, Request $request)
{
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $order->getPackage()->getAmount(),
'currency' => 'EUR',
'default_method' => 'ogone_gateway', // Optional
'predefined_data' => array(
'ogone_gateway' => array(
'tp' => '', // Optional
'PM' => $pm, // Optional - Example value: "CreditCard" - Note: You can consult the list of PM values on Ogone documentation
'BRAND' => $brand, // Optional - Example value: "VISA" - Note: If you send the BRAND field without sending a value in the PM field (‘CreditCard’ or ‘Purchasing Card’), the BRAND value will not be taken into account.
'CN' => $billingAddress->getFullName(), // Optional
'EMAIL' => $this->getUser()->getEmail(), // Optional
'OWNERZIP' => $billingAddress->getPostalCode(), // Optional
'OWNERADDRESS' => $billingAddress->getStreetLine(), // Optional
'OWNERCTY' => $billingAddress->getCountry()->getName(), // Optional
'OWNERTOWN' => $billingAddress->getCity(), // Optional
'OWNERTELNO' => $billingAddress->getPhoneNumber(), // Optional
'lang' => $request->getLocale(), // 5 characters maximum, for e.g: fr_FR
'ORDERID' => '123456', // Optional, 30 characters maximum
),
),
));
if ('POST' === $this->request->getMethod()) {
$form->bindRequest($this->request);
if ($form->isValid()) {
$this->ppc->createPaymentInstruction($instruction = $form->getData());
$order->setPaymentInstruction($instruction);
$this->em->persist($order);
$this->em->flush($order);
return new RedirectResponse($this->router->generate('payment_complete', array(
'orderNumber' => $order->getOrderNumber(),
)));
}
}
return array(
'form' => $form->createView()
);
}
/**
*
*/
public function completeAction(Order $order)
{
$instruction = $order->getPaymentInstruction();
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}
$result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();
if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();
if ($action instanceof VisitUrl) {
return new RedirectResponse($action->getUrl());
}
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}
// payment was successful, do something interesting with the order
}
public function cancelAction(Order $order)
{
die('cancel the payment');
}
/** @DILookupMethod("form.factory") */
protected function getFormFactory() { }
}
如果使用
return array(
'form' => $form->createView()
);
在控制器上,您应该将@Template注释添加到控制器操作
use SensioBundleFrameworkExtraBundleConfigurationTemplate;
class PaymentController extends Controller
{
...
/**
*
* @param CTCBundleOrderBundleControllerOrder $order
* @Template()
* @return RedirectResponse
*/
public function detailsAction(Order $order, Request $request)
或您应该用模板返回"渲染"
return $this->render('MyAppSomeBundle:Payment:details.html.twig', array( 'form' => $form->createView());