Payment Method for Drupal Commerce

Go1 Vietnam Training

13 May 2015

Viet Nguyen - Quyen Bui

Declaration

<?php
/**
 * Implements hook_commerce_payment_method_info().
 */
function go1_example_commerce_payment_method_info() {
  return array(
    // Define method_id as the key of the array element
    'commerce_payment_example' => array(
      // string used as the base for the magically constructed callback names 
      // each of which will be defaulted to [base]_[callback] unless explicitly set 
      // defaults to the method_id
      'base' => 'commerce_payment_example',

      // Full title of the payment method
      'title' => t('Example Payment Gateway'),
      
      // Display title in the payment form, defaults to the full title
      'display_title' => t('Example Payment'),
      
      // Defaults to the title
      'short_title' => t('Example'),
      
      // Description of the payment method
      'description' => t('Provides integration with the Swipe HQ payment gateway.'),

      // Indicating whether this payment method configuration is enabled or not
      'active' => TRUE,

      // indicating whether or not the customer must be redirected offsite 
      // to put in their payment information
      'offsite' => TRUE,
      
      // indicating whether or not the customer should be automatically redirected 
      // on the checkout payment step
      'offsite_autoredirect' => FALSE,
      
      // callbacks for payment method operations
      'callbacks' => array(
        'settings_form' => 'commerce_payment_example_settings_form',
        
        'submit_form' => 'commerce_payment_example_submit_form',

        'submit_form_validate' => 'commerce_payment_example_submit_form_validate',

        'submit_form_submit' => 'commerce_payment_example_submit_form_submit',

        'redirect_form' => 'commerce_payment_example_redirect_form',

        'redirect_form_validate' => 'commerce_payment_example_redirect_form_validate',

        'redirect_form_submit' => 'commerce_payment_example_redirect_form_submit',
      ),
      
      // File to include all callbacks of this payment method
      'file' => 'go1_example.pages.inc',
    ),
  );
}

Implementation

...
'callbacks' => array(
  // Settings form for the payment method
  'settings_form' => 'commerce_payment_example_settings_form',
  
  // Form elements to collect details required to process the payment
  'submit_form' => 'commerce_payment_example_submit_form',

  // Validate input data from submit_form
  'submit_form_validate' => 'commerce_payment_example_submit_form_validate',
  
  // Process input data to create a new payment transaction
  'submit_form_submit' => 'commerce_payment_example_submit_form_submit',

  // Returns form elements that should be submitted to the redirected payment service
  'redirect_form' => 'commerce_payment_example_redirect_form',
  
  // Validate any returned data upon return from a redirected payment service
  // before proceeding to checkout completion
  'redirect_form_validate' => 'commerce_payment_example_redirect_form_validate',

  // Do anything required before proceeding to checkout completion
  // e.g. update payment transaction status
  'redirect_form_submit' => 'commerce_payment_example_redirect_form_submit',
),
...

Examples

References

Q & A

Thank you !

Made with Slides.com