kopia lustrzana https://github.com/longclawshop/longclaw
Fixes unknown field in basket api
rodzic
1cead7642b
commit
edf8260d6b
|
@ -28,7 +28,7 @@ def get_item_count(request):
|
|||
bid = utils.basket_id(request)
|
||||
item = ProductVariant.objects.get(id=request.GET["variant_id"])
|
||||
try:
|
||||
count = BasketItem.objects.get(basket_id=bid, product=item).quantity
|
||||
count = BasketItem.objects.get(basket_id=bid, variant=item).quantity
|
||||
except BasketItem.DoesNotExist:
|
||||
count = 0
|
||||
return Response(data={"quantity": count}, status=status.HTTP_200_OK)
|
||||
|
@ -47,12 +47,12 @@ def add_to_basket(request):
|
|||
# Check if the variant is already in the basket
|
||||
in_basket = False
|
||||
for item in items:
|
||||
if item.product.id == variant.id:
|
||||
if item.variant.id == variant.id:
|
||||
item.increase_quantity(quantity)
|
||||
in_basket = True
|
||||
break
|
||||
if not in_basket:
|
||||
item = BasketItem(product=variant, quantity=quantity, basket_id=bid)
|
||||
item = BasketItem(variant=variant, quantity=quantity, basket_id=bid)
|
||||
item.save()
|
||||
|
||||
items, _ = utils.get_basket_items(request)
|
||||
|
@ -71,7 +71,7 @@ def remove_from_basket(request):
|
|||
variant = ProductVariant.objects.get(id=request.data["variant_id"])
|
||||
quantity = request.data.get("quantity", 1)
|
||||
try:
|
||||
item = BasketItem.objects.get(basket_id=utils.basket_id(request), product=variant)
|
||||
item = BasketItem.objects.get(basket_id=utils.basket_id(request), variant=variant)
|
||||
except BasketItem.DoesNotExist:
|
||||
return Response(data={"message": "Item does not exist in cart"},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
|
|
@ -7,5 +7,5 @@ DEFAULT_SHIPPING_ENABLED = getattr(settings, 'DEFAULT_SHIPPING_ENABLED', True)
|
|||
|
||||
PAYMENT_GATEWAY = getattr(settings,
|
||||
'PAYMENT_GATEWAY',
|
||||
'longclaw.checkout.gateways.BraintreePayment')
|
||||
'longclaw.checkout.gateways.BasePayment')
|
||||
CURRENCY = getattr(settings, "CURRENCY", "GBP")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
'''
|
||||
Gateways module to hold payment processor backend logic
|
||||
'''
|
||||
from longclaw.checkout.gateways.base import BasePayment
|
||||
from longclaw.checkout.gateways.braintree_payment import BraintreePayment, PaypalVZeroPayment
|
||||
from longclaw.checkout.gateways.stripe_payment import StripePayment
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
from django.conf import settings
|
||||
import braintree
|
||||
from longclaw.checkout import app_settings
|
||||
from longclaw.checkout.utils import PaymentError
|
||||
|
||||
class BasePayment():
|
||||
'''
|
||||
Provides the interface for payment backends and
|
||||
can function as a dummy backend for testing.
|
||||
'''
|
||||
|
||||
def create_payment(self, request, amount):
|
||||
'''
|
||||
Dummy function for creating a payment through a payment gateway.
|
||||
Should be overridden in gateway implementations.
|
||||
Can be used for testing - to simulate a failed payment/error,
|
||||
pass `error: true` in the request data.
|
||||
'''
|
||||
err = request.data.get("error", False)
|
||||
if err:
|
||||
raise PaymentError("Dummy error requested")
|
||||
|
||||
def get_token(self, request):
|
||||
'''
|
||||
Dummy function for generating a client token through
|
||||
a payment gateway. Most (all?) gateways have a flow which
|
||||
involves requesting a token from the server (usually to
|
||||
tokenize the payment method) and then passing that token
|
||||
to another api endpoint to create the payment.
|
||||
|
||||
This function should be overriden in child classes
|
||||
'''
|
||||
return 'dummy_token'
|
|
@ -2,8 +2,9 @@ from django.conf import settings
|
|||
import braintree
|
||||
from longclaw.checkout import app_settings
|
||||
from longclaw.checkout.utils import PaymentError
|
||||
from longclaw.checkout.gateways import BasePayment
|
||||
|
||||
class BraintreePayment():
|
||||
class BraintreePayment(BasePayment):
|
||||
'''
|
||||
Create a payment using Braintree
|
||||
'''
|
||||
|
|
|
@ -3,9 +3,10 @@ from django.conf import settings
|
|||
import stripe
|
||||
from longclaw.checkout.app_settings import CURRENCY
|
||||
from longclaw.checkout.utils import PaymentError
|
||||
from longclaw.checkout.gateways import BasePayment
|
||||
|
||||
|
||||
class StripePayment():
|
||||
class StripePayment(BasePayment):
|
||||
'''
|
||||
Create a payment using stripe
|
||||
'''
|
||||
|
|
Ładowanie…
Reference in New Issue