--- paypal.module.4.6	2005-11-02 20:14:58.492598859 +0100
+++ paypal.module	2005-11-02 20:20:51.132549419 +0100
@@ -1,5 +1,5 @@
 <?php
-// $Id: paypal.module,v 1.22.2.2 2005/10/30 19:06:35 mathias Exp $
+// $Id: paypal.module,v 1.22.2.1 2005/06/29 17:11:20 mathias Exp $
 
 /********************************************************************
  * Drupal Hooks
@@ -48,60 +48,48 @@
   return $output;
 }
 
-function paypal_paymentapi(&$txn, $op, $arg = '') {
+function paypal_paymentapi(&$data, $op, $arg = '') {
+
   switch ($op) {
     case 'display name':
       return t('PayPal');
 
+    case 'update':
+    case 'insert':
+      return paypal_save($data);
+
     case 'on checkout':
-      paypal_verify_checkout($txn);
-      break;
+      return paypal_verify_checkout($data);
 
     case 'payment page':
-      if ($txn->gross > 0) {
-        return paypal_goto($txn);
+      if ($data['gross'] > 0) {
+        return paypal_goto($data);
       }
       break;
-    }
-}
 
-/**
- * Implementation of hook_ec_transactionapi().
- */
-function paypal_ec_transactionapi(&$txn, $op, $a3 = NULL, $a4 = NULL) {
-  if ($txn->payment_method != 'paypal') return NULL;
-  switch ($op) {
-    case 'load':
-      $txn->payment = db_fetch_object(db_query("SELECT * FROM {ec_paypal} WHERE txnid = %d", $txn->txnid));
-      break;
-    case 'insert':
-    case 'update':
-      paypal_save($txn);
-      break;
     case 'delete':
-      paypal_delete($txn);
-      break;
-  }
+      return paypal_delete($data);
+    }
 }
 
-function paypal_verify_checkout($txn) {
-  if (variable_get('paypal_min_amount', '5.00') > $txn->gross) {
+function paypal_verify_checkout($data) {
+  if (variable_get('paypal_min_amount', '5.00') > $data['gross']) {
     form_set_error('gross', t('Your purchase total must be at least %min-purchase-amount for Paypal purchases.', array('%min-purchase-amount' => payment_format(variable_get('paypal_min_amount', '5.00')))));
   }
 }
 
-function paypal_delete($txn) {
-  db_query('DELETE FROM {ec_paypal} WHERE txnid = %d', $txn->txnid);
+function paypal_delete($data) {
+  db_query('DELETE FROM {ec_paypal} WHERE txnid = %d', $data['txnid']);
 }
 
-function paypal_goto($txn) {
+function paypal_goto($edit) {
 
   global $user;
 
   // Earmark the item_number since we never know if the admin is using Paypal
   // for other services.
-  if ($txn->txnid) {
-    $txnid = 'txnid_'. $txn->txnid;
+  if ($edit['txnid']) {
+    $txnid = 'txnid_'. $edit['txnid'];
   }
 
   global $base_url;
@@ -109,16 +97,17 @@
   $return_url = $base_url .'/'. $return_url;
   $cancel_url = (!strstr(variable_get('paypal_cancel_url', 'node'), 'http://')) ? $base_url. '/'. variable_get("paypal_cancel_url", 'node') : variable_get("paypal_cancel_url", 'node');
 
-  $item_name = ($user->uid) ? variable_get('site_name', 'drupal'). ' order #'. $txn->txnid. " for $user->name" : variable_get("site_name", "drupal"). " order";
+  $item_name = ($user->uid) ? t("%site_name order #%txn_id for %user_name", array('%site_name'=>variable_get('site_name', 'drupal'),'%txn_id'=>$txn->txnid,'%user_name'=>$user->name)): t("%site_name order #%txn_id",array('%site_name'=>variable_get("site_name", "drupal"),'%txn_id'=>$txn->txnid));
   $uri_array = array('business'       => variable_get('paypal_receiver_email', variable_get("site_mail", ini_get("sendmail_from"))),
                      'item_name'      => $item_name,
                      'item_number'    => $txnid,
-                     'amount'         => $txn->subtotal,
-                     'shipping'       => $txn->shipping_cost,
+                     'amount'         => $edit['subtotal'],
+                     'shipping'       => $edit['shipping_cost'],
                      'no_shipping'    => 1,
                      'return'         => $return_url,
                      'cancel'         => $cancel_url,
-                     'currency_code'  => variable_get('paypal_currency_code', 'USD')
+                     'currency_code'  => variable_get('paypal_currency_code', 'USD'),
+		     'country'        => $edit['billing_country']
                      );
 
   foreach($uri_array as $key => $value) {
@@ -139,15 +128,15 @@
   header("Location: $url");
 }
 
-function paypal_save($txn) {
+function paypal_save($edit) {
 
-  if ($txn->txnid && $txn->ppid) {
+  if ($edit['txnid'] && $edit['ppid']) {
 
-    if (db_result(db_query("SELECT COUNT(txnid) FROM {ec_paypal} WHERE txnid = '%s'", $txn->txnid))) {
-      db_query("UPDATE {ec_paypal} SET ppid = '%s', fee = '%s' WHERE txnid = '%d'", $txn->ppid, $txn->fee, $txn->txnid);
+    if (db_result(db_query("SELECT COUNT(txnid) FROM {ec_paypal} WHERE txnid = '%s'", $edit['txnid']))) {
+      db_query("UPDATE {ec_paypal} SET ppid = '%s', fee = '%s' WHERE txnid = '%d'", $edit['ppid'], $edit['fee'], $edit['txnid']);
     }
     else {
-      db_query("INSERT INTO {ec_paypal} (txnid, ppid, fee) VALUES (%d, '%s', '%s')", $txn->txnid, $txn->ppid, $txn->fee);
+      db_query("INSERT INTO {ec_paypal} (txnid, ppid, fee) VALUES ('%d', '%s', '%s')", $edit['txnid'], $edit['ppid'], $edit['fee']);
     }
   }
 
@@ -195,17 +184,11 @@
     watchdog('paypal', t('IPN hit, no transaction ID given.'));
   }
 
-  $has_shippable_item = false;
   foreach($i as $key => $value) {
     $pp_item->nid = $value;
     $pp_item->qty = $quantity[$key];
     $pp_item->title = $name[$key];
     $pp_item->price = null;
-
-    if (product_is_shippable($item->nid)) {
-      $has_shippable_item = true;
-    }
-
     $item[] = $pp_item;
   }
 
@@ -213,11 +196,11 @@
   $header = "POST /cgi-bin/webscr 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);
+  $fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
 
   /* Assign posted variables to local variables */
   $payment_status = $_POST['payment_status'];
-  $fee            = $_POST['payment_fee'];
+  $fee            = $_POST['mc_fee'];
   $payment_amount = $_POST['mc_gross'];
   $ppid           = $_POST['txn_id'];
   $receiver_email = $_POST['receiver_email'];
@@ -271,10 +254,6 @@
              removed from your account and returned to the customer */
           case 'COMPLETED':
               $data['payment_status'] = payment_get_status_id('completed');
-              // If there are no shippable items, assume the transaction workflow is complete.
-              if (!$has_shippable_item) {
-                $data['workflow'] = 6;
-              }
               $txnid = store_transaction_save($data);
               if ($is_new && $txnid) {
                 /* Compose and send confirmation email to the user */
