Projet

Général

Profil

0003-lingo-use-payment-backend-s-slug-in-default-callback.patch

Benjamin Dauvergne, 10 mai 2021 13:16

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH 3/3] lingo: use payment backend's slug in default callback URL
 (#49145)

 combo/apps/lingo/models.py  | 6 ++++--
 combo/apps/lingo/urls.py    | 2 +-
 tests/test_lingo_manager.py | 4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)
combo/apps/lingo/models.py
145 145
class PaymentBackend(models.Model):
146 146
    label = models.CharField(verbose_name=_('Label'), max_length=64)
147 147
    slug = models.SlugField(
148
        unique=True, verbose_name=_('Identifier'), help_text=_('The identifier is used in webservice calls.')
148
        unique=True,
149
        verbose_name=_('Identifier'),
150
        help_text=_('The identifier is used in webservice calls and callback URLs for the payment backend.'),
149 151
    )
150 152
    service = models.CharField(verbose_name=_('Payment Service'), max_length=64, choices=SERVICES)
151 153
    service_options = JSONField(blank=True, verbose_name=_('Payment Service Options'))
......
279 281

  
280 282
    @property
281 283
    def callback_url(self):
282
        return reverse('lingo-callback-payment-backend', kwargs={'payment_backend_pk': self.pk})
284
        return reverse('lingo-callback-payment-backend', kwargs={'payment_backend_pk': self.slug})
283 285

  
284 286

  
285 287
@python_2_unicode_compatible
combo/apps/lingo/urls.py
100 100
    url(r'^lingo/cancel/(?P<pk>\w+)/$', CancelItemView.as_view(), name='lingo-cancel-item'),
101 101
    url(r'^lingo/callback/(?P<regie_pk>\w+)/$', CallbackView.as_view(), name='lingo-callback'),
102 102
    url(
103
        r'^lingo/callback-payment-backend/(?P<payment_backend_pk>\w+)/$',
103
        r'^lingo/callback-payment-backend/(?P<payment_backend_pk>[A-Za-z0-9_-]+)/$',
104 104
        CallbackView.as_view(),
105 105
        name='lingo-callback-payment-backend',
106 106
    ),
tests/test_lingo_manager.py
72 72

  
73 73
    # callback URL is shown
74 74
    assert 'Callback URL' in resp
75
    assert 'http://testserver/lingo/callback-payment-backend/%s/' % payment_backend.pk in resp
75
    assert 'http://testserver/lingo/callback-payment-backend/%s/' % payment_backend.slug in resp
76 76

  
77 77
    resp.forms[0]['description'] = 'other description'
78 78
    resp = resp.forms[0].submit()
......
639 639

  
640 640
    # callback URL is shown
641 641
    assert 'Callback URL' in resp
642
    assert 'http://testserver/lingo/callback-payment-backend/%s' % payment_backend.pk in resp
642
    assert 'http://testserver/lingo/callback-payment-backend/%s' % payment_backend.slug in resp
643 643

  
644 644
    # service cannot be changed
645 645
    assert 'disabled' in resp.form['service'].attrs
646
-