lingo: pass extra item info to eopayment backend (#42992)
This commit is contained in:
parent
1bdc236839
commit
1c0c36583e
|
@ -398,6 +398,16 @@ class PayMixin(object):
|
|||
kwargs = {
|
||||
'email': email, 'first_name': firstname, 'last_name': lastname
|
||||
}
|
||||
kwargs['merchant_name'] = settings.TEMPLATE_VARS.get('global_title') or 'Compte Citoyen'
|
||||
kwargs['items_info'] = []
|
||||
for item in remote_items or items:
|
||||
kwargs['items_info'].append({
|
||||
'text': item.subject,
|
||||
'amount': item.amount,
|
||||
'reference_id': item.reference_id,
|
||||
})
|
||||
if not email and item.email:
|
||||
kwargs['email'] = item.email
|
||||
if items:
|
||||
capture_date = items[0].capture_date
|
||||
if capture_date:
|
||||
|
|
|
@ -392,9 +392,63 @@ def test_basket_item_with_capture_date(app, user, user_name_id, regie, basket_pa
|
|||
location = urlparse.urlparse(resp.location)
|
||||
assert location.path == '/'
|
||||
assert location.hostname == 'dummy-payment.demo.entrouvert.com'
|
||||
|
||||
items_info = [{'text': 'test item', 'amount': Decimal('10.00'), 'reference_id': ''}]
|
||||
eopayment_mock.assert_called_once_with(
|
||||
Decimal(10), email=user.email, first_name=user.first_name, last_name=user.last_name,
|
||||
capture_date=capture_date)
|
||||
capture_date=capture_date, merchant_name='Compte Citoyen', items_info=items_info
|
||||
)
|
||||
|
||||
|
||||
def test_basket_items_extra_info(app, user, user_name_id, regie, basket_page, monkeypatch):
|
||||
url = '%s?NameId=%s' % (reverse('api-add-basket-item'), user_name_id)
|
||||
items_info = [{'text': 'face mask', 'amount': Decimal(10), 'reference_id': '1'},
|
||||
{'text': 'face mask 2', 'amount': Decimal(15), 'reference_id': '2'}]
|
||||
items_post_data = [{'display_name': 'face mask', 'amount': 10, 'reference_id': 1},
|
||||
{'display_name': 'face mask 2', 'amount': 15, 'reference_id': 2}]
|
||||
global_title = 'FooBar'
|
||||
|
||||
url = sign_url(url, settings.LINGO_API_SIGN_KEY)
|
||||
for item in items_post_data:
|
||||
resp = app.post_json(url, params=item)
|
||||
assert resp.status_code == 200
|
||||
|
||||
resp = login(app).get('/test_basket_cell/')
|
||||
import eopayment
|
||||
eopayment_mock = mock.Mock(
|
||||
return_value=('orderid', eopayment.URL, 'http://dummy-payment.demo.entrouvert.com/'))
|
||||
monkeypatch.setattr(eopayment.Payment, 'request', eopayment_mock)
|
||||
with override_settings(TEMPLATE_VARS={'global_title': global_title}):
|
||||
resp = resp.form.submit()
|
||||
eopayment_mock.assert_called_once_with(
|
||||
Decimal(25), email=user.email, first_name=user.first_name, last_name=user.last_name,
|
||||
merchant_name=global_title, items_info=items_info
|
||||
)
|
||||
|
||||
|
||||
def test_basket_items_extra_info_no_basket(app, regie, basket_page, monkeypatch):
|
||||
# when no user is authenticated, it is still possible to pass an email to eopayment backend
|
||||
url = reverse('api-add-basket-item')
|
||||
email = 'test@entrouvert.com'
|
||||
items_info = [{'text': 'face mask', 'amount': Decimal(10), 'reference_id': ''}]
|
||||
item = {'display_name': 'face mask', 'amount': 10, 'email': email}
|
||||
|
||||
url = sign_url(url, settings.LINGO_API_SIGN_KEY)
|
||||
resp = app.post_json(url, params=item)
|
||||
assert resp.status_code == 200
|
||||
item = BasketItem.objects.first()
|
||||
assert item.user is None
|
||||
|
||||
payment_url = resp.json['payment_url']
|
||||
import eopayment
|
||||
eopayment_mock = mock.Mock(
|
||||
return_value=('orderid', eopayment.URL, 'http://dummy-payment.demo.entrouvert.com/'))
|
||||
monkeypatch.setattr(eopayment.Payment, 'request', eopayment_mock)
|
||||
resp = app.get(payment_url)
|
||||
eopayment_mock.assert_called_once_with(
|
||||
Decimal(10), email=email, first_name='', last_name='', items_info=items_info,
|
||||
merchant_name='Compte Citoyen'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_capture_date", [8, '', 'not-a-date'])
|
||||
|
|
Loading…
Reference in New Issue