Reputation: 4392
I'm currently creating a checkout page in Magento based on "One Page Checkout" - or well, I emptied onepage.phtml and started from scratch.
The order gets placed and everything, but the user is never coming to the third-party payment page; some payment methods return a blank page while other returns the error code "Error in Klarna::setConfig: Missing config field(s): secret".
I suspect that some missing JavaScript is involved, so my final question is: Is it possible to make the checkout work without JavaScript and, in that case, how?
If relevant, here is the PHP code I use to create the order (placed in the top of onepage.phtml).
<?php
$checkout = Mage::getSingleton('checkout/type_onepage');
//STEP(1)
$checkout->saveCheckoutMethod('guest');
//STEP(2)
$checkout->saveBilling($_POST['billing'], false);
//STEP(3)
$checkout->saveShipping($_POST, false);
//STEP(4)
$checkout->saveShippingMethod('flatrate_flatrate');
//STEP(5)
$checkout->savePayment($_POST['payment']);
//STEP(6)
$checkout->saveOrder();
?>
Thank you in advance!
Upvotes: 0
Views: 1719
Reputation: 5390
Yes you can place order without any JS. For supporting payment methods with some redirect url after savePayment method you must add this lines:
$redirectUrl = $checkout->getQuote()
->getPayment()
->getCheckoutRedirectUrl();
if ($redirectUrl) {
return $this->getResponse()->setRedirect($redirectUrl);
}
and after saveOrder add this:
$redirectUrl = $checkout->getRedirectUrl();
if ($redirectUrl) {
$this->_redirect($redirectUrl);
}
Also you must use try {...} catch () { ...} block for error handling:
try {
$checkout = Mage::getSingleton('checkout/type_onepage');
//STEP(1)
$checkout->saveCheckoutMethod('guest');
//STEP(2)
$checkout->saveBilling($_POST['billing'], false);
//STEP(3)
$checkout->saveShipping($_POST, false);
//STEP(4)
$checkout->saveShippingMethod('flatrate_flatrate');
//STEP(5)
$checkout->savePayment($_POST['payment']);
//STEP(6)
$checkout->saveOrder();
} catch (Mage_Core_Exception $e) {
Mage::getSingleton('checkout/session')->addError($e->getMessage());
} catch (Exception $e) {
Mage::logException($e);
Mage::getSingleton('checkout/session')->addError(Mage::helper('checkout')->__('Unable to process your order. Please try again later'));
}
Upvotes: 1