0001-nanterre-permettre-de-payer-plusieurs-factures-fixes.patch
zoo/zoo_nanterre/api_views.py | ||
---|---|---|
1418 | 1418 | |
1419 | 1419 | |
1420 | 1420 |
class TransactionSagaSerializer(serializers.Serializer): |
1421 |
num_facture = serializers.CharField() |
|
1421 |
num_facture = serializers.CharField(required=False, default='') |
|
1422 |
num_factures = serializers.ListField(child=serializers.CharField(), required=False, default=[]) |
|
1422 | 1423 |
urlretour_asynchrone = serializers.URLField() |
1423 | 1424 |
urlretour_synchrone = serializers.URLField() |
1424 | 1425 |
email = serializers.EmailField(required=False) |
1425 | 1426 | |
1427 |
def validate(self, data): |
|
1428 |
if not data['num_facture'] and not data['num_factures']: |
|
1429 |
raise serializers.ValidationError('vous devez fournir num_facture ou num_factures') |
|
1430 |
return data |
|
1431 | ||
1426 | 1432 | |
1427 | 1433 |
class SagaTransaction(SagaFactures): |
1428 | 1434 |
def post(self, request, identifier, format=None): |
1429 |
factures, error_response = self.get_factures(identifier) |
|
1430 | ||
1431 |
if error_response: |
|
1432 |
return error_response |
|
1433 | ||
1434 | 1435 |
serializer = TransactionSagaSerializer(data=request.data) |
1435 | 1436 |
if not serializer.is_valid(): |
1436 | 1437 |
return Response({ |
... | ... | |
1438 | 1439 |
'errors': flatten_errors(serializer.errors), |
1439 | 1440 |
}, status=400) |
1440 | 1441 | |
1442 |
data = serializer.validated_data |
|
1443 | ||
1444 |
factures, error_response = self.get_factures(identifier) |
|
1445 | ||
1446 |
if error_response: |
|
1447 |
return error_response |
|
1448 | ||
1449 |
factures_a_payer = [] |
|
1450 | ||
1441 | 1451 |
for facture in factures: |
1442 |
if facture.num == serializer.validated_data['num_facture']:
|
|
1443 |
break
|
|
1444 |
else:
|
|
1452 |
if facture.num == data['num_facture'] or facture.num in data['num_factures']:
|
|
1453 |
factures_a_payer.append(facture)
|
|
1454 |
if not factures_a_payer:
|
|
1445 | 1455 |
return Response({ |
1446 | 1456 |
'err': 1, |
1447 | 1457 |
'errors': [ |
1448 |
'numéro de facture inconnu',
|
|
1458 |
u'numéro(s) de facture inconnu',
|
|
1449 | 1459 |
] |
1450 | 1460 |
}) |
1451 | 1461 | |
1452 | 1462 |
data = serializer.validated_data |
1453 | 1463 |
email = data.get('email') or self.individu.content['email'] or '' |
1454 | 1464 |
url, error = self.ws.transaction( |
1455 |
facture=facture,
|
|
1465 |
facture_or_factures=factures_a_payer,
|
|
1456 | 1466 |
urlretour_asynchrone=data['urlretour_asynchrone'], |
1457 | 1467 |
urlretour_synchrone=data['urlretour_synchrone'], |
1458 | 1468 |
email=email) |
zoo/zoo_nanterre/saga.py | ||
---|---|---|
149 | 149 |
yield facture |
150 | 150 |
return list(helper()), None |
151 | 151 | |
152 |
def transaction(self, facture, urlretour_asynchrone, urlretour_synchrone, email): |
|
152 |
def transaction(self, facture_or_factures, urlretour_asynchrone, urlretour_synchrone, email):
|
|
153 | 153 |
body = ''' |
154 | 154 |
<Transaction> |
155 | 155 |
<num_service>{num_service}</num_service> |
... | ... | |
159 | 159 |
<email>{email}</email> |
160 | 160 |
<urlretour_synchrone>{urlretour_synchrone}</urlretour_synchrone> |
161 | 161 |
</Transaction>''' |
162 |
if isinstance(facture_or_factures, Facture): |
|
163 |
id_facture = unicode(facture_or_factures.num) |
|
164 |
montant = facture_or_factures.reste_a_payer |
|
165 |
else: |
|
166 |
id_facture = u'--'.join(unicode(facture.num) for facture in facture_or_factures) |
|
167 |
montant = sum(facture.reste_a_payer for facture in facture_or_factures) |
|
162 | 168 |
tree, error = self.soap_call( |
163 | 169 |
self.paiement_url, body, 'TransactionReturn', |
164 | 170 |
num_service=self.num_service, |
165 |
id_facture=facture.num,
|
|
166 |
montant=facture.reste_a_payer,
|
|
171 |
id_facture=id_facture,
|
|
172 |
montant=montant,
|
|
167 | 173 |
urlretour_asynchrone=urlretour_asynchrone, |
168 | 174 |
urlretour_synchrone=urlretour_synchrone, |
169 | 175 |
email=email) |
170 |
- |