diff --git a/commerce_no_payment.module b/commerce_no_payment.module index 56a559a..705a8ab 100644 --- a/commerce_no_payment.module +++ b/commerce_no_payment.module @@ -11,21 +11,45 @@ */ function commerce_no_payment_commerce_payment_method_info() { $payment_methods = array(); - $payment_methods['commerce_no_payment'] = array( 'title' => t('No payment required'), 'description' => t('Does a complete payment transaction with no payment required.'), - 'active' => TRUE, ); - return $payment_methods; } /** + * Payment method callback: settings form. + */ +function commerce_no_payment_settings_form($settings = NULL) { + $settings = (array) $settings + array( + 'information' => '', + 'enforce' => 1 + ); + $form = array(); + $form['information'] = array( + '#type' => 'textarea', + '#title' => t('Information'), + '#description' => t('Information you would like to be shown to users when they select this payment method.'), + '#default_value' => $settings['information'] + ); + $form['enforce'] = array( + '#type' => 'checkbox', + '#title' => t('Enforce 0 order balance'), + '#description' => t('Require an order balance of 0 for this payment method to validate.'), + '#default_value' => $settings['enforce'] + ); + return $form; +} + +/** * Payment method callback: submit form. */ function commerce_no_payment_submit_form($payment_method, $pane_values, $checkout_pane, $order) { $form = array(); + $form['commerce_no_payment_description'] = array( + '#markup' => filter_xss($payment_method['settings']['information']) + ); return $form; } @@ -33,9 +57,12 @@ function commerce_no_payment_submit_form($payment_method, $pane_values, $checkou * Payment method callback: submit form validation. */ function commerce_no_payment_submit_form_validate($payment_method, $pane_form, $pane_values, $order, $form_parents = array()) { - /* could possibly check orders for a balance of 0.00 - but then it wouldn't be useful for testing, as it wouldnt work on other orders - */ + $order->language = isset($order->language) ? $order->language : LANGUAGE_NONE; + $balance = $order->commerce_order_total[$order->language][0]['amount']; + if($payment_method['settings']['enforce'] && $balance > 0){ + form_set_error(implode('][', array_merge($form_parents, array('information'))), t('Order balance must be equal to zero for this payment method.')); + return FALSE; + } } /** @@ -62,6 +89,5 @@ function commerce_no_payment_transaction($payment_method, $order, $charge) { $transaction->amount = $charge['amount']; $transaction->currency_code = $charge['currency_code']; $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS; - commerce_payment_transaction_save($transaction); }