diff --git a/assets/images/svg/mobilepay.logo.svg b/assets/images/svg/mobilepay.logo.svg new file mode 100644 index 00000000..23681fa3 --- /dev/null +++ b/assets/images/svg/mobilepay.logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/includes/Actions/Subscriptions.php b/includes/Actions/Subscriptions.php index d279bd80..08bf1f9e 100644 --- a/includes/Actions/Subscriptions.php +++ b/includes/Actions/Subscriptions.php @@ -176,9 +176,10 @@ public function update_failing_payment_method( WC_Subscription $subscription, WC public function delete_resubscribe_meta( WC_Order $resubscribe_order ) { if ( in_array( $resubscribe_order->get_payment_method(), self::PAYMENT_METHODS, true ) ) { // Delete tokens. - delete_post_meta( $resubscribe_order->get_id(), '_payment_tokens' ); - delete_post_meta( $resubscribe_order->get_id(), '_reepay_token' ); - delete_post_meta( $resubscribe_order->get_id(), '_reepay_token_id' ); + $resubscribe_order->delete_meta_data( '_payment_tokens' ); + $resubscribe_order->delete_meta_data( '_reepay_token' ); + $resubscribe_order->delete_meta_data( '_reepay_token_id' ); + $resubscribe_order->save_meta_data(); } } @@ -256,7 +257,8 @@ public function save_subscription_payment_meta( WC_Subscription $subscription, s // Add tokens. foreach ( explode( ',', $meta_value ) as $reepay_token ) { ReepayTokens::assign_payment_token( $subscription, $reepay_token ); - update_post_meta( $subscription->get_id(), 'reepay_token', $reepay_token ); + $subscription->update_meta_data( 'reepay_token', $reepay_token ); + $subscription->save_meta_data(); } } } @@ -362,6 +364,12 @@ public function scheduled_subscription_payment( float $amount_to_charge, WC_Orde throw new Exception( $result->get_error_message(), $result->get_error_code() ); } + // Fix for subscriptions can create the invoice + sleep(5); + if($renewal_order->get_status() == 'pending'){ + sleep(5); + } + // Instant settle. do_action( 'reepay_instant_settle', $renewal_order ); } catch ( Exception $e ) { @@ -467,7 +475,7 @@ public function save_new_payment_method_option_html( string $html, WC_Payment_Ga */ public function create_sub_invoice( int $order_id, string $this_status_transition_from, string $this_status_transition_to, WC_Order $instance ) { $renewal_order = wc_get_order( $order_id ); - $renewal_sub = get_post_meta( $order_id, '_subscription_renewal', true ); + $renewal_sub = $renewal_order->get_meta( '_subscription_renewal' ); $gateway = rp_get_payment_method( $renewal_order ); if ( ! empty( $renewal_sub ) && ! empty( $gateway ) ) { $order_data = reepay()->api( $gateway )->get_invoice_data( $renewal_order ); @@ -498,7 +506,9 @@ public function create_sub_invoice( int $order_id, string $this_status_transitio */ public function sync_reepay_token_meta( int $meta_id, int $post_id, string $meta_key, $meta_value ) { if ( 'reepay_token' === $meta_key ) { - update_post_meta( $post_id, '_reepay_token', $meta_value ); + $order = wc_get_order( $post_id ); + $order->update_meta_data( '_reepay_token', $meta_value ); + $order->save_meta_data(); } } } diff --git a/includes/Admin/MetaBoxes.php b/includes/Admin/MetaBoxes.php index 656e3c2d..83c76086 100644 --- a/includes/Admin/MetaBoxes.php +++ b/includes/Admin/MetaBoxes.php @@ -8,6 +8,7 @@ namespace Reepay\Checkout\Admin; use Automattic\WooCommerce\Utilities\OrderUtil; +use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Exception; use Reepay\Checkout\Gateways\ReepayCheckout; use WC_Order; @@ -39,85 +40,77 @@ public function __construct() { * Register meta boxes on order page */ public function add_meta_boxes() { - $screen = get_current_screen(); - $post_types = array( 'shop_order', 'shop_subscription' ); + $screen = wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() + ? wc_get_page_screen_id( 'shop-order' ) + : 'shop_order'; - if ( OrderUtil::custom_orders_table_usage_is_enabled() ) { - $post_types[] = 'woocommerce_page_wc-orders'; + $order_id = !empty($_GET['id']) ? $_GET['id'] : $_GET['post']; + $order = wc_get_order( $order_id ); + if($order){ + $order_data = $order->get_data(); - $post = get_post( wc_clean( $_GET['id'] ?? 0 ) ); - } else { - global $post; - } - - if ( empty( $post ) || ! in_array( $screen->id, $post_types, true ) || ! in_array( $post->post_type, $post_types, true ) ) { - return; - } - - $order = wc_get_order( $post->ID ); - - if ( empty( $order ) || ! rp_is_order_paid_via_reepay( $order ) ) { - return; - } - $gateway = rp_get_payment_method( $order ); + if ( empty( $order ) || ! rp_is_order_paid_via_reepay( $order ) ) { + return; + } - if ( empty( $gateway ) ) { - return; - } + $gateway = rp_get_payment_method( $order ); - if ( ! empty( get_post_meta( $post->ID, '_reepay_order', true ) ) && 0 !== $post->post_parent ) { - $subscription = get_post_meta( $post->post_parent, '_reepay_subscription_handle', true ); - } elseif ( ! empty( get_post_meta( $post->ID, '_reepay_subscription_handle_parent', true ) ) ) { - $subscription = get_post_meta( $post->ID, '_reepay_subscription_handle_parent', true ); - } else { - $subscription = get_post_meta( $post->ID, '_reepay_subscription_handle', true ); - } + if ( empty( $gateway ) ) { + return; + } - add_meta_box( - 'reepay_checkout_customer', - __( 'Customer', 'reepay-checkout-gateway' ), - array( $this, 'generate_meta_box_content_customer' ), - $screen->id, - 'side', - 'high', - array( - 'order' => $order, - 'gateway' => $gateway, - 'post' => $post, - ) - ); + if ( ! empty( $order->get_meta( '_reepay_order' ) ) && 0 !== $order_data['parent_id'] ) { + $parent_order = wc_get_order( $order_data['parent_id'] ); + $subscription = $parent_order->get_meta( '_reepay_subscription_handle' ); + } elseif ( ! empty( $order->get_meta( '_reepay_subscription_handle_parent' ) ) ) { + $subscription = $order->get_meta( '_reepay_subscription_handle_parent' ); + } else { + $subscription = $order->get_meta( '_reepay_subscription_handle' ); + } - if ( ! empty( get_post_meta( $post->ID, '_transaction_id', true ) ) ) { add_meta_box( - 'reepay_checkout_invoice', - __( 'Invoice', 'reepay-checkout-gateway' ), - array( $this, 'generate_meta_box_content_invoice' ), - $screen->id, + 'reepay_checkout_customer', + __( 'Customer', 'reepay-checkout-gateway' ), + array( $this, 'generate_meta_box_content_customer' ), + $screen, 'side', 'high', array( 'order' => $order, 'gateway' => $gateway, - 'post' => $post, ) ); - } - if ( ! empty( $subscription ) ) { - add_meta_box( - 'reepay_checkout_subscription', - __( 'Subscription', 'reepay-checkout-gateway' ), - array( $this, 'generate_meta_box_content_subscription' ), - $screen->id, - 'side', - 'high', - array( - 'order' => $order, - 'gateway' => $gateway, - 'post' => $post, - ) - ); + if ( ! empty( $order->get_transaction_id() ) ) { + add_meta_box( + 'reepay_checkout_invoice', + __( 'Invoice', 'reepay-checkout-gateway' ), + array( $this, 'generate_meta_box_content_invoice' ), + $screen, + 'side', + 'high', + array( + 'order' => $order, + 'gateway' => $gateway, + ) + ); + } + + if ( ! empty( $subscription ) ) { + add_meta_box( + 'reepay_checkout_subscription', + __( 'Subscription', 'reepay-checkout-gateway' ), + array( $this, 'generate_meta_box_content_subscription' ), + $screen, + 'side', + 'high', + array( + 'order' => $order, + 'gateway' => $gateway, + ) + ); + } } } @@ -133,16 +126,15 @@ public function generate_meta_box_content_customer( $x, array $meta ) { * * @var WC_Order $order * @var ReepayCheckout $gateway - * @var WP_Post $post */ $order = $meta['args']['order']; - $gateway = $meta['args']['gateway']; - $post = $meta['args']['post']; + $order_data = $order->get_data(); - if ( ! empty( get_post_meta( $post->ID, '_reepay_order', true ) ) && 0 !== $post->post_parent ) { - $handle = get_post_meta( $post->post_parent, '_reepay_customer', true ); + if ( ! empty( $order->get_meta( '_reepay_order' ) ) && 0 !== $order_data['parent_id'] ) { + $parent_order = wc_get_order( $order_data['parent_id'] ); + $handle = $parent_order->get_meta('_reepay_customer'); } else { - $handle = get_post_meta( $post->ID, '_reepay_customer', true ); + $handle = $order->get_meta( '_reepay_customer' ); } if ( empty( $handle ) ) { @@ -150,7 +142,7 @@ public function generate_meta_box_content_customer( $x, array $meta ) { } $template_args = array( - 'email' => get_post_meta( $post->ID, '_billing_email', true ), + 'email' => $order->get_billing_email(), 'handle' => $handle, 'link' => $this->dashboard_url . 'customers/customers/customer/' . $handle, ); @@ -173,11 +165,9 @@ public function generate_meta_box_content_invoice( $x, array $meta ) { * * @var WC_Order $order * @var ReepayCheckout $gateway - * @var WP_Post $post */ $order = $meta['args']['order']; $gateway = $meta['args']['gateway']; - $post = $meta['args']['post']; $order_data = reepay()->api( $gateway )->get_invoice_data( $order ); @@ -218,21 +208,21 @@ public function generate_meta_box_content_subscription( $x, array $meta ) { * * @var WC_Order $order * @var ReepayCheckout $gateway - * @var WP_Post $post */ $order = $meta['args']['order']; $gateway = $meta['args']['gateway']; - $post = $meta['args']['post']; - - if ( ! empty( get_post_meta( $post->ID, '_reepay_order', true ) ) && 0 !== $post->post_parent ) { - $handle = get_post_meta( $post->post_parent, '_reepay_subscription_handle', true ); - $plan = get_post_meta( $post->post_parent, '_reepay_subscription_plan', true ); - } elseif ( get_post_meta( $post->ID, '_reepay_renewal', true ) ) { - $handle = get_post_meta( $post->ID, '_reepay_subscription_handle_parent', true ); - $plan = get_post_meta( $post->ID, '_reepay_subscription_plan', true ); + $order_data = $order->get_data(); + + if ( ! empty( $order->get_meta( '_reepay_order' ) ) && 0 !== $order_data['parent_id'] ) { + $parent_order = wc_get_order( $order_data['parent_id'] ); + $handle = $parent_order->get_meta( '_reepay_subscription_handle' ); + $plan = $parent_order->get_meta( '_reepay_subscription_plan' ); + } elseif ( $order->get_meta( '_reepay_renewal' ) ) { + $handle = $order->get_meta( '_reepay_subscription_handle_parent' ); + $plan = $order->get_meta( '_reepay_subscription_plan' ); } else { - $handle = get_post_meta( $post->ID, '_reepay_subscription_handle', true ); - $plan = get_post_meta( $post->ID, '_reepay_subscription_plan', true ); + $handle = $order->get_meta( '_reepay_subscription_handle' ); + $plan = $order->get_meta( '_reepay_subscription_plan' ); } $template_args = array( @@ -244,7 +234,8 @@ public function generate_meta_box_content_subscription( $x, array $meta ) { try { $subscription = reepay_s()->api()->request( "subscription/{$template_args['handle']}" ); $template_args['plan'] = $subscription['plan']; - update_post_meta( $post->ID, '_reepay_subscription_plan', $subscription['plan'] ); + $order->update_meta_data( '_reepay_subscription_plan', $subscription['plan'] ); + $order->save_meta_data(); } catch ( Exception $e ) { //phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch // Do not show subscription plan name if api error. } diff --git a/includes/Api.php b/includes/Api.php index 96817230..1495f5a9 100644 --- a/includes/Api.php +++ b/includes/Api.php @@ -972,8 +972,8 @@ private function process_charge_result( WC_Order $order, array $result ) { break; case 'settled': - update_post_meta( $order->get_id(), '_reepay_capture_transaction', $result['transaction'] ); - + $order->update_meta_data( '_reepay_capture_transaction', $result['transaction'] ); + $order->save_meta_data(); OrderStatuses::set_settled_status( $order, sprintf( @@ -987,8 +987,8 @@ private function process_charge_result( WC_Order $order, array $result ) { break; case 'cancelled': - update_post_meta( $order->get_id(), '_reepay_cancel_transaction', $result['transaction'] ); - + $order->update_meta_data( '_reepay_cancel_transaction', $result['transaction'] ); + $order->save_meta_data(); if ( ! $order->has_status( 'cancelled' ) ) { $order->update_status( 'cancelled', diff --git a/includes/Gateways/ReepayCheckout.php b/includes/Gateways/ReepayCheckout.php index a3a4df94..3f09e10f 100644 --- a/includes/Gateways/ReepayCheckout.php +++ b/includes/Gateways/ReepayCheckout.php @@ -82,7 +82,7 @@ public function __construct() { $this->payment_methods = $this->settings['payment_methods'] ?: $this->payment_methods; $this->skip_order_lines = $this->settings['skip_order_lines'] ?: $this->skip_order_lines; $this->failed_webhooks_email = $this->settings['failed_webhooks_email'] ?: $this->failed_webhooks_email; - $this->handle_failover = $this->settings['handle_failover'] ?: $this->handle_failover; + $this->handle_failover = !empty($this->settings['handle_failover']) ?: $this->handle_failover; if ( 'yes' === $this->save_cc ) { $this->supports[] = 'add_payment_method'; diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 57b467d9..4097ab07 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -911,7 +911,8 @@ public function process_payment( $order_id ) { } if ( ! empty( $result['id'] ) ) { - update_post_meta( $order_id, 'reepay_session_id', $result['id'] ); + $order->update_meta_data( 'reepay_session_id', $result['id'] ); + $order->save_meta_data(); } if ( is_wp_error( $result ) ) { @@ -1039,7 +1040,8 @@ public function process_payment( $order_id ) { } if ( ! empty( $result['id'] ) ) { - update_post_meta( $order_id, 'reepay_session_id', $result['id'] ); + $order->update_meta_data( 'reepay_session_id', $result['id'] ); + $order->save_meta_data(); } do_action( 'reepay_instant_settle', $order ); @@ -1208,7 +1210,8 @@ public function process_session_charge( array $params, WC_Order $order ): array $handle = rp_get_order_handle( $order, true ); $params['order']['handle'] = $handle; - update_post_meta( $order->get_id(), '_reepay_order', $handle ); + $order->update_meta_data( '_reepay_order', $handle ); + $order->save_meta_data(); $result = reepay()->api( $this )->request( 'POST', @@ -1242,7 +1245,8 @@ public function process_session_charge( array $params, WC_Order $order ): array } if ( ! empty( $result['id'] ) ) { - update_post_meta( $order->get_id(), 'reepay_session_id', $result['id'] ); + $order->update_meta_data( 'reepay_session_id', $result['id'] ); + $order->save_meta_data(); } if ( is_checkout_pay_page() ) { diff --git a/includes/OrderFlow/Webhook.php b/includes/OrderFlow/Webhook.php index 98b10d86..fc02403c 100644 --- a/includes/OrderFlow/Webhook.php +++ b/includes/OrderFlow/Webhook.php @@ -263,7 +263,8 @@ public function process( array $data ) { ); } - update_post_meta( $order->get_id(), '_reepay_capture_transaction', $data['transaction'] ); + $order->update_meta_data( '_reepay_capture_transaction', $data['transaction'] ); + $order->save_meta_data(); self::unlock_order( $order->get_id() ); @@ -329,7 +330,7 @@ public function process( array $data ) { return; } - $sub_order = get_post_meta( $order->get_id(), '_reepay_subscription_handle', true ); + $sub_order = $order->get_meta( '_reepay_subscription_handle' ); if ( ! empty( $sub_order ) ) { return; } @@ -484,7 +485,9 @@ public function process( array $data ) { * @see wait_for_unlock() */ private static function lock_order( int $order_id ) { - update_post_meta( $order_id, '_reepay_locked', '1' ); + $order = wc_get_order( $order_id ); + $order->update_meta_data( '_reepay_locked', '1' ); + $order->save_meta_data(); } /** @@ -496,7 +499,9 @@ private static function lock_order( int $order_id ) { * @see wait_for_unlock() */ private static function unlock_order( $order_id ) { - delete_post_meta( $order_id, '_reepay_locked' ); + $order = wc_get_order( $order_id ); + $order->delete_meta_data( '_reepay_locked' ); + $order->save_meta_data(); } /** @@ -509,7 +514,8 @@ private static function unlock_order( $order_id ) { private static function wait_for_unlock( int $order_id ): bool { set_time_limit( 0 ); - $is_locked = (bool) get_post_meta( $order_id, '_reepay_locked', true ); + $order = wc_get_order( $order_id ); + $is_locked = (bool) $order->get_meta( '_reepay_locked' ); $needs_reload = false; $attempts = 0; while ( $is_locked ) { @@ -520,7 +526,7 @@ private static function wait_for_unlock( int $order_id ): bool { } wp_cache_delete( $order_id, 'post_meta' ); - $is_locked = (bool) get_post_meta( $order_id, '_reepay_locked', true ); + $is_locked = (bool) $order->get_meta( '_reepay_locked' ); if ( $is_locked ) { $needs_reload = true; clean_post_cache( $order_id ); diff --git a/includes/Tokens/ReepayTokens.php b/includes/Tokens/ReepayTokens.php index b1ae0bc6..af4e3298 100644 --- a/includes/Tokens/ReepayTokens.php +++ b/includes/Tokens/ReepayTokens.php @@ -44,12 +44,12 @@ public static function assign_payment_token( WC_Order $order, $token ) { } if ( $token->get_id() ) { - // Delete tokens if exist. - delete_post_meta( $order->get_id(), '_payment_tokens' ); + // Reload order. $order = wc_get_order( $order->get_id() ); - + // Delete tokens if exist. + $order->delete_meta_data( '_payment_tokens' ); // Add payment token. $order->add_payment_token( $token ); diff --git a/templates/checkout/thankyou.php b/templates/checkout/thankyou.php index b3ef34a6..97d3ae8e 100644 --- a/templates/checkout/thankyou.php +++ b/templates/checkout/thankyou.php @@ -31,7 +31,7 @@ get_id(), '_reepay_another_orders', true ) ?: array(); + $another_orders = $order->get_meta( '_reepay_another_orders' ) ?: array(); do_action( 'woocommerce_before_thankyou', $order->get_id() ); ?> diff --git a/templates/meta-boxes/invoice.php b/templates/meta-boxes/invoice.php index d2de0fc7..d5bd1b95 100644 --- a/templates/meta-boxes/invoice.php +++ b/templates/meta-boxes/invoice.php @@ -23,6 +23,10 @@ ?>