From ee0c2dc0ef30dbecd747a58932aa21d4c03edd90 Mon Sep 17 00:00:00 2001
From: Paolo Stancato <pstancato@syons.com.ar>
Date: Fri, 4 Sep 2009 11:39:16 -0300
Subject: [PATCH] Campo 'custom' personalizable

---
 lm_paypal.module                               |   14 ++++++++++----
 lm_paypal_donations/lm_paypal_donations.module |    8 +++++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lm_paypal.module b/lm_paypal.module
index b52afee..30c593a 100644
--- a/lm_paypal.module
+++ b/lm_paypal.module
@@ -424,7 +424,6 @@ function lm_paypal_page_thanks() {
  *   Or FALSE if amount is not a valid positive float.
  */
 function lm_paypal_api_payment_form($form_state, $amount, $options = array(), $type = LM_PAYPAL_FORM_TYPE_DONATE) {
-
   // Check for the different forms of $amount allowed: either a value, or an
   // array of values (with the default value being [value] rather than value.
 
@@ -590,10 +589,17 @@ function lm_paypal_api_payment_form($form_state, $amount, $options = array(), $t
     '#value' => lm_paypal_api_get_notify_url(),
     '#name' => 'notify_url',
   );
-  if (empty($custom) || is_array($custom)) {
-    $custom = array();
+  $custom_defaults = array('uid' => $user->uid);
+  $custom = array();
+  if (isset($options['custom']) && is_array($options['custom'])) {
+    $custom = $options['custom'];
+  }
+  else {
+    if ($options['custom'] != '') {
+      $custom = array('other' => $options['custom']);
+    }
   }
-  $custom['uid'] = $user->uid;
+  $custom = array_merge($custom_defaults, $custom);
   $form['custom'] = array(
     '#type' => 'hidden',
     '#value' => serialize($custom),
diff --git a/lm_paypal_donations/lm_paypal_donations.module b/lm_paypal_donations/lm_paypal_donations.module
index 6e630cf..efb3482 100644
--- a/lm_paypal_donations/lm_paypal_donations.module
+++ b/lm_paypal_donations/lm_paypal_donations.module
@@ -235,11 +235,14 @@ function _lm_paypal_process_in_donate($ipn, $link, $uid, $other, $item_number) {
  *   Label to put before the amount if asking the user
  * @param string $return_path = NULL
  *   If non empty it is the url the user is returned to after the transaction
+ * @param array $custom = array()
+ *   Custom fields defined by the user
+ *
  * @return
  *   The html string representing the button.
  */
 
-function lm_paypal_donate($amount, $ccc = NULL, $name = NULL, $button_url = NULL, $amount_label = NULL, $return_url = NULL) {
+function lm_paypal_donate($amount, $ccc = NULL, $name = NULL, $button_url = NULL, $amount_label = NULL, $return_url = NULL, $custom = array()) {
   if (!user_access('access lm_paypal_donate')) {
     return t('Access to PayPal donation buttons denied');
   }
@@ -259,6 +262,9 @@ function lm_paypal_donate($amount, $ccc = NULL, $name = NULL, $button_url = NULL
   if ($return_url) {
     $options['return_path'] = $return_url;
   }
+  if ($custom) {
+    $options['custom'] = $custom;
+  }
 
   return drupal_get_form('lm_paypal_api_payment_form', $amount, $options);
 }
-- 
1.6.0.4

