Ali-Toosi / django-pardakht

Django app for connecting to Iranian payment gateways.
MIT License
15 stars 8 forks source link

Token unique property conflicts with bank errors #3

Closed Bersam closed 5 years ago

Bersam commented 5 years ago

As you make token unique in your model, it seems that it cause conflicts at two points, first when no token is returned from bank and second when bank return an error such -18 as error code. Making token unique make sense as it really should be unique, but in such exceptions, it need to be handled carefully.

Ali-Toosi commented 5 years ago

That is a good point, thank you.

The process of getting the token from the gateway takes place in the select_gateway view, which will call the get_token method of the selected gateway. If the selected gateway is Zarinpal, the result status will be checked here to be successful, otherwise return None as the token, and then in the caller view it is checked here that if the returned token is None, render an error page and don't continue the process. Concerning the Saman gateway, on the other hand, it doesn't say in the API documentations what the possible return values are for the RequestToken method, and thus, I only check (here) that if the returned value is not None or an empty string, it is fine, otherwise, return None and the same process of rendering the error page... But if you have faced a problem caused by this assumption, please let me know and send me a little more details about the return value you have obtained from RequestToken method of the Saman gateway.

With regard to storing null values in a unique field, Django doesn't consider null to be equal to null in the model fields for the same purpose, and you can have multiple instances containing null as the value of some unique field. For further details on this please check out this ticket: #9039.