lingo: use payment backend's slug in default callback URL (#49145)

This commit is contained in:
Benjamin Dauvergne 2021-05-06 17:45:56 +02:00
parent a8676ab897
commit 1822b1f3c7
3 changed files with 7 additions and 5 deletions

View File

@ -145,7 +145,9 @@ class PaymentBackendManager(models.Manager):
class PaymentBackend(models.Model):
label = models.CharField(verbose_name=_('Label'), max_length=64)
slug = models.SlugField(
unique=True, verbose_name=_('Identifier'), help_text=_('The identifier is used in webservice calls.')
unique=True,
verbose_name=_('Identifier'),
help_text=_('The identifier is used in webservice calls and callback URLs for the payment backend.'),
)
service = models.CharField(verbose_name=_('Payment Service'), max_length=64, choices=SERVICES)
service_options = JSONField(blank=True, verbose_name=_('Payment Service Options'))
@ -279,7 +281,7 @@ class PaymentBackend(models.Model):
@property
def callback_url(self):
return reverse('lingo-callback-payment-backend', kwargs={'payment_backend_pk': self.pk})
return reverse('lingo-callback-payment-backend', kwargs={'payment_backend_pk': self.slug})
@python_2_unicode_compatible

View File

@ -100,7 +100,7 @@ urlpatterns = [
url(r'^lingo/cancel/(?P<pk>\w+)/$', CancelItemView.as_view(), name='lingo-cancel-item'),
url(r'^lingo/callback/(?P<regie_pk>\w+)/$', CallbackView.as_view(), name='lingo-callback'),
url(
r'^lingo/callback-payment-backend/(?P<payment_backend_pk>\w+)/$',
r'^lingo/callback-payment-backend/(?P<payment_backend_pk>[A-Za-z0-9_-]+)/$',
CallbackView.as_view(),
name='lingo-callback-payment-backend',
),

View File

@ -72,7 +72,7 @@ def test_edit_regie(app, admin_user, payment_backend):
# callback URL is shown
assert 'Callback URL' in resp
assert 'http://testserver/lingo/callback-payment-backend/%s/' % payment_backend.pk in resp
assert 'http://testserver/lingo/callback-payment-backend/%s/' % payment_backend.slug in resp
resp.forms[0]['description'] = 'other description'
resp = resp.forms[0].submit()
@ -639,7 +639,7 @@ def test_edit_payment_backend(app, admin_user):
# callback URL is shown
assert 'Callback URL' in resp
assert 'http://testserver/lingo/callback-payment-backend/%s' % payment_backend.pk in resp
assert 'http://testserver/lingo/callback-payment-backend/%s' % payment_backend.slug in resp
# service cannot be changed
assert 'disabled' in resp.form['service'].attrs