public function getCheckouts(Customweb_Payment_ExternalCheckout_IContext $context)
 {
     $checkouts = $this->getCheckoutsUnfiltered();
     $result = array();
     foreach ($checkouts as $checkout) {
         if ($checkout->isActive() && $checkout->checkMinimalOrderTotal($context->getOrderAmountInDecimals()) && $checkout->checkMaximalOrderTotal($context->getOrderAmountInDecimals())) {
             $result[] = $checkout;
         }
     }
     return $result;
 }
 protected function checkContextCompleteness(Customweb_Payment_ExternalCheckout_IContext $context)
 {
     Customweb_Core_Assert::notNull($context->getBillingAddress(), "The context must contain a billing address, before it can be COMPLETED.");
     Customweb_Core_Assert::notNull($context->getShippingAddress(), "The context must contain a shipping address, before it can be COMPLETED. You may use the billing address when no shipping address is present.");
     Customweb_Core_Assert::hasLength($context->getShippingMethodName(), "The context must contain a shipping method name, before it can be COMPLETED.");
     Customweb_Core_Assert::notNull($context->getBillingAddress(), "The context must contain a billing address, before it can be COMPLETED.");
     Customweb_Core_Assert::hasSize($context->getInvoiceItems(), "At least one line item must be added before it can be COMPLETED.");
     Customweb_Core_Assert::hasLength($context->getCustomerEmailAddress(), "The context must contain an e-mail address before it can be COMPLETED.");
 }
 private function createTransactionContextFromContext(Customweb_Payment_ExternalCheckout_IContext $context)
 {
     if (!$context instanceof Customweb_SaferpayCw_Model_ExternalCheckoutContext) {
         throw new Customweb_Core_Exception_CastException('Customweb_SaferpayCw_Model_ExternalCheckoutContext');
     }
     $this->redirectOnEmptyBasket();
     $quote = $context->getQuote();
     $quote->collectTotals()->save();
     $isNewCustomer = false;
     switch ($context->getRegisterMethod()) {
         case 'guest':
             $this->prepareGuestQuote($context);
             break;
         case 'register':
             $this->prepareNewCustomerQuote($context);
             $isNewCustomer = true;
             break;
         default:
             $this->prepareCustomerQuote($context);
             break;
     }
     $quote->getBillingAddress()->setShouldIgnoreValidation(true);
     $quote->getShippingAddress()->setShouldIgnoreValidation(true);
     $service = Mage::getModel('sales/service_quote', $quote);
     $service->submitAll();
     if ($isNewCustomer) {
         try {
             $this->involveNewCustomer($context);
         } catch (Exception $e) {
             Mage::helper('SaferpayCw')->logException($e);
         }
     }
     Mage::getSingleton('checkout/session')->setLastQuoteId($quote->getId())->setLastSuccessQuoteId($quote->getId())->clearHelperData();
     $order = $service->getOrder();
     Mage::getSingleton('checkout/session')->setLastOrderId($order->getId())->setRedirectUrl(false)->setLastRealOrderId($order->getIncrementId());
     $transaction = Mage::getModel('saferpaycw/transaction');
     $transaction->setOrderId($order->getId());
     $transaction->setOrderPaymentId($order->getPayment()->getId());
     $transaction->save();
     return $context->getPaymentMethod()->getTransactionContext($order, $transaction);
 }