Пример #1
0
 def add_stripe_payment(self, charge):
     assert self.currency == charge['currency'].upper(), "Currency mismatch"
     Money = MoneyMaker(self.currency)
     amount = Money(charge['amount']) / Money.subunits
     OrderPayment.objects.create(
         order=self,
         amount=amount,
         transaction_id=charge['id'],
         payment_method=StripePayment.namespace,
     )
Пример #2
0
 def add_paypal_payment(self, charge):
     transaction = charge['transactions'][0]
     assert self.currency == transaction['amount']['currency'].upper(
     ), "Currency mismatch"
     Money = MoneyMaker(self.currency)
     amount = Money(Decimal(transaction['amount']['total']))
     OrderPayment.objects.create(order=self,
                                 amount=amount,
                                 transaction_id=charge['id'],
                                 payment_method=PayPalPayment.namespace)
Пример #3
0
 def add_mollie_payment(self, payment):
     assert self.currency == payment.amount['currency'], "Currency mismatch"
     Money = MoneyMaker(payment.amount['currency'])
     amount = Money(payment.amount['value'])
     OrderPayment.objects.create(
         order=self,
         amount=amount,
         transaction_id=payment['id'],
         payment_method=MolliePayment.namespace, #always ideal
     )
Пример #4
0
 def get_price(self, request):
     """
     Return the starting price for instances of this smart phone model.
     """
     if not hasattr(self, '_price'):
         if self.variants.exists():
             currency = self.variants.first().unit_price.currency
             aggr = self.variants.aggregate(models.Min('unit_price'))
             self._price = MoneyMaker(currency)(aggr['unit_price__min'])
         else:
             self._price = Money()
     return self._price
Пример #5
0
    def refund_payment(self):
        """
        Refund the payment using Stripe's refunding API.
        """
        Money = MoneyMaker(self.currency)
        filter_kwargs = {
            'transaction_id__startswith': 'ch_',
            'payment_method': StripePayment.namespace,
        }
        for payment in self.orderpayment_set.filter(**filter_kwargs):
            refund = stripe.Refund.create(charge=payment.transaction_id)
            if refund['status'] == 'succeeded':
                amount = Money(refund['amount']) / Money.subunits
                OrderPayment.objects.create(order=self, amount=-amount, transaction_id=refund['id'],
                                            payment_method=StripePayment.namespace)

        del self.amount_paid  # to invalidate the cache
        if self.amount_paid:
            # proceed with other payment service providers
            super(OrderWorkflowMixin, self).refund_payment()
Пример #6
0
import requests

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.utils.translation import ugettext_lazy as _

from shop.money import MoneyMaker
from shop_sendcloud.models import ShippingMethod, ShippingDestination

EUR = MoneyMaker('EUR')


class Command(BaseCommand):
    help = _("Fetch shipping method fees from SendCloud.")
    download_url = 'https://panel.sendcloud.sc/api/v2/shipping_methods'
    credentials = settings.SHOP_SENDCLOUD['API_KEY'], settings.SHOP_SENDCLOUD[
        'API_SECRET']
    INCLUDE_CARRIERES = settings.SHOP_SENDCLOUD.get('INCLUDE_CARRIERES')
    EXCLUDE_CARRIERES = settings.SHOP_SENDCLOUD.get('EXCLUDE_CARRIERES',
                                                    ['sendcloud'])

    def handle(self, verbosity, *args, **options):
        response = requests.get(self.download_url, auth=self.credentials)
        if response.status_code != 200:
            msg = "Failed to import carriers from SendCloud. Reason: {message}"
            raise CommandError(msg.format(**response.json()['error']))
        response_data = response.json()
        for sm in response_data['shipping_methods']:
            if isinstance(self.INCLUDE_CARRIERES, (list, tuple)):
                if sm['carrier'] not in self.INCLUDE_CARRIERES:
                    continue
Пример #7
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from decimal import Decimal

from django.db.utils import OperationalError
from django.utils.translation import ugettext_lazy as _

from shop.modifiers.pool import cart_modifiers_pool
from shop.serializers.cart import ExtraCartRow
from shop.shipping.modifiers import ShippingModifier
from shop.money import MoneyMaker
from shop_sendcloud.models import ShippingMethod, ShippingDestination

EUR = MoneyMaker('EUR')  # at SendCloud, everything is charged in Euros


class SendcloudShippingModifierBase(ShippingModifier):
    carrier = None

    def get_queryset(self):
        return ShippingMethod.objects.filter(carrier=self.carrier)

    def get_choice(self):
        qs = self.get_queryset().order_by('id')
        return (self.identifier, qs.first().name)

    def add_extra_cart_row(self, cart, request):
        if not self.is_active(cart) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1:
            return