def check_payment_data_is_captured(self, request): # this method only ever gets invoked when visiting checkout:preview # let POST requests through if request.method == 'POST': return # Check to see if payment is actually required for this order. shipping_address = self.get_shipping_address(request.basket) shipping_method = self.get_shipping_method(request.basket, shipping_address) if shipping_method: shipping_charge = shipping_method.calculate(request.basket) else: # It's unusual to get here as a shipping method should be set by # the time this skip-condition is called. In the absence of any # other evidence, we assume the shipping charge is zero. shipping_charge = prices.Price(currency=request.basket.currency, excl_tax=D('0.00'), tax=D('0.00')) total = self.get_order_totals(request.basket, shipping_charge) # bounce requests without a payment method set if not self.checkout_session.payment_method() and total.excl_tax != D( '0.00'): raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), ) # bounce requests which specify a card, # as the CC info only exists on the page and not in the DB if self.checkout_session.payment_method() == 'card': raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), )
def check_a_valid_shipping_address_is_captured(self): # Check that shipping address has been completed if not self.checkout_session.is_shipping_address_set(): raise exceptions.FailedPreCondition( url=reverse('checkout:shipping-address'), message=_("Please choose a shipping address")) # Check that the previously chosen shipping address is still valid shipping_address = self.get_shipping_address( basket=self.request.basket) if not shipping_address and not self.request.basket.custom_ledger: raise exceptions.FailedPreCondition( url=reverse('checkout:shipping-address'), message=_("Your previously chosen shipping address is " "no longer valid. Please choose another one"))
def check_basket_is_valid(self, request): """ Check that the basket is permitted to be submitted as an order. That is, all the basket lines are available to buy - nothing has gone out of stock since it was added to the basket. """ messages = [] strategy = request.strategy for line in request.basket.all_lines(): result = strategy.fetch_for_line(line) is_permitted, reason = result.availability.is_purchase_permitted( line.quantity) if not is_permitted: # Create a more meaningful message to show on the basket page msg = _( "'%(title)s' is no longer available to buy (%(reason)s). " "Please adjust your basket to continue" ) % { 'title': line.product.get_title(), 'reason': reason} messages.append(msg) if messages: raise exceptions.FailedPreCondition( url=reverse('basket:summary'), messages=messages )
def check_basket_is_not_empty(self, request): if request.basket.is_empty: raise exceptions.FailedPreCondition( url=reverse('basket:summary'), message=_( "You need to add some items to your basket to checkout") )
def check_if_checkout_is_active(self, request): msg = 'There isn\'t an active checkout session available.' if not self.checkout_session.system(): messages.error(self.request,msg) raise exceptions.FailedPreCondition( url=reverse('payments:payments-error') )
def check_user_email_is_captured(self, request): if not user_is_authenticated(request.user) \ and not self.checkout_session.get_guest_email(): raise exceptions.FailedPreCondition( url=reverse('checkout:index'), message=_("Please either sign in or enter your email address"))
def check_payment_data_is_captured(self, request): # this method only ever gets invoked when visiting checkout:preview # let POST requests through if request.method == 'POST': return # bounce requests without a payment method set if not self.checkout_session.payment_method(): raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), ) # bounce requests which specify a card, # as the CC info only exists on the page and not in the DB if self.checkout_session.payment_method() == 'card': raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), )
def check_a_valid_shipping_method_is_captured(self): # Check that shipping method has been set if not self.checkout_session.is_shipping_method_set( self.request.basket): raise exceptions.FailedPreCondition( url=reverse('checkout:shipping-method'), message=_("Please choose a shipping method")) # Check that a *valid* shipping method has been set shipping_address = self.get_shipping_address( basket=self.request.basket) shipping_method = self.get_shipping_method( basket=self.request.basket, shipping_address=shipping_address) if not shipping_method: raise exceptions.FailedPreCondition( url=reverse('checkout:shipping-method'), message=_("Your previously chosen shipping method is " "no longer valid. Please choose another one"))
def check_payment_method_is_captured(self, request): """ Precheck for user has chosen payment method if not chosen send to checkout:payment-method page """ if not self.checkout_session.payment_method(): raise exceptions.FailedPreCondition( url=reverse('checkout:payment-method'), message="Пожалуйста выберите метод оплаты")
def check_basket_has_required_quantity(self, request): if request.basket.num_items < settings.OSCAR_MIN_BASKET_QUANTITY_THRESHOLD_WHOLESALE: items_required = settings.OSCAR_MIN_BASKET_QUANTITY_THRESHOLD_WHOLESALE - request.basket.num_items msg = mark_safe( "<b>You need to add %s more item to your basket to checkout.</b>" % items_required) msg_plural = mark_safe( "<b>You need to add %s more items to your basket to checkout.</b>" % items_required) raise exceptions.FailedPreCondition(url=reverse('basket:summary'), message=ungettext_lazy( msg, msg_plural, items_required))
def check_shipping_data_is_captured(self, request): if not request.basket.is_shipping_required(): # Even without shipping being required, we still need to check that # a shipping method code has been set. if not self.checkout_session.is_shipping_method_set( self.request.basket): raise exceptions.FailedPreCondition( url=reverse('checkout:shipping-method'), ) return # Basket requires shipping: check address and method are captured and # valid. self.check_a_valid_shipping_address_is_captured() self.check_a_valid_shipping_method_is_captured()
def check_payment_data_is_captured(self, request): """ Validate that we have a card nonce stored from Square """ # Check to make sure we have a nonce from the payment processor if not self.get_card_nonce(): msg = "We're sorry, we could not contact the payment processor." raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), message=msg) # Run parent function; currently doesn't do anything, but may be # implemented in the future super().check_payment_data_is_captured(request)
def check_payment_data_is_captured(self, request): if request.method != "POST": raise exceptions.FailedPreCondition( url=reverse('checkout:payment-details'), message=_("Please enter your payment details"))