| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace MultiSafepay\WooCommerce\Utils; |
| 4 |
|
| 5 |
use WC_Order; |
| 6 |
|
| 7 |
/** |
| 8 |
* This class defines methods to handle easily different actions related with the WC_Order object |
| 9 |
*/ |
| 10 |
class Order { |
| 11 |
|
| 12 |
/** |
| 13 |
* Check if the order is a MultiSafepay order |
| 14 |
* |
| 15 |
* @param WC_Order $order |
| 16 |
* @return bool |
| 17 |
*/ |
| 18 |
public static function is_multisafepay_order( WC_Order $order ): bool { |
| 19 |
if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) { |
| 20 |
return true; |
| 21 |
} |
| 22 |
|
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Add a note to the order |
| 28 |
* |
| 29 |
* @param WC_Order $order |
| 30 |
* @param string $message |
| 31 |
* @param bool $on_debug |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public static function add_order_note( WC_Order $order, string $message, bool $on_debug = false ): void { |
| 35 |
if ( $on_debug && ! get_option( 'multisafepay_debugmode', false ) ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
$order->add_order_note( $message ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Return WooCommerce Order ID where meta value key is 'multisafepay_transaction_id' and value is $order_id |
| 44 |
* |
| 45 |
* @param string $order_id |
| 46 |
* @return false|mixed|\WC_Order |
| 47 |
* |
| 48 |
* @phpcs:disable WordPress.DB.SlowDBQuery |
| 49 |
*/ |
| 50 |
public static function get_order_id_by_multisafepay_transaction_id_key( string $order_id ) { |
| 51 |
$orders = wc_get_orders( |
| 52 |
array( |
| 53 |
'limit' => 1, |
| 54 |
'meta_key' => 'multisafepay_transaction_id', |
| 55 |
'meta_value' => $order_id, |
| 56 |
'return' => 'ids', |
| 57 |
) |
| 58 |
); |
| 59 |
return ! empty( $orders ) ? $orders[0] : false; |
| 60 |
} |
| 61 |
} |
| 62 |
|