Project

General

Profile

Using WResoruce for handling post messages

Added by Mario Diethelm over 3 years ago

Hello, has been a long time without posting in this forum. I have re started a project to integrate a local payment system (in Chile) to a Wt application. The payment system is activated through an http post message sent using a WResource. Once the html code is streamed to the response parameter of the WResource (this resource is bounded to the application session currently being processed), the application is redirected to the local payment system were the actual payment flow is processed. Everything works ok up to that point.

When the customer finishes the payment flow, the local payment system redirects the flow to an specific url, informed in the initiation process of the payment flow, again through an http post message. I am using a WResource ® bounded to the WServer through addResource(&r, "/internal_path"). My application is receiving the answer from the payment system in the expected URL but then the current session is killed, and WT application creator callback routine is activated, the same way if a new session were starting.

I would appreciate your comments and hints in this case.

Thanks a lot. Best regards.

Mario Diethelm


Replies (3)

RE: Using WResoruce for handling post messages - Added by Mario Diethelm over 3 years ago

As usual, the issue was in my code. I reviewed the PayPal example and got some hints to improve my code. The weird behaviour that made my application to close the current session and start a new one every time the local payment system (WebPay) returned with information to my application was solved adding a WtDialog invoked in parallel with WebPay. I am not sure why.

Additionally, and based on the PayPal example, I modified the resources (WResource) to communicate with WebPay. Instead of binding the resources at server level now I handle them at session level. Instead of assigning a fixed URL for the resources, I use the URL generated by WResource starting from a fixed internal path assigned through WResource::setInternalPath.

Anyway, now the payment flow is working. I would like to ask for some advices to improve my current implementation. According to the documentation and based on the experience using WebPay, is not possible to show WebPay GUI in a window, you must use the full web browser tab. I trigger WebPay (WResource) from a WPushButton using setLink. I had to include a setLinkTarget(TargetNewWindow) to display WebPay GUI in a new browser tab. If I use the default behaviour for setLink (TargetSelf or TargetThisWindow), I am not able to get back at the point (page) where the payment was started. Is there a way to switch from one browser tab to another (i.e. from WebPay tab to my application tab)? After switching back from WebPay tab to application tab, is there a way to close WebPay tab?

Thanks again. Best regards.

RE: Using WResoruce for handling post messages - Added by Mario Diethelm over 3 years ago

Hi again. Still working on the payment system implementation.

As I commented in the previous post, besides the issue regarding the switch between WebPay tab and my application tab, the payment flow is working. Nevertheless, I have a problem with my application UI update time. I have followed the complete sequence for both approved and rejected payments through Wt::log("info") messages in each relevant step of the payment flow. When the payment flows finish, the object that handles WebPay interface emits a Wt::Signal that informs the WebPay status through an integer (the status) and a string that provides information for the customer regarding how the payment flow concluded (approved, rejected, timed out, etc.).

The slot that is associated with the above commented Wt::Signal receives the signal and in fact it add a new entry log (Wt::log) informing the situation. Even though the log correctly reflects the elapsed time between the start and the end of the payment flow (normally between 5 - 10 seconds), the application UI is not updated at the same time the signal is received. In fact, it takes a long time (20 - 40) to finally update the UI.

I have tried adding a WApplication::instance()->enableUpdate(true) immediately before the payment flow starts and a WApplication::instance()->enableUpdate(false) + triggerUpdate() when the slot waiting for the WebPay finish signal receives it, following PayPal example, but it did not fixed the problem.

What I am doing wrong? Is there a way to force the UI update? Is this problem related to the fact that I am triggering the WebPay UI in a different tab (TargetNewWindow)?

Once again, thanks a lot. Best regards.

RE: Using WResource for handling post messages - Added by Mario Diethelm over 3 years ago

Hi.

As I commented in my previous post, the payment flow is working and I finally implemented a way to return from the payment solution tab (opened using TargetNewWindow) to the Wt application tab. But I am still stuck with the UI update problem. In a nutshell, the payment flow (not just for approved but also for rejected, timed out or aborted transactions) works pretty well and timely informs (using a Wt::Signal) when it is completed. Even though the slot that is connected to the payment flow termination event receives the signal, the UI is not immediately updated (it takes between 30 to 90 seconds to update). I have tried several approaches, but I cannot get the UI updated timely:

  1. Using WApplication::instance()->processEvents(), the session is closed
  2. Using WApplication::instance()->refresh(), after setting to false at wt_config.xml level. No effect
  3. Based on the example paypalexample.c, I added a WApplication::instance()->enableUpdates(true) when the payment flow starts and enableUpdates(false) and triggerUpdate() when the slot connected to the paymentflow closing event receives the corresponding signal. No effect. I actually tested calling first triggerUpdate() and then enablesUpdates(false) but same result, no effect (in fact the way that this mechanism is implemented in paypalexample.c is a little confusing to me. According to Wt documentation a call to triggerUpdate only has an effect after updates have been enabled from within the normal event loop using enableUpdates(). I don’t understand why in paypalexample.c triggerUpdate() calls are always after enableUpdates(false) calls).

I would appreciate any advice that could help me to get the UI updated in a timely way.

Thanks again. Regards.

    (1-3/3)