def get_shipping_cost_kwargs(request, country=None): country_code = request.query_params.get('country_code', None) if country: if country_code is not None: raise utils.InvalidShippingCountry( "Cannot specify country and country_code") country_code = country destination = request.query_params.get('destination', None) if destination: try: destination = models.Address.objects.get(pk=destination) except models.Address.DoesNotExist: raise utils.InvalidShippingDestination("Address not found") elif not country_code: raise utils.InvalidShippingCountry("No country code supplied") if not country_code: country_code = destination.country.pk bid = basket_id(request) option = request.query_params.get('shipping_rate_name', 'standard') settings = Configuration.for_request(request) return dict(country_code=country_code, destination=destination, basket_id=bid, settings=settings, name=option)
def shipping_rate(context, **kwargs): """Return the shipping rate for a country & shipping option name. """ settings = Configuration.for_request(context["request"]) code = kwargs.get('code', None) name = kwargs.get('name', None) return get_shipping_cost(settings, code, name)
def get_context(self): settings = Configuration.for_request(self.request) sales = stats.sales_for_time_period(*stats.current_month()) return { 'total': "{}{}".format(settings.currency_html_code, sum(order.total for order in sales)), 'text': 'In sales this month', 'url': '/admin/orders/order/', 'icon': 'icon-tick' }
def create_payment(self, request, amount, description=''): try: currency = Configuration.for_request(request).currency charge = stripe.Charge.create( amount=int(math.ceil(amount * 100)), # Amount in pence currency=currency.lower(), source=request.POST.get('stripeToken'), description=description ) return charge.id except stripe.error.CardError as error: raise PaymentError(error.user_message) except Exception as e: raise PaymentError('An unexpected error occured, please try again')
def create_payment(self, request, amount, description=''): config = Configuration.for_request(request) nonce = request.POST.get('payment_method_nonce') result = self.gateway.transaction.sale({ "amount": str(amount), "payment_method_nonce": nonce, "merchant_account_id": config.currency, "options": { "paypal": { "description": description } } }) if not result.is_success: raise PaymentError(result.message) return result.transaction.order_id
def currency(request): config = Configuration.for_request(request) return { 'currency_html_code': config.currency_html_code, 'currency': config.currency }