Source code for shoop.testing.simple_checkout_phase
# -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2015, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django import forms
from django.views.generic.edit import FormView
from shoop.front.checkout import (
BasicServiceCheckoutPhaseProvider, CheckoutPhaseViewMixin
)
from .models import CarrierWithCheckoutPhase, PaymentWithCheckoutPhase
[docs]class TestMethodCheckoutPhase(CheckoutPhaseViewMixin, FormView):
template_name = "shoop_testing/simple_checkout_phase.jinja"
data_attribute = None # Override in subclass
storage_identifier = None # Override in subclass
[docs] def get_initial(self):
initial = super(TestMethodCheckoutPhase, self).get_initial()
storage = self.storage.get(self.storage_identifier)
if storage:
initial.update({"input_field": storage.get("input_value")})
return initial
[docs] def is_valid(self):
data = self.storage.get(self.storage_identifier, {})
return bool(data.get("input_value"))
[docs] def process(self):
data = self.storage.get(self.storage_identifier, {})
basket_data = getattr(self.request.basket, self.data_attribute)
basket_data["input_value"] = data.get("input_value")
[docs]class TestPaymentCheckoutPhase(TestMethodCheckoutPhase):
identifier = "test_payment_phase"
title = "Test Payment Phase"
form_class = TestPaymentCheckoutPhaseForm
storage_identifier = "payment_with_checkout_phase"
data_attribute = "payment_data"
[docs]class TestShipmentCheckoutPhase(TestMethodCheckoutPhase):
identifier = "test_shipment_phase"
title = "Test Shipment Phase"
form_class = TestShipmentCheckoutPhaseForm
storage_identifier = "shipment_with_checkout_phase"
data_attribute = "shipping_data"
[docs]class PaymentPhaseProvider(BasicServiceCheckoutPhaseProvider):
phase_class = TestPaymentCheckoutPhase
service_provider_class = PaymentWithCheckoutPhase
[docs]class ShipmentPhaseProvider(BasicServiceCheckoutPhaseProvider):
phase_class = TestShipmentCheckoutPhase
service_provider_class = CarrierWithCheckoutPhase