0

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...

4
  • What I'm looking for is a way to solve this problem You have described your task very well. But somehow, I failed to see exactly where the problem is. Would you mind explaining it for people with short-term memory? Commented Apr 4, 2013 at 14:04
  • 1
    You have more issues than just concurrency - reliability is also extremely important when dealing with payments. Rather than trying to hack together your own solution that works 99% of the time, I would look into something more robust, like WCF, so that you never lose track of a payment transaction that can take up to 4 minutes to complete. Commented Apr 4, 2013 at 14:07
  • I can't use WCF for other reasons. I'm simply posting a httpwebrequest to a url. Commented Apr 4, 2013 at 14:18
  • @dopache - Don't get hung up on a particular framework. The point is - what are you doing to make sure that 1) no payment request is ever lost, and 2) no payment request is processed more than once? Commented Apr 4, 2013 at 14:30

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, that looks pretty scary as you mentioned. I really don't know what to try? If you would be me, what would you prefer. Apply this complicated way, or just handle it in the background and send an information mail?. Thanks for your help by the way...
I would use an Azure table for persistent storage and Azure worker roles for processing. Whether you update the user via polling or email is really determined by how you want your app to behave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.