--- uc_paybox.module	2009-10-30 10:36:58.000000000 +0100
+++ uc_paybox.module.new	2009-11-03 12:32:31.000000000 +0100
@@ -82,17 +82,37 @@ function uc_paybox_form_alter(&$form, &$
       unset($form['back']);
       $form['#action'] = base_path() .'cart/paybox/checkout';     
       $form['back'] = array(
-        '#value' => '<span style="margin-right:200px;"'. l(t('Back'), 'cart/checkout') .'</span>',
+        '#value' => '<span style="margin-right:200px;">'. l(t('Back'), 'cart/checkout') .'</span>',
       );
       $form['submit'] = array(
         '#type' => 'submit',
         '#value' => variable_get('uc_paybox_checkout_button', t('Submit Order')),
       );
+      
+      // Cache the details for use in other functions.
+      uc_paybox_cache('save', $_SESSION['sespb']);
+      
     }
   }
   elseif ($form_id == 'uc_store_format_settings_form') {
     $form['currency']['uc_currency_code']['#description'] .= ' '. t('Paybox only accepts the following currencies: @list', array('@list' => implode(', ', array_keys(_uc_paybox_currency(FALSE)))));
   }
+  elseif ($form_id == 'uc_cart_checkout_form') {
+    // Cache the Paybox details for use in other functions.
+    if (isset($_SESSION['sespb'])) {
+      uc_paybox_cache('save', $_SESSION['sespb']);
+
+      // Store the encrypted details to the form for processing on submit.
+      $form['payment_details_data'] = array(
+        '#type' => 'hidden',
+        '#value' => $_SESSION['sespb'],
+      );
+
+      // Clear the session of the details.
+      unset($_SESSION['sespb']);
+    }
+    unset($_SESSION['uc_paybox_pay']);
+  }
 }
 
 /*******************************************************************************
@@ -157,11 +177,35 @@ function uc_paybox_store_status() {
 function uc_payment_method_paybox($op, &$arg1) {
   switch ($op) {
     case 'cart-details':
-      $details = variable_get('uc_paybox_method_descr', t('Redirect to Paybox to pay by credit card.'));
-      return $details;
-
+      $details = variable_get('uc_paybox_method_descr', t('Redirect to Paybox to pay by credit card.'))
+       . drupal_get_form('uc_payment_method_paybox_form', $arg1);
+      return uc_strip_form($details);
+
+    case 'cart-review':
+      if (isset($_SESSION['sespb'])) {
+      	$payment_types = _uc_paybox_payment_type();
+      	$payment_details = unserialize($_SESSION['sespb']);
+        $payment_type = $payment_types[$payment_details['uc_paybox_typepaiement']];
+        if ($payment_type) {
+          $review[] = array('title' => t('Card Type'), 'data' => $payment_type);
+        }
+      }
+      return $review;
+      
     case 'cart-process':
-      return;
+    	$rc = TRUE;
+    	// Fetch the Paybox details from the $_POST directly.
+      $uc_paybox_data = array(
+        'uc_paybox_typepaiement' => check_plain($_POST['uc_paybox_typepaiement']),
+      );
+      if (!$uc_paybox_data['uc_paybox_typepaiement']) {
+      	drupal_set_message(t('Payment Type field is required.'), 'error');
+      	$rc = FALSE;
+      }
+      // Go ahead and put the Paybox data in the payment details array.
+      $arg1->payment_details = $uc_paybox_data;
+      $_SESSION['sespb'] = serialize($arg1->payment_details);
+      return $rc;
 
     case 'settings':
       // is_readable() can be false positive if apache user not cgi-bin folder owner...
@@ -249,6 +293,14 @@ function uc_payment_method_paybox($op, &
         '#options' => _uc_paybox_currency(),
         '#default_value' => variable_get('uc_paybox_devise', '978'),
       );
+      $form['paybox']['uc_paybox_typepaiement'] = array(
+        '#type' => 'select',
+        '#title' => t('Payment Type'),
+        '#description' => t('Select the type(s) of payment permitted. If none is selected, the selection will be done on the Paybox site'),
+        '#options' => _uc_paybox_payment_type(),
+        '#multiple' => TRUE,
+        '#default_value' => variable_get('uc_paybox_typepaiement', ''),
+      );         
       $form['paybox']['uc_paybox_cgi_path'] = array(
         '#type' => 'textfield',
         '#title' => t('Paybox cgi path'),
@@ -273,6 +325,81 @@ function uc_payment_method_paybox($op, &
   }
 }
 
+// Displays the credit card details form on the checkout screen.
+function uc_payment_method_paybox_form($form_state, $order) {
+  // Normally the payment data is posted in via AJAX.
+  if (!empty($_POST['payment-details-data']) && arg(0) == 'cart') {
+    $order->payment_details = uc_paybox_cache('save', $_POST['payment-details-data']);
+  }
+
+  // But we have to accommodate failed checkout form validation here.
+  if (isset($_SESSION['sespb'])) {
+    $order->payment_details = uc_paybox_cache('save', $_SESSION['sespb']);
+    unset($_SESSION['sespb']);
+  }
+  	
+	$payment_types = _uc_paybox_payment_type();
+  $options = array(); 
+  foreach ($payment_types as $payment_type['code'] => $payment_type['name']) {
+  	if (in_array($payment_type['code'], variable_get('uc_paybox_typepaiement', ''))) {
+		  $options[$payment_type['code']] = $payment_type['name'];
+  	}
+  	switch (count($options)) {
+  		case 0:
+        $form['uc_paybox_typepaiement'] = array(
+          '#type' => 'hidden',
+          '#value' => 'ALL',
+        );
+  			break;
+  			
+  		case 1:
+  			$value = array_keys($options);
+  			$value = $value[0];
+        $form['uc_paybox_typepaiement'] = array(
+          '#type' => 'hidden',
+          '#value' => $value,
+        );
+  			break;
+  			
+  		default:
+        $form['uc_paybox_typepaiement'] = array(
+          '#type' => 'radios',
+          '#title' => t('Payment Type'),
+          '#default_value' => $order->payment_details['uc_paybox_typepaiement'],
+          '#options' => $options,
+          '#required' => TRUE,
+        );
+  			break;
+  	}
+	}
+	
+  return $form;
+}
+
+/**
+ * Caches payment details on a pageload for use in various functions.
+ *
+ * @param $op
+ *   The cache operation to perform; either 'save', 'load', or 'clear'.
+ * @param $data
+ *   The serialized string containing the payment data.
+ * @return
+ *   An array of payment details.
+ */
+function uc_paybox_cache($op, $data = NULL) {
+  // The payment data will be stored in this static variable.
+  static $uc_paybox_cache = array();
+
+  if ($op == 'save') {
+    $uc_paybox_cache = unserialize($data);
+  }
+  elseif ($op == 'clear') {
+    $uc_paybox_cache = array();
+  }
+
+  return $uc_paybox_cache;
+}
+
 /**
  * function to check paybox server ip when payment notification and auto notification
  */
