diff --git a/eopayment/payfip_ws.py b/eopayment/payfip_ws.py index 751cd88..4292dc1 100644 --- a/eopayment/payfip_ws.py +++ b/eopayment/payfip_ws.py @@ -327,7 +327,14 @@ class Payment(PaymentCommon): if e.code == 'P5' and delta < threshold: return PaymentResponse(result=WAITING, signed=True, order_id=transaction_id) raise e - return self.payfip_response_to_eopayment_response(idop, response) + eopayment_response = self.payfip_response_to_eopayment_response(idop, response) + # convert CANCELLED to WAITING during the first 20 minutes + if eopayment_response.result == CANCELLED and delta < threshold: + eopayment_response.result = WAITING + eopayment_response.bank_status = ( + '%s - still waiting as idop is still active' % eopayment_response.bank_status + ) + return eopayment_response def response(self, query_string, **kwargs): fields = parse_qs(query_string, True) diff --git a/tests/test_payfip_ws.py b/tests/test_payfip_ws.py index d141849..3bfc25d 100644 --- a/tests/test_payfip_ws.py +++ b/tests/test_payfip_ws.py @@ -393,8 +393,8 @@ def test_payment_cancelled(history, backend): assert url == 'https://www.payfip.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103' response = backend.response('idop=%s' % payment_id) - assert response.result == eopayment.CANCELLED - assert response.bank_status == 'cancelled CB' + assert response.result == eopayment.WAITING + assert response.bank_status == 'cancelled CB - still waiting as idop is still active' assert response.order_id == payment_id assert response.transaction_id == '201912261758460053903194 cc0cb210-1cd4-11ea-8cca-0213ad91a103' @@ -406,7 +406,17 @@ def test_payment_status_cancelled(history, backend, freezer): response = backend.payment_status( transaction_id='cc0cb210-1cd4-11ea-8cca-0213ad91a103', transaction_date=now ) + assert response.result == eopayment.WAITING + assert response.bank_status == 'cancelled CB - still waiting as idop is still active' + + freezer.move_to(datetime.timedelta(minutes=20, seconds=1)) + + history.counter = 1 # only the response + response = backend.payment_status( + transaction_id='cc0cb210-1cd4-11ea-8cca-0213ad91a103', transaction_date=now + ) assert response.result == eopayment.CANCELLED + assert response.bank_status == 'cancelled CB' def test_normalize_objet():