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; } } Uncategorized -

Spiral Fidget Cone

Smooth spiral fidget cone.
Price range: $6.00 through $8.00
View Details

Jesus Cross (Keychain / Necklace)

Jesus Cross keychain / necklace
Price range: $8.00 through $11.00
View Details
Scroll to Top
0

Subtotal