0001-lingo-add-transaction_amount-in-pay_invoice-payload-.patch
combo/apps/lingo/models.py | ||
---|---|---|
194 | 194 |
return requests.get(url, user=user, remote_service='auto', cache_duration=0) |
195 | 195 |
raise PermissionDenied |
196 | 196 | |
197 |
def pay_invoice(self, invoice_id, transaction_id, transaction_date):
|
|
197 |
def pay_invoice(self, invoice_id, transaction): |
|
198 | 198 |
url = self.webservice_url + '/invoice/%s/pay/' % invoice_id |
199 |
data = {'transaction_id': transaction_id, |
|
200 |
'transaction_date': transaction_date.strftime('%Y-%m-%dT%H:%M:%S')} |
|
199 |
data = {'transaction_id': transaction.order_id, |
|
200 |
'transaction_date': transaction.end_date.strftime('%Y-%m-%dT%H:%M:%S'), |
|
201 |
'transaction_amount': str(transaction.amount)} |
|
201 | 202 |
headers = {'content-type': 'application/json'} |
202 |
return requests.post(url, remote_service='auto', |
|
203 |
return requests.post(url, user=transaction.user, remote_service='auto',
|
|
203 | 204 |
data=json.dumps(data), headers=headers).json() |
204 | 205 | |
205 | 206 |
def as_api_dict(self): |
... | ... | |
486 | 487 |
for item_id in items.split(','): |
487 | 488 |
try: |
488 | 489 |
remote_item = regie.get_invoice(user=self.user, invoice_id=item_id) |
489 |
regie.pay_invoice(item_id, self.order_id, self.end_date)
|
|
490 |
regie.pay_invoice(item_id, self) |
|
490 | 491 |
except Exception: |
491 | 492 |
to_be_paid_remote_items.append(item_id) |
492 | 493 |
logger.exception(u'unable to notify payment for remote item %s from transaction %s', |
tests/test_lingo_remote_regie.py | ||
---|---|---|
173 | 173 |
content = cell.render(context) |
174 | 174 |
assert 'No items yet' in content |
175 | 175 | |
176 |
@mock.patch('combo.apps.lingo.models.Regie.pay_invoice') |
|
176 | ||
177 |
@mock.patch('combo.apps.lingo.models.requests.post') |
|
177 | 178 |
@mock.patch('combo.apps.lingo.models.requests.get') |
178 |
def test_anonymous_successful_item_payment(mock_get, mock_pay_invoice, app, remote_regie):
|
|
179 |
assert remote_regie.is_remote() == True
|
|
179 |
def test_anonymous_successful_item_payment(mock_get, mock_post, app, remote_regie):
|
|
180 |
assert remote_regie.is_remote() is True
|
|
180 | 181 |
encrypt_id = aes_hex_encrypt(settings.SECRET_KEY, 'F201601') |
181 | 182 |
mock_json = mock.Mock() |
182 | 183 |
mock_json.json.return_value = {'err': 0, 'data': INVOICES[0]} |
183 | 184 |
mock_get.return_value = mock_json |
184 |
mock_pay_invoice.return_value = mock.Mock(status_code=200) |
|
185 |
mock_post_json = mock.Mock() |
|
186 |
mock_post_json.json.return_value = {"err": 0, "data": True} |
|
187 |
mock_post.return_value = mock_post_json |
|
185 | 188 |
resp = app.get('/lingo/item/%s/%s/' % (remote_regie.id, encrypt_id)) |
186 | 189 |
form = resp.form |
187 | 190 | |
... | ... | |
215 | 218 |
assert urlparse.urlparse(resp.url).path == '/' |
216 | 219 |
# simulate successful call to callback URL |
217 | 220 |
resp = app.get(reverse('lingo-callback', kwargs={'regie_pk': remote_regie.id}), params=args) |
221 | ||
218 | 222 |
trans = Transaction.objects.all() |
219 | 223 |
b_item = BasketItem.objects.all() |
220 | ||
221 | 224 |
assert trans |
222 | 225 |
assert b_item |
223 | 226 |
trans = trans[0] |
... | ... | |
228 | 231 | |
229 | 232 |
assert resp.status_code == 200 |
230 | 233 | |
234 |
assert len(mock_post.call_args_list) == 1 |
|
235 |
call_args = mock_post.call_args_list[0] |
|
236 |
assert call_args[0][0] == 'http://example.org/regie/invoice/F201601/pay/' |
|
237 |
call_data = json.loads(call_args[1]['data']) |
|
238 |
assert call_data == { |
|
239 |
'transaction_id': trans.order_id, |
|
240 |
'transaction_date': trans.end_date.strftime('%Y-%m-%dT%H:%M:%S'), |
|
241 |
'transaction_amount': str(trans.amount), |
|
242 |
} |
|
243 | ||
244 | ||
231 | 245 |
@mock.patch('combo.apps.lingo.models.requests.get') |
232 | 246 |
def test_anonymous_item_payment_email_error(mock_get, app, remote_regie): |
233 | 247 |
assert remote_regie.is_remote() == True |
234 |
- |