Reputation: 1497
I'm currently working on an e-commerce project and I need some help with my payment page. At the checkout page, I get the users' payment info which is a GSM number only, I post it to the payment system service, which returns a synchronous response. Response can be "OK", "NOT OK", "AWAIT" and "TIMEOUT". OK means payment is successful, NOT OK means payment is not successful and of course "TIMEOUT" means the payment operation is timed out.
The tricky part is "AWAIT". This service has a timeout of 4 mins. This 4 mins is used for user to complete his/her payment via his/her cell phone. The payment system works in a such different way, when I start the payment process, the service returns me "AWAIT" immediately and sends users' smart-phone a notification. This notification starts, let's call it a custom wallet, a custom wallet app. Then, user selects his/her payment card, which is pre-defined in this custom wallet system and confirms the payment. The user has a 4 min timeout period. In this 4 min either he/she completes the payment or the operation is timed out. My problem is, this payment service is a synchronous operation. So, I have to call it every 5 seconds for a 4 min period until I get a response other than "AWAIT". By this time I have to return a synchronous response to the page indicating that the payment process has begun and waiting for user confirmation and start an async operation which checks this custom wallet service for 4 mins and gets the response. And then I need to post this async response to the web page.
What I'm looking for is a way to solve this problem in order to avoid possible problems like concurrency or synchronization. I would appreciate a little sample code for this also. Thanks...
Upvotes: 0
Views: 749
Reputation: 457382
By this time I have to return a synchronous response to the page indicating that the payment process has begun and waiting for user confirmation and start an async operation which checks this custom wallet service for 4 mins and gets the response. And then I need to post this async response to the web page.
Yeah, that's not easy. The only solution I can recommend is pretty complex.
When the initial request comes in, you need to create a persistent entity for that transaction, save it, and then return the unique entity identifier. Note that it must be saved in a persistent location (i.e., an Azure table).
Next, you'll need a separate server to poll for updates (i.e., an Azure worker role, or a Win32 service). This should not be done from ASP.NET since it is work that lives without an HTTP request.
Then, when your end-user app polls for completion, your web service can retrieve the current state from the persistent entity.
There are different "shortcuts" you can take: keeping the entities in memory instead of persistent, and rolling the server into some kind of background process in the ASP.NET site. But both of these shortcuts bring serious reliability and robustness issues, and should not be considered for financial transactions.
Upvotes: 3