1

I want to add a payment method on my site which is using Commerce kickstart on Drupal 7. Someone told me that I have to write a payment module, which I tried to do.
The problem is that after installation, my payment method doesn't appear on payments methods on the administration page.

What I am trying to do is collect some information about the order (e.g., order ID, order total amount, customer name) and post them to an external page.

I used the PayPal Payments Standard (WPS) module (a submodule of Commerce PayPal) and the Commerce ATOS Credit Card Payment module (a submodule of Commerce Atos) as reference to write my own code.

        /**
         * @file
         * Implements Mobile Money Standard in Drupal Commerce checkout.
         */

        /**
         * Implements hook_commerce_payment_method_info().
         */
        function commerce_mobile_money_commerce_payment_method_info() {
          $payment_methods = array();

          $payment_methods['mobile_money'] = array(
            'base' => 'commerce_mobile_money',
            'title' => t('Mobile Money'),
            'display_title ' => t('pay with <img src="image/mobile-money.jpg" style="width:37px; height:21px;" alt="mobile money"> '),
            'short_title' => t('MOBILEMO'),
            'description' => t('Mobile Money payment base on wecashup'),
            'terminal' => FALSE,
            'offsite' => TRUE,
            'offsite_autoredirect' => TRUE,
          );

          return $payment_methods;
        }

        function commerce_mobile_money_settings_form($settings = NULL) {
          $form = array();

         $wrapper = entity_metadata_wrapper('commerce_order', $order);
         $amount = $wrapper->commerce_order_total->amount->value();

          $form['amount'] = array(
            '#type' => 'textfield',
            '#title' => t('total order amount'),
            '#default_value' => $amount,
          );

          $form['order_id'] = array(
            '#type' => 'textfield',
            '#title' => t('unique id of order'),
            '#default_value' => $order->order_id,
          );
          $form['show_payment_instructions'] = array(
            '#type' => 'checkbox',
            '#title' => t('Show a message on the checkout form when Mobile Money is selected telling the customer to "Continue with checkout to complete payment via Mobile Money."'),
            '#default_value' => $settings['show_payment_instructions'],
          );
          return $form;
        }

        /**
         * Payment method callback: adds a message to the submission form if enabled in
         * the payment method settings.
         */
        function commerce_mobile_money_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
          $form = array();

          if (!empty($payment_method['settings']['mobile_money_instructions'])) {
            $form['mobile_money_information'] = array(
              '#markup' => '<span style="color:green;">' . t('(continuer pour payer avec mobile money.)') . '</span>',
            );
          }

          return $form;
        }

        /**
         * Payment method callback: redirect form, a wrapper around the module's general
         *   use function for building a MOBILEMO form.
         */
        function commerce_mobile_money_redirect_form($form, &$form_state, $order, $payment_method) {

          $settings = array(
            // Return to the previous page when payment is canceled
            'cancel_return' => url('checkout/' . $order->order_id . '/payment/back/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)),

            // Return to the payment redirect page for processing successful payments
            'return' => url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)),

            // Specify the current payment method instance ID in the notify_url
            'payment_method' => $payment_method['instance_id'],

            // Include the application indicator
            'bn' => $payment_method['buttonsource'],
          );

          return commerce_mobile_money_order_form($form, $form_state, $order, $payment_method['settings'] + $settings);
        }

        /**
         * Builds a Website Payments Standard form from an order object
         * @param $order
         *   The fully loaded order being paid for.
         * @return
         *   A renderable form array.
         */
        function commerce_mobile_money_order_form($form, &$form_state, $order, $settings) {

          $form['#action'] = "https://noebis.com/fr/payer-par-mobile-money";

          $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Proceed to MOBILEMO'),
          );

          return $form;
        }

        function commerce_mobile_money_redirect_form_back($order, $payment_method) {
          // Try to find if a transaction has already been saved for this order and
          // this payment method.
          $transactions = commerce_payment_transaction_load_multiple(array(), array('instance_id' => $payment_method['instance_id'], 'status' => COMMERCE_PAYMENT_STATUS_PENDING, 'order_id' => $order->order_id));
          $transaction = array_pop($transactions);
          // Marks the transaction as Failed.
          if ($transaction) {
            $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
            $transaction->message = t("Cancellation of payment by the end user");
            commerce_payment_transaction_save($transaction);
          }
        }

I am sure there is an error somewhere, but I don't really know where.

My module folder just have two files (mobile_money_payment.module and mobile_money_payment.info) and an image folder.

closed as too broad by kiamlaluno Aug 26 '17 at 1:17

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.