req.endHandler(new SimpleHandler() { // never called, don't know why...
protected void handle() {
// my business code (doesn't matter here)
req.headers().put("worldpay-done", "true"); // just to flag the job is done
}
});
vertx.setTimer(2000, new Handler<Long>(){ // checking 2s after WorldPay post
public void handle(Long timerID) {
if (!"true".equals(req.headers().get("worldpay-done"))) { // actually always happen try {
System.out.println("Trying workaround");
// Ugly code to get the post content received by vert.x
java.lang.reflect.Field field = DefaultHttpServerRequest.class.getDeclaredField("request");
field.setAccessible(true);
DefaultHttpRequest request = (DefaultHttpRequest) field.get(req);
field = DefaultHttpMessage.class.getDeclaredField("content");
field.setAccessible(true);
ChannelBuffer content = (ChannelBuffer) field.get(request);
// Now getting the WorldPay form parameters
Buffer buff = new Buffer(content);
Map<String, String> parameters = new HashMap<>();
for (Map.Entry<String, List<String>> entry : new QueryStringDecoder(buff.toString(), false).getParameters().entrySet()) {
parameters.put(entry.getKey(), entry.getValue().get(0));
System.out.println(entry.getKey() + " = " + entry.getValue().get(0));
}
// my business code (doesn't matter here)
req.headers().put("worldpay-done", "true");
} catch (Exception e) {
CoreSystem.log(e);
}
}
});
}
This code is ugly but at least it works with vert.x 1.3.
I couldn't find a similar workaround with vert.x 2.1
Not sure it's useful but here is the 'Callback Failure Alert From WorldPay' email I receive from WorldPay on each payment notification attempt:
Our systems have detected that your callback has failed.
This callback failure means we were unable to pass information
to your server about the following transaction:
Transaction ID: xxx
Cart ID: xxx
Installation ID: xxx
Error reported: Callback to: http://mybookingwebsite/payment-notification/: failed CAUSED BY Read timed out
Server Reference: ukdc2-pz-cen07:callbackFailureEmail-12067:MerchReq-373-46
Also, if you usually return a response page for us to display to the Shopper
within the time allowed (1 minute), this will not have been displayed.
WorldPay will have displayed to the Shopper the response page file
(resultY.html or resultC.html) held for your installation on the WorldPay
server. This will be your own custom version, if you have supplied one, or,
if not, the WorldPay default version.
We hope this information will be of assistance. Please refer to the WorldPay
or contact your local Technical Support team if you want help or advice
about using the callback facility or about this particular callback failure.
If you would like to switch off the callback failure alerts or would like to
change the address to which these emails are sent, you can do so by
following the steps below on the Merchant Interface (WorldPay
- Log on to the Merchant Interface.
- Click on the "Configuration Options" button for the relevant installation.
- Edit the "Callback Failure Alert email address" field. If you wish to switch
off the callback failure alerts, set the "Callback Failure Alert email
address" field as blank.
- Make sure you click on "Save Changes" before leaving the page.
Thank you,
WorldPay Technical Support
Technical Support (Europe, Middle East & Africa)
Technical Support (The Americas)
Technical Support (Asia Pacific)