Changeset 3400022
- Timestamp:
- 11/20/2025 08:25:41 PM (5 months ago)
- File:
-
- 1 edited
-
maaly-pay/trunk/maaly-pay.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
maaly-pay/trunk/maaly-pay.php
r3399551 r3400022 27 27 define('MAALY_PAY_PLUGIN_URL', plugin_dir_url(__FILE__)); 28 28 29 define('MAALY_PAY_ABS_PLUGIN_URL', trailingslashit( plugin_dir_path( __FILE__ )));30 define('MAALY_PAY_REL_PLUGIN_URL', untrailingslashit( plugins_url( '/', __FILE__ )));29 define('MAALY_PAY_ABS_PLUGIN_URL', trailingslashit(plugin_dir_path(__FILE__))); 30 define('MAALY_PAY_REL_PLUGIN_URL', untrailingslashit(plugins_url('/', __FILE__))); 31 31 32 32 // ----------------------------------------------------------------------------- … … 194 194 : ''); 195 195 196 // $status = isset($data['status']) ? $data['status'] : null;197 198 196 if (empty($merchantTxId)) { 199 197 status_header(400); … … 202 200 } 203 201 204 $orders = wc_get_orders([ 205 'limit' => 1, 206 'meta_key' => 'maaly_merchant_tx_id', 207 'meta_value' => $merchantTxId, 208 ]); 209 210 if (empty($orders)) { 211 status_header(404); 212 echo 'Order not found'; 213 exit; 214 } 215 216 $order = $orders[0]; 217 $order->add_order_note('Maaly callback received: ' . wp_json_encode($data)); 218 219 // if (!is_null($status)) { 220 // $completed = false; 221 // if (is_string($status)) { 222 // $s = strtolower($status); 223 // $completed = in_array($s, ['1', 'true', 'completed', 'success']); 224 // } elseif (is_bool($status)) { 225 // $completed = $status; 226 // } elseif (is_numeric($status)) { 227 // $completed = intval($status) === 1; 228 // } 229 230 // if ($completed) { 231 // $order->payment_complete(); 232 // $order->add_order_note('Payment completed via Maaly.'); 233 // } else { 234 // $order->update_status('failed', 'Payment not completed according to Maaly callback.'); 235 // } 236 // } 237 238 $order->payment_complete(); 239 $order->add_order_note('Payment completed via Maaly.'); 240 241 status_header(200); 242 echo 'OK'; 243 exit; 202 $api_key = get_option(Maaly_Pay_Settings::OPTION_KEY, ''); 203 $res = Maaly_Pay_API::check_transaction_status($merchantTxId, $api_key); 204 205 if (!isset($res['filledAmount'])) { 206 if (isset($res['status'])) { 207 echo "Payment is not initiated by customer yet."; 208 exit; 209 } 210 } else { 211 $status = isset($res['status']) ? isset($res['requestedAmount']) ? $res['status'] : false : false; 212 213 $orders = wc_get_orders([ 214 'limit' => 1, 215 'meta_key' => 'maaly_merchant_tx_id', 216 'meta_value' => $merchantTxId, 217 ]); 218 219 if (empty($orders)) { 220 status_header(404); 221 echo 'Order not found'; 222 exit; 223 } 224 225 $order = $orders[0]; 226 $order->add_order_note('Maaly callback received: ' . wp_json_encode($data)); 227 228 if ($status) { 229 $order->payment_complete(); 230 $order->add_order_note('Payment completed via Maaly.'); 231 232 status_header(200); 233 echo 'Payment Received'; 234 exit; 235 } else { 236 echo 'Waiting for payment...'; 237 exit; 238 } 239 } 244 240 }); 245 241 246 242 // BLOCK PAYMENT GATEWAY 247 add_action( 'woocommerce_blocks_loaded', function () {248 if ( !class_exists( \Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType::class )) {243 add_action('woocommerce_blocks_loaded', function () { 244 if (!class_exists(\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType::class)) { 249 245 return; 250 246 } … … 255 251 add_action( 256 252 'woocommerce_blocks_payment_method_type_registration', 257 function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {258 $payment_method_registry->register( new WC_MaalyGateway_Blocks());253 function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) { 254 $payment_method_registry->register(new WC_MaalyGateway_Blocks()); 259 255 } 260 256 );
Note: See TracChangeset
for help on using the changeset viewer.