class WC_Gateway_MyGateway extends WC_Payment_Gateway { public function __construct() { $this->id = 'mygateway'; $this->method_title = 'My Payment Gateway'; $this->method_description = 'Pay using MyGateway API'; $this->has_fields = false; $this->init_form_fields(); $this->init_settings(); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); } public function process_payment($order_id) { // 1️⃣ Get the WooCommerce order $order = wc_get_order($order_id); // 2️⃣ Prepare API request data $api_key = $this->get_option('api_key'); // Admin saved API key $body = array( 'amount' => $order->get_total(), 'currency' => $order->get_currency(), 'order_id' => $order->get_id(), 'api_key' => $api_key ); // 3️⃣ Send POST request to 3rd-party API $response = wp_remote_post('https://api.yourgateway.com/pay', array( 'method' => 'POST', 'body' => $body, 'timeout' => 60, 'headers' => array('Accept' => 'application/json') )); // 4️⃣ Handle response if (is_wp_error($response)) { wc_add_notice('Payment failed: Unable to connect to payment gateway.', 'error'); return; } $response_body = wp_remote_retrieve_body($response); $result = json_decode($response_body, true); if ($result['status'] === 'success') { // Payment succeeded $order->payment_complete(); // WooCommerce handles stock, emails, etc. return array( 'result' => 'success', 'redirect' => $this->get_return_url($order) ); } else { // Payment failed wc_add_notice('Payment failed: ' . $result['message'], 'error'); return; } } Contact -
Group of diverse kids collaborating on a 3D printing project using a laptop and other devices.

Get in Touch with EZlabstudio Today

We Would Love to Hear from You Soon

P: +251 932 1996 00
E: demissiehenok4@gmail.com
A: 2360 Hood Avenue, San Diego, CA, 92123
Follow me on Facebook
Follow me on X
Follow me on Instagram
Follow me on LinkedIn
Watch me on YouTube
This field is required.

Join Our Community

Stay Updated on Our Latest Designs!

Subscribe for exclusive offers and be the first to see our new 3D-printed creations.

Scroll to Top
0

Subtotal