Projet

Général

Profil

Révision dbb0c974

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/commerce/modules/payment/includes/commerce_payment.checkout_pane.inc
5 5
 * Callback functions for the Payment module's checkout panes.
6 6
 */
7 7

  
8
// Constants that govern the behavior of the payment method checkout pane when
9
// no payment methods are enabled for an order.
10
define('COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY', 'empty');
11
define('COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY_EVENT', 'empty_event');
12
define('COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE', 'message');
13
define('COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE_EVENT', 'message_event');
14

  
15

  
8 16
/**
9 17
 * Checkout pane callback: returns the payment pane's settings form.
10 18
 */
......
16 24
    '#title' => t('Require a payment method at all times, preventing checkout if none is available.'),
17 25
    '#default_value' => variable_get('commerce_payment_pane_require_method', FALSE),
18 26
  );
27
  $form['commerce_payment_pane_no_method_behavior'] = array(
28
    '#type' => 'radios',
29
    '#title' => t('Checkout pane behavior when no payment methods are enabled for an order'),
30
    '#description' => t('Note: regardless of your selection, no payment transaction will be created for the order upon checkout completion as they represent actual financial transactions.'),
31
    '#options' => array(
32
      COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY => t('Leave the payment checkout pane empty.'),
33
      COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY_EVENT => t('Leave the payment checkout pane empty and trigger <em>When an order is first paid in full</em> on submission of free orders.'),
34
      COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE => t('Display a message in the pane indicating payment is not required for the order.'),
35
      COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE_EVENT => t('Display a message in the pane indicating payment is not required and trigger <em>When an order is first paid in full</em> on submission of free orders.'),
36
    ),
37
    '#default_value' => variable_get('commerce_payment_pane_no_method_behavior', COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE),
38
    '#states' => array(
39
      'visible' => array(
40
        ':input[name="commerce_payment_pane_require_method"]' => array('checked' => FALSE),
41
      ),
42
    ),
43
  );
19 44

  
20 45
  return $form;
21 46
}
......
50 75
  // If no payment methods were found, return the empty form.
51 76
  if (empty($options)) {
52 77
    if (!variable_get('commerce_payment_pane_require_method', FALSE)) {
78
      $behavior = variable_get('commerce_payment_pane_no_method_behavior', COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE);
79

  
80
      switch ($behavior) {
81
        case COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE:
82
        case COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE_EVENT:
83
          $pane_form['message'] = array(
84
            '#markup' => '<div>' . t('Payment is not required to complete your order.') . '</div>',
85
          );
86
          break;
87

  
88
        case COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY:
89
        case COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY_EVENT:
90
        default:
91
          break;
92
      }
93

  
53 94
      return $pane_form;
54 95
    }
55 96
    else {
......
224 265
      }
225 266
    }
226 267
  }
268
  else {
269
    // If there were no payment methods on the form, check to see if the pane is
270
    // configured to trigger "When an order is first paid in full" on submission
271
    // for free orders.
272
    $behavior = variable_get('commerce_payment_pane_no_method_behavior', COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE);
273

  
274
    if (in_array($behavior, array(COMMERCE_PAYMENT_PANE_NO_METHOD_EMPTY_EVENT, COMMERCE_PAYMENT_PANE_NO_METHOD_MESSAGE_EVENT))) {
275
      // Check the balance of the order.
276
      $balance = commerce_payment_order_balance($order);
277

  
278
      if (!empty($balance) && $balance['amount'] <= 0) {
279
        // Trigger the event now for free orders, simulating payment being
280
        // submitted on pane submission that brings the balance to 0. Use an
281
        // empty transaction, as we wouldn't typically save a transaction where
282
        // a financial transaction has not actually occurred.
283
        rules_invoke_all('commerce_payment_order_paid_in_full', $order, commerce_payment_transaction_new('', $order->order_id));
284

  
285
        // Update the order's data array to indicate this just happened.
286
        $order->data['commerce_payment_order_paid_in_full_invoked'] = TRUE;
287
      }
288
    }
289
  }
227 290
}
228 291

  
229 292
/**

Formats disponibles : Unified diff