@@ -374,3 +501,38 @@ function _uc_paybox_currency($paybox = T
   $paybox ? $output = $paybox_currency : $output = $currency;
   return $output;
 }
+/**
+ * Define payment types available, see paybox doc
+ */
+function _uc_paybox_payment_type() {
+  $paybox_payment_type = array(
+    'CARTE|CB' => t('Carte Bleue'),
+    'CARTE|VISA' => t('VISA'),
+    'CARTE|EUROCARD_MASTERCARD' => t('MasterCard'),
+    'CARTE|E_CARD' => t('E-Bleue'),
+    'CARTE|AMEX' => t('American Express'),
+    'CARTE|DINERS' => t('Diner\'s Club'),
+    'CARTE|JCB' => t('JCB'),
+    'CARTE|COFINOGA' => t('Cofinoga'),
+    'CARTE|SOFINCO' => t('Sofinco'),
+    'CARTE|AURORE' => t('Aurore'),
+    'CARTE|CDGP' => t('CDGP'),
+    'CARTE|24h00' => t('24h00'),
+    'CARTE|RIVEGAUCHE' => t('Rive Gauche'),
+    'SYMPASS|CB' => t('Carte Bleue (Sympass)'),
+    'SYMPASS|VISA' => t('VISA (Sympass)'),
+    'SYMPASS|EUROCARD_MASTERCARD' => t('MasterCard (Sympass)'),
+    'SYMPASS|E_CARD' => t('E-Bleue (Sympass)'),
+    'SYMPASS|AMEX' => t('American Express (Sympass)'),
+    'SYMPASS|DINERS' => t('Diner\'s Club (Sympass)'),
+    'SYMPASS|JCB' => t('JCB (Sympass)'),
+    'SYMPASS|AURORE' => t('Aurore (Sympass)'),
+    'PAYNOVA|PAYNOVA' => t('Paynova'),
+    'TERMINEO|TERMINEO' => t('Termineo'),
+    'PAYPAL|PAYPAL' => t('Paypal'),
+    'UNEURO|UNEURO' => t('Un Euro'),
+    'NETRESERVE|NETCDGP' => t('CDGP (Netreserve)'),
+    'NETRESERVE|NETCOF' => t('Cofinoga (Netreserve)'),
+  );
+  return $paybox_payment_type;
+}
\ No newline at end of file
--- uc_paybox.pages.inc	2009-11-03 10:02:12.000000000 +0100
+++ uc_paybox.pages.inc.new	2009-11-03 13:00:54.000000000 +0100
@@ -18,6 +18,13 @@ function uc_paybox_payment() {
   }
   $order = uc_order_load($_SESSION['cart_order']);
   // request construction
+  if (isset($_SESSION['sespb'])) {
+    $payment_details = unserialize($_SESSION['sespb']);
+    list($type_paiement, $type_carte) = explode('|', $payment_details['uc_paybox_typepaiement']);
+    $chaine['type_paiement'] = " PBX_TYPEPAIEMENT=". $type_paiement;
+    $chaine['type_carte'] = " PBX_TYPECARTE=". $type_carte;
+  }
+  
   $chaine['mode'] = " PBX_MODE=4";
   if (variable_get('uc_paybox_site', '') == '') {
     $chaine['site'] = " PBX_SITE=1999888";
