? simple_payments.patch
Index: invoice_paypal.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invoice_paypal/invoice_paypal.info,v
retrieving revision 1.1
diff -u -p -r1.1 invoice_paypal.info
--- invoice_paypal.info	19 Nov 2009 08:55:46 -0000	1.1
+++ invoice_paypal.info	20 Nov 2009 11:55:19 -0000
@@ -3,4 +3,5 @@ name = Pay with Paypal
 description = Extends the Invoice module to allow paying invoices online using Paypal
 core = 6.x
 dependencies[] = invoice
-dependencies[] = flag
\ No newline at end of file
+dependencies[] = flag
+dependencies[] = simple_payments_paypal
Index: invoice_paypal.js
===================================================================
RCS file: invoice_paypal.js
diff -N invoice_paypal.js
--- invoice_paypal.js	19 Nov 2009 08:55:46 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,12 +0,0 @@
-// $Id: invoice_paypal.js,v 1.1 2009/11/19 08:55:46 cweagans Exp $
-
-$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
-  if (data.flagName == 'invoice_paid') {
-    if (data.flagStatus == 'flagged') {
-      $('div.invoice_paypal_button_container').hide();      
-    }
-    if (data.flagStatus == 'unflagged') {
-      $('div.invoice_paypal_button_container').show();
-    }
-  }
-});
\ No newline at end of file
Index: invoice_paypal.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invoice_paypal/invoice_paypal.module,v
retrieving revision 1.3
diff -u -p -r1.3 invoice_paypal.module
--- invoice_paypal.module	19 Nov 2009 10:09:07 -0000	1.3
+++ invoice_paypal.module	20 Nov 2009 11:55:19 -0000
@@ -11,7 +11,6 @@
  */
 function invoice_paypal_init() {
   drupal_add_css(drupal_get_path('module', 'invoice_paypal') .'/invoice_paypal.css');
-  drupal_add_js(drupal_get_path('module', 'invoice_paypal') . '/invoice_paypal.js');
 }
 
 /**
@@ -81,7 +80,7 @@ function invoice_paypal_flag_default_fla
     'unflag_short' => 'Mark this invoice as unpaid',
     'unflag_long' => '',
     'unflag_message' => 'Invoice has been marked as unpaid!',
-    'show_on_page' => TRUE,
+    'show_on_page' => FALSE,
     'show_on_teaser' => FALSE,
     'show_on_form' => TRUE,
     'status' => TRUE,
@@ -114,44 +113,46 @@ function invoice_paypal_nodeapi(&$node, 
     case 'view':
       if ($node->type == 'invoice') {
         $flag = flag_get_flag('invoice_paid');
-        if ($flag->is_flagged($node->nid)) {
-          drupal_add_js("$(document).ready(function(){ $('div.invoice_paypal_button_container').hide();  })", 'inline');
+        if (!$flag->is_flagged($node->nid)) {
+          $vars = array(
+            'module' => 'invoice_paypal',
+            'type' => 'invoice',
+            'custom' => $node->invoice['formatted_invoice_number'],
+            'item_name' => $node->title,
+            'item_number' => $node->nid,
+            'no_shipping' => TRUE,
+            'no_note' => TRUE,
+            'return' => url(drupal_get_destination(), array('absolute' => TRUE)),
+            'amount' => $node->invoice['inctotal'],
+          );
+
+          $paypal_form = drupal_get_form('invoice_paypal_payment_form', $vars);
+
+          $node->content['invoice_paypal_button'] = array(
+            '#weight' => 99,
+            '#value' => '<div class="invoice_paypal_button_container">' . $paypal_form . '</div>',
+          );
         }
-        $node->content['invoice_paypal_button'] = array(
-          '#value' => theme('invoice_paypal_button', variable_get('invoice_paypal_email_address', ''), variable_get('invoice_paypal_currency_code', 'USD'), $node->invoice['formatted_invoice_number'], $node->invoice['inctotal']),
-          '#weight' => 99,
-        );
       }
       break;
   }
 }
 
-/**
- * Implementation of hook_theme().
- */
-function invoice_paypal_theme() {
-  return array(
-    'invoice_paypal_button' => array(
-      'arguments' => array('email', 'currency_code', 'invoice_number', 'total'),
-    ),
-  );
+function invoice_paypal_payment_form($form_state, $vars) {
+  $form = simple_payments_paypal_payment_form($vars);
+  $form['button'] = array(
+    '#type' => 'button',
+    '#value' => t('Pay with PayPal'),
+  );
+  return $form;
 }
 
-/**
- * Theme function for Paypal button
- */
-function theme_invoice_paypal_button($email, $currency_code, $invoice_number, $total) {
-  $output = '<div class="invoice_paypal_button_container">';
-  $output .= <<<EOL
-<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
-<input type="hidden" name="cmd" value="_xclick">
-<input type="hidden" name="business" value="{$email}">
-<input type="hidden" name="currency_code" value="{$currency_code}">
-<input type="hidden" name="item_name" value="Invoice #{$invoice_number}">
-<input type="hidden" name="amount" value="{$total}">
-<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Pay invoice now">
-</form>
-EOL;
-  $output .= '</div>';
-  return $output;
-}
+function invoice_paypal_simple_payment_process($payment) {
+  $flag = flag_get_flag('invoice_paid');
+  if ($flag->flag('flag', $payment['item_number'])) {
+    return TRUE;
+  }
+  else {
+    return FALSE;
+  }
+}
\ No newline at end of file
