--- paypal.module.4.6	2006-02-20 13:53:08.146526169 +0100
+++ paypal.module	2006-02-20 13:50:46.088998079 +0100
@@ -36,6 +36,7 @@
 function paypal_settings() {
   $output = form_textfield(t('PayPal Receiver Email'), 'paypal_receiver_email', variable_get('paypal_receiver_email', variable_get('site_mail', ini_get('sendmail_from'))), 70, 180, t('Primary email address of the payment recipent. This is also your main paypal email address.'));
   $output .= form_textfield(t('PayPal processing URL'), 'paypal_url', variable_get('paypal_url', 'https://www.paypal.com/xclick/'), 70, 180, t('URL of the secure payment page customers are sent to for payment processing.'));
+  $output .= form_textfield(t('PayPal IPN "request back" validation URL'), 'paypal_ipnrb_url', variable_get('paypal_ipnrb_url', 'http://www.paypal.com/cgi-bin/webscr'), 70, 180, t('URL where IPN "request back" is posted to validate the transaction.'));
   $output .= form_textfield(t('Successful payment URL'), 'paypal_return_url', variable_get('paypal_return_url', '%order-history'), 70, 180, t("This is the destination to which you would like to send your customers when their payment has been successfully completed. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'. You may also enter '%order-history' to link to the user's order history."));
   $output .= form_textfield(t('Cancel payment URL'), "paypal_cancel_url", variable_get("paypal_cancel_url", "node"), 70, 180, t("This is the destination to which you would like to send your customers if they cancel their payment. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify 'node'."));
 
@@ -208,12 +209,20 @@
 
     $item[] = $pp_item;
   }
-
+  $ipnrb = parse_url(variable_get('paypal_ipnrb_url', 'http://www.paypal.com/cgi-bin/webscr'));
   /* Post back to PayPal system to validate */
-  $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
+  $header = "POST {$ipnrb['path']} HTTP/1.0\r\n";
   $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
   $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
-  $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
+  if ($ipnrb['scheme']=='http') {
+    $port= 80;
+    $host=$ipnrb['host'];
+  }
+  else {
+    $port= 443;
+    $host="ssl://{$ipnrb['host']}";
+  }
+  $fp = fsockopen($host,$port, $errno, $errstr, 30);
 
   /* Assign posted variables to local variables */
   $payment_status = $_POST['payment_status'];
