*/
public WOActionResults ipnAction() { // processor for Instant Payment Notifications
boolean isSandboxMode = false;
WORequest ppIPNRequest = request(); // the incoming PayPal IPN (Instant Payment Notification)
if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelInformational)) {
NSLog.debug.appendln("PayPal's request looks like: " + ppIPNRequest + "\n\n");
NSLog.debug.appendln("PayPal's request content looks like: " + ppIPNRequest.contentString() + "\n\n");
}
WOResponse ppValidationResponse = null; // PayPal's validation of our echoed data
String ppValidationResponseString = null;
boolean connectionSuccess;
if (ppIPNRequest.formValues().containsKey("test_ipn")) {
isSandboxMode = true;
} else {
isSandboxMode = false;
}
String returnString = ppIPNRequest.contentString() + "&cmd=_notify-validate";
WOHTTPConnection ppEchoConnection = new WOHTTPConnection(paypalSite, 80); // our echo to PayPal
if (isSandboxMode) {
ppEchoConnection = new WOHTTPConnection(sandboxSite, 80); // our echo to PayPal
}
// assemble User-Agent header
StringBuilder ua = new StringBuilder();
ua.append("WebObjects/ " + ERXProperties.webObjectsVersion() + " (");
ua.append(System.getProperty("os.arch"));
ua.append("; ");
ua.append(System.getProperty("os.name"));
ua.append(' ');
ua.append(System.getProperty("os.version"));
ua.append(')');
NSMutableDictionary headers = new NSMutableDictionary();
headers.setObjectForKey("en", "Accept-Language");
headers.setObjectForKey("iso-8859-1,*,utf-8", "Accept-Charset");
headers.setObjectForKey("image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*", "Accept");
headers.setObjectForKey(ua.toString(),"User-Agent");
// the response back to PayPal
WORequest paypalEchoRequest;
paypalEchoRequest = new WORequest("POST", paypalCgi, "HTTP/1.1", headers, null, null);
paypalEchoRequest.setContent(returnString);
ppEchoConnection.setReceiveTimeout(90 * 1000); // 90 second timeout -- this might be too long!?!
connectionSuccess = ppEchoConnection.sendRequest(paypalEchoRequest);
if (connectionSuccess) {
ppValidationResponse = ppEchoConnection.readResponse(); // read PayPal's validation
}