0001-lingo-support-can_pay_only_one-on-remote-regie-50067.patch
combo/apps/lingo/forms.py | ||
---|---|---|
109 | 109 |
instance.save() |
110 | 110 |
return instance |
111 | 111 | |
112 |
def clean(self): |
|
113 |
cleaned_data = super().clean() |
|
114 |
if cleaned_data['webservice_url'] and cleaned_data['can_pay_only_one_basket_item']: |
|
115 |
raise ValidationError('Individual item payment is incompatible with remote regie.') |
|
116 |
return cleaned_data |
|
117 | ||
118 | 112 | |
119 | 113 |
class PaymentBackendForm(forms.ModelForm): |
120 | 114 |
combo/apps/lingo/views.py | ||
---|---|---|
360 | 360 |
self, request, regie, items, remote_items, next_url='/', email='', firstname='', |
361 | 361 |
lastname=''): |
362 | 362 |
# check contract |
363 |
assert bool(len(items)) != bool(len(remote_items)), ( |
|
364 |
'there should be at least one item or remote item to pay and not both items' |
|
365 |
) |
|
366 |
assert not regie.can_pay_only_one_basket_item or len(items) == 1, ( |
|
367 |
'regie can only pay one basket item, but handle_payment() ' |
|
368 |
'did not receive one item: len(items) = %d' % len(items) |
|
369 |
) |
|
363 |
if bool(len(items)) == bool(len(remote_items)): |
|
364 |
raise PaymentException('there should be at least one item or remote item to pay and not both items') |
|
365 |
if regie.can_pay_only_one_basket_item and (len(items) > 1 or len(remote_items) > 1): |
|
366 |
raise PaymentException('regie can only pay one basket item, but handle_payment() ' |
|
367 |
'did not receive one item: len(items) = %d' % len(items)) |
|
370 | 368 | |
371 | 369 |
total_amount = sum([x.amount for x in remote_items or items]) |
372 | 370 | |
... | ... | |
495 | 493 |
regie.compute_extra_fees(user=user) |
496 | 494 |
items = BasketItem.get_items_to_be_paid(user=user).filter(regie=regie) |
497 | 495 | |
498 |
if regie.can_pay_only_one_basket_item and len(items) > 1:
|
|
499 |
messages.error(request, _('Grouping basket items is not allowed.'))
|
|
500 |
logger.error('lingo: regie can only pay one basket item, but handle_payment() received',
|
|
501 |
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items})
|
|
502 |
return HttpResponseRedirect(next_url)
|
|
496 |
if regie.can_pay_only_one_basket_item and (len(items) > 1 or len(remote_items) > 1):
|
|
497 |
messages.error(request, _('Grouping basket items is not allowed.')) |
|
498 |
logger.error('lingo: regie can only pay one basket item, but handle_payment() received', |
|
499 |
extra={'regie': str(regie), 'items': items, 'remote_items': remote_items}) |
|
500 |
return HttpResponseRedirect(next_url) |
|
503 | 501 | |
504 | 502 |
if items: |
505 | 503 |
capture_date = items[0].capture_date |
tests/test_lingo_remote_regie.py | ||
---|---|---|
42 | 42 |
'paid': False, |
43 | 43 |
'payment_date': '1970-01-01', |
44 | 44 |
'no_online_payment_reason': '', |
45 |
'reference_id': 'order-id-1', |
|
46 |
}, |
|
47 |
{ |
|
48 |
'id': 'F201602', |
|
49 |
'display_id': 'F-2016-Two', |
|
50 |
'label': 'invoice-two', |
|
51 |
'regie': 'remote', |
|
52 |
'created': '2016-02-02', |
|
53 |
'pay_limit_date': '2999-12-31', |
|
54 |
'total_amount': '543.21', |
|
55 |
'amount': '543.21', |
|
56 |
'has_pdf': True, |
|
57 |
'online_payment': True, |
|
58 |
'paid': False, |
|
59 |
'payment_date': '1970-01-01', |
|
60 |
'no_online_payment_reason': '', |
|
61 |
'reference_id': 'order-id-2', |
|
45 | 62 |
}, |
46 | 63 |
] |
47 | 64 | |
... | ... | |
87 | 104 |
@mock.patch('combo.utils.requests_wrapper.RequestsSession.send') |
88 | 105 |
def test_remote_regie_active_invoices_cell(mock_send, remote_regie): |
89 | 106 |
assert remote_regie.is_remote() == True |
107 |
assert remote_regie.can_pay_only_one_basket_item is False |
|
90 | 108 | |
91 | 109 |
page = Page(title='xxx', slug='test_basket_cell', template_name='standard') |
92 | 110 |
page.save() |
... | ... | |
108 | 126 |
content = cell.render(context) |
109 | 127 |
assert 'F-2016-One' in content |
110 | 128 |
assert '123.45' in content |
129 |
assert 'F-2016-Two' in content |
|
130 |
assert '543.21' in content |
|
111 | 131 | |
112 | 132 |
assert '?page=%s' % page.pk in content |
113 | 133 |
# check if regie webservice has been correctly called |
... | ... | |
199 | 219 |
content = cell.render(context) |
200 | 220 |
assert 'F-2016-One' in content |
201 | 221 |
assert '123.45' in content |
222 |
assert 'F-2016-Two' in content |
|
223 |
assert '543.21' in content |
|
202 | 224 |
assert 'class="invoice-payment-limit-date"' in content |
203 | 225 | |
204 | 226 |
# invoice without limit date |
205 | 227 |
invoices = copy.deepcopy(INVOICES) |
206 | 228 |
invoices[0]['pay_limit_date'] = '' |
229 |
invoices[1]['pay_limit_date'] = '' |
|
207 | 230 |
ws_invoices = {'err': 0, 'data': invoices} |
208 | 231 |
mock_response = mock.Mock(status_code=200, content=json.dumps(ws_invoices)) |
209 | 232 |
mock_response.json.return_value = ws_invoices |
... | ... | |
592 | 615 |
@mock.patch('combo.apps.lingo.models.Regie.pay_invoice') |
593 | 616 |
@mock.patch('combo.apps.lingo.models.requests.get') |
594 | 617 |
def test_remote_invoice_successfull_payment_redirect(mock_get, mock_pay_invoice, app, remote_regie): |
618 |
assert remote_regie.is_remote() |
|
619 |
assert remote_regie.can_pay_only_one_basket_item is False |
|
620 |
remote_regie.save() |
|
621 | ||
595 | 622 |
page = Page(title='xxx', slug='active-remote-invoices-page', template_name='standard') |
596 | 623 |
page.save() |
597 |
assert remote_regie.is_remote() |
|
598 | 624 |
encrypt_id = aes_hex_encrypt(settings.SECRET_KEY, force_bytes('F201601')) |
599 | 625 |
mock_json = mock.Mock() |
600 | 626 |
mock_json.json.return_value = {'err': 0, 'data': INVOICES[0]} |
... | ... | |
612 | 638 |
parsed = urlparse.urlparse(location) |
613 | 639 |
# get return_url and transaction id from location |
614 | 640 |
qs = urlparse.parse_qs(parsed.query) |
641 |
assert 'orderid' not in qs |
|
642 |
assert 'subject' not in qs |
|
615 | 643 |
args = {'transaction_id': qs['transaction_id'][0], 'signed': True, |
616 | 644 |
'ok': True, 'reason': 'Paid'} |
617 | 645 |
resp = app.get(qs['return_url'][0], params=args) |
... | ... | |
622 | 650 |
assert urlparse.urlparse(resp.html.find('a', {'id': 'next-url'})['href']).path == \ |
623 | 651 |
'/active-remote-invoices-page/' |
624 | 652 | |
653 |
# one item limitation: send orderid to eopayment |
|
654 |
remote_regie.can_pay_only_one_basket_item = True |
|
655 |
remote_regie.save() |
|
656 |
resp = form.submit() |
|
657 |
assert resp.status_code == 302 |
|
658 |
location = resp.location |
|
659 |
assert 'dummy-payment' in location |
|
660 |
parsed = urlparse.urlparse(location) |
|
661 |
qs = urlparse.parse_qs(parsed.query) |
|
662 |
assert qs['orderid'] == ['order-id-1'] |
|
663 |
assert qs['subject'] == ['invoice-one'] |
|
664 | ||
625 | 665 | |
626 | 666 |
@mock.patch('combo.apps.lingo.models.UserSAMLIdentifier') |
627 | 667 |
@mock.patch('combo.apps.lingo.models.requests.get') |
628 |
- |