WooCommerce Development

Learn to build and customize e-commerce stores with WooCommerce.

intermediate Backend Development 5 hours

Chapter 5: Payment Gateway Integration

Chapter 5 of 15

Chapter 5: Payment Gateway Integration

5.1 Payment Methods

Configure payment gateways for accepting payments.

Built-in Payment Methods:

  • PayPal - Popular payment gateway
  • Stripe - Credit card processing
  • Bank transfer - Direct bank transfers
  • Cash on delivery - Pay on delivery
  • Check payments - Check payments
  • BACS - Bank account transfers

5.2 Payment Gateway Setup

Set up payment gateways properly.

  • Obtain API credentials from gateway provider
  • Configure gateway settings in WooCommerce
  • Test payment processing in sandbox mode
  • Enable for production after testing
  • Configure payment method restrictions
  • Set up webhook endpoints

5.3 Custom Payment Gateways

Develop custom payment gateways when needed.

function init_custom_gateway() {
    if (!class_exists('WC_Payment_Gateway')) {
        return;
    }
    
    class WC_Custom_Gateway extends WC_Payment_Gateway {
        public function __construct() {
            $this->id = 'custom_gateway';
            $this->method_title = 'Custom Gateway';
            $this->method_description = 'Custom payment gateway';
            $this->init_form_fields();
            $this->init_settings();
        }
        
        public function process_payment($order_id) {
            // Process payment logic
            return array(
                'result' => 'success',
                'redirect' => $this->get_return_url($order)
            );
        }
    }
}
add_action('plugins_loaded', 'init_custom_gateway');

5.4 Payment Gateway Testing

Test payment gateways thoroughly before going live.

  • Test in sandbox/test mode
  • Test various payment scenarios
  • Test error handling
  • Test refund processing
  • Verify webhook handling