Ali-Toosi / django-pardakht

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

How to test payment on local machine ? #5

Closed omiid-ad closed 4 years ago

omiid-ad commented 4 years ago

hey, im new at payment stuff, and im trying to connect to Saman gateway using this package. i did every config you mentioned in REEDME.rst . but everytime a user create a payment, it return -18 as Token, and will raise a DuplicateEntryKey for further payments (because Token is unique and it will set it to -18 for every payment, so its not unique anymore !).

i'm using django 3.0.5, and wanna test payments on my local machine (127.0.0.1:8000/...)

Where is the problem ? why i cant test my payments ?!

Ali-Toosi commented 4 years ago

Hi Omid,

Unfortunately, Saman does not provide explanations on error responses for RequestToken method specifically. However, they have provided a table of status codes for verifyTransaction method which we can assume is used for other methods as well. In that case, the -18 code you are receiving is because you are testing from an IP that Saman gateway doesn't allow you to make requests from. You should either update the correct IP into Saman's system or seek further information from them as to how you can test it with local IP.

Regarding the DuplicateEntryKey error, I just released a new version which raises an error if an error is returned instead of a token and doesn't save it to the database so it should work fine now.

Please update the package (pip install --upgrade django-pardakht) and try again. It shouldn't raise the duplicate key error but instead, it will show the user an error message that token could not be retrieved and it will log the error code (-18 in your case) in the log files.

omiid-ad commented 4 years ago

Thanks for solving the issue, i really appreciate that.

Ok i will call to Saman Operators and ask them how to test from local ip, if they provide me any usefull informations, i will inform you. :)

Sorry i know i should open anorher issue, but i have a very little question about how callback methodworks. You mentioned that callback method calls via PaymentObject as its argument, so how can i pass in more argument ? Ex . A product id , a dictionary or ... .

Thanks ~

Ali-Toosi commented 4 years ago

Any data beyond the payment attributes should be stored in other models and accessed using a foreign key to the payment object.

For example, if you want to have a store selling products then one possible pathway to take would be creating an Invoice model which stores all of the products purchased, then each Invoice will have a Payment by a foreign key. So when your callback function is called, you will find the invoice associated with that payment and find the products you want to provide to your user, from the Invoice object.