mirror of
https://github.com/pretix/pretix.git
synced 2026-08-23 12:51:59 +00:00
PayPal: Fix support for CLP
This commit is contained in:
@@ -3,9 +3,9 @@ from decimal import ROUND_HALF_UP, Decimal
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
def round_decimal(dec, currency=None):
|
def round_decimal(dec, currency=None, places_dict=settings.CURRENCY_PLACES):
|
||||||
if currency:
|
if currency:
|
||||||
places = settings.CURRENCY_PLACES.get(currency, 2)
|
places = places_dict.get(currency, 2)
|
||||||
return Decimal(dec).quantize(
|
return Decimal(dec).quantize(
|
||||||
Decimal('1') / 10 ** places, ROUND_HALF_UP
|
Decimal('1') / 10 ** places, ROUND_HALF_UP
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from django.core import signing
|
|||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils.translation import ugettext as __, ugettext_lazy as _
|
from django.utils.translation import ugettext as __, ugettext_lazy as _
|
||||||
|
|
||||||
|
from pretix.base.decimal import round_decimal
|
||||||
from pretix.base.models import Order, Quota, RequiredAction
|
from pretix.base.models import Order, Quota, RequiredAction
|
||||||
from pretix.base.payment import BasePaymentProvider, PaymentException
|
from pretix.base.payment import BasePaymentProvider, PaymentException
|
||||||
from pretix.base.services.mail import SendMailException
|
from pretix.base.services.mail import SendMailException
|
||||||
@@ -117,14 +118,14 @@ class Paypal(BasePaymentProvider):
|
|||||||
{
|
{
|
||||||
"name": __('Order for %s') % str(request.event),
|
"name": __('Order for %s') % str(request.event),
|
||||||
"quantity": 1,
|
"quantity": 1,
|
||||||
"price": str(cart['total']),
|
"price": self.format_price(cart['total']),
|
||||||
"currency": request.event.currency
|
"currency": request.event.currency
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"amount": {
|
"amount": {
|
||||||
"currency": request.event.currency,
|
"currency": request.event.currency,
|
||||||
"total": str(cart['total'])
|
"total": self.format_price(cart['total'])
|
||||||
},
|
},
|
||||||
"description": __('Event tickets for {event}').format(event=request.event.name)
|
"description": __('Event tickets for {event}').format(event=request.event.name)
|
||||||
}
|
}
|
||||||
@@ -133,6 +134,34 @@ class Paypal(BasePaymentProvider):
|
|||||||
request.session['payment_paypal_order'] = None
|
request.session['payment_paypal_order'] = None
|
||||||
return self._create_payment(request, payment)
|
return self._create_payment(request, payment)
|
||||||
|
|
||||||
|
def format_price(self, value):
|
||||||
|
return str(round_decimal(value, self.event.currency, {
|
||||||
|
# PayPal behaves differently than Stripe in deciding what currencies have decimal places
|
||||||
|
# Source https://developer.paypal.com/docs/classic/api/currency_codes/
|
||||||
|
'HUF': 0,
|
||||||
|
'JPY': 0,
|
||||||
|
'MYR': 0,
|
||||||
|
'TWD': 0,
|
||||||
|
# However, CLPs are not listed there while PayPal requires us not to send decimal places there. WTF.
|
||||||
|
'CLP': 0,
|
||||||
|
# Let's just guess that the ones listed here are 0-based as well
|
||||||
|
# https://developers.braintreepayments.com/reference/general/currencies
|
||||||
|
'BIF': 0,
|
||||||
|
'DJF': 0,
|
||||||
|
'GNF': 0,
|
||||||
|
'KMF': 0,
|
||||||
|
'KRW': 0,
|
||||||
|
'LAK': 0,
|
||||||
|
'PYG': 0,
|
||||||
|
'RWF': 0,
|
||||||
|
'UGX': 0,
|
||||||
|
'VND': 0,
|
||||||
|
'VUV': 0,
|
||||||
|
'XAF': 0,
|
||||||
|
'XOF': 0,
|
||||||
|
'XPF': 0,
|
||||||
|
}))
|
||||||
|
|
||||||
def _create_payment(self, request, payment):
|
def _create_payment(self, request, payment):
|
||||||
try:
|
try:
|
||||||
if payment.create():
|
if payment.create():
|
||||||
@@ -207,7 +236,7 @@ class Paypal(BasePaymentProvider):
|
|||||||
{
|
{
|
||||||
"name": __('Order {slug}-{code}').format(slug=self.event.slug.upper(), code=order.code),
|
"name": __('Order {slug}-{code}').format(slug=self.event.slug.upper(), code=order.code),
|
||||||
"quantity": 1,
|
"quantity": 1,
|
||||||
"price": str(order.total),
|
"price": self.format_price(order.total),
|
||||||
"currency": order.event.currency
|
"currency": order.event.currency
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -351,14 +380,14 @@ class Paypal(BasePaymentProvider):
|
|||||||
{
|
{
|
||||||
"name": __('Order {slug}-{code}').format(slug=self.event.slug.upper(), code=order.code),
|
"name": __('Order {slug}-{code}').format(slug=self.event.slug.upper(), code=order.code),
|
||||||
"quantity": 1,
|
"quantity": 1,
|
||||||
"price": str(order.total),
|
"price": self.format_price(order.total),
|
||||||
"currency": order.event.currency
|
"currency": order.event.currency
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"amount": {
|
"amount": {
|
||||||
"currency": request.event.currency,
|
"currency": request.event.currency,
|
||||||
"total": str(order.total)
|
"total": self.format_price(order.total)
|
||||||
},
|
},
|
||||||
"description": __('Order {order} for {event}').format(
|
"description": __('Order {order} for {event}').format(
|
||||||
event=request.event.name,
|
event=request.event.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user