PPv2: Limit description and custom_id to 127 chars (Z#23101013)

This commit is contained in:
Martin Gross
2022-06-07 09:39:32 +02:00
parent 0dfef2699f
commit 2d3cd8f3dc
2 changed files with 22 additions and 18 deletions
+20 -18
View File
@@ -548,8 +548,8 @@ class PaypalMethod(BasePaymentProvider):
'value': value, 'value': value,
}, },
'payee': payee, 'payee': payee,
'description': description, 'description': description[:127],
'custom_id': custom_id, 'custom_id': custom_id[:127],
# 'shipping': {}, # Include Shipping information? # 'shipping': {}, # Include Shipping information?
}], }],
'application_context': { 'application_context': {
@@ -610,31 +610,33 @@ class PaypalMethod(BasePaymentProvider):
if pp_captured_order.status == 'APPROVED': if pp_captured_order.status == 'APPROVED':
try: try:
custom_id = '{prefix}{orderstring}{postfix}'.format(
prefix='{} '.format(self.settings.prefix) if self.settings.prefix else '',
orderstring=__('Order {slug}-{code}').format(
slug=self.event.slug.upper(),
code=payment.order.code
),
postfix=' {}'.format(self.settings.postfix) if self.settings.postfix else ''
)
description = '{prefix}{orderstring}{postfix}'.format(
prefix='{} '.format(self.settings.prefix) if self.settings.prefix else '',
orderstring=__('Order {order} for {event}').format(
event=request.event.name,
order=payment.order.code
),
postfix=' {}'.format(self.settings.postfix) if self.settings.postfix else ''
)
patchreq = OrdersPatchRequest(pp_captured_order.id) patchreq = OrdersPatchRequest(pp_captured_order.id)
patchreq.request_body([ patchreq.request_body([
{ {
"op": "replace", "op": "replace",
"path": "/purchase_units/@reference_id=='default'/custom_id", "path": "/purchase_units/@reference_id=='default'/custom_id",
"value": '{prefix}{orderstring}{postfix}'.format( "value": custom_id[:127],
prefix='{} '.format(self.settings.prefix) if self.settings.prefix else '',
orderstring=__('Order {slug}-{code}').format(
slug=self.event.slug.upper(),
code=payment.order.code
),
postfix=' {}'.format(self.settings.postfix) if self.settings.postfix else ''
),
}, },
{ {
"op": "replace", "op": "replace",
"path": "/purchase_units/@reference_id=='default'/description", "path": "/purchase_units/@reference_id=='default'/description",
"value": '{prefix}{orderstring}{postfix}'.format( "value": description[:127],
prefix='{} '.format(self.settings.prefix) if self.settings.prefix else '',
orderstring=__('Order {order} for {event}').format(
event=request.event.name,
order=payment.order.code
),
postfix=' {}'.format(self.settings.postfix) if self.settings.postfix else ''
),
} }
]) ])
self.client.execute(patchreq) self.client.execute(patchreq)
@@ -70,6 +70,7 @@ var pretixpaypal = {
pretixpaypal.paypage = Boolean($('#paypal-button-container').data('paypage')); pretixpaypal.paypage = Boolean($('#paypal-button-container').data('paypage'));
pretixpaypal.order_id = $.trim($("#paypal_oid").html()); pretixpaypal.order_id = $.trim($("#paypal_oid").html());
pretixpaypal.currency = $("body").attr("data-currency"); pretixpaypal.currency = $("body").attr("data-currency");
pretixpaypal.locale = $("body").attr("data-locale") + "_" + $("body").attr("data-datetimelocale").toUpperCase();
} }
pretixpaypal.continue_button.prop("disabled", true); pretixpaypal.continue_button.prop("disabled", true);
@@ -82,6 +83,7 @@ var pretixpaypal = {
'?client-id=' + pretixpaypal.client_id + '?client-id=' + pretixpaypal.client_id +
'&components=buttons,funding-eligibility' + '&components=buttons,funding-eligibility' +
'&currency=' + pretixpaypal.currency; '&currency=' + pretixpaypal.currency;
//'&locale=' + pretixpaypal.locale;
if (pretixpaypal.merchant_id) { if (pretixpaypal.merchant_id) {
sdk_url += '&merchant-id=' + pretixpaypal.merchant_id; sdk_url += '&merchant-id=' + pretixpaypal.merchant_id;