| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | +use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; | |
| 10 | 11 | use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper; |
| 11 | 12 | use WP_Post; |
| 12 | 13 | |
| 13 | 14 | /** |
| @@ -30,29 +31,18 @@ | ||
| 30 | 31 | * This metabox is only register if the current order has been paid via PayPlug. |
| 31 | 32 | */ |
| 32 | 33 | public function register_payplug_metabox() { |
| 33 | 34 | global $post; |
| 34 | - $screen = get_current_screen(); | |
| 35 | - if ( is_null( $screen ) || 'shop_order' !== $screen->post_type ) { | |
| 36 | - return; | |
| 37 | - } | |
| 38 | 35 | |
| 39 | - $order = wc_get_order( $post ); | |
| 40 | - if ( false === $order ) { | |
| 41 | - return; | |
| 42 | - } | |
| 36 | + $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() | |
| 37 | + ? function_exists("wc_get_page_screen_id") ? wc_get_page_screen_id( 'shop-order' ) : "shop_order" | |
| 38 | + : 'shop_order'; | |
| 43 | 39 | |
| 44 | - $payment_method = PayplugWoocommerceHelper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); | |
| 45 | - | |
| 46 | - if ( 'payplug' !== $payment_method && 'oney_x3_with_fees' !== $payment_method && 'oney_x4_with_fees' !== $payment_method) { | |
| 47 | - return; | |
| 48 | - } | |
| 49 | - | |
| 50 | 40 | add_meta_box( |
| 51 | 41 | 'payplug-transaction-details', |
| 52 | 42 | __( 'PayPlug payment details', 'payplug' ), |
| 53 | 43 | [ $this, 'render' ], |
| 54 | - 'shop_order', | |
| 44 | + $screen, | |
| 55 | 45 | 'side' |
| 56 | 46 | ); |
| 57 | 47 | } |
| 58 | 48 | |
| @@ -61,13 +51,19 @@ | ||
| 61 | 51 | * |
| 62 | 52 | * @param WP_Post $post |
| 63 | 53 | */ |
| 64 | 54 | public function render( $post ) { |
| 65 | - $order = wc_get_order( $post ); | |
| 55 | + | |
| 56 | + $order = ( $post instanceof WP_Post ) ? wc_get_order( $post->ID ) : $post; | |
| 57 | + | |
| 66 | 58 | if ( false === $order ) { |
| 67 | 59 | return; |
| 68 | 60 | } |
| 69 | 61 | |
| 62 | + if( !in_array($order->get_payment_method(), ['payplug', 'oney_x3_with_fees', 'oney_x4_with_fees', 'oney_x3_without_fees', 'oney_x4_without_fees','bancontact', 'apple_pay', 'american_express', 'satispay', 'sofort', 'ideal', 'mybank'])){ | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 70 | 66 | $metadata = PayplugWoocommerceHelper::get_transaction_metadata( $order ); |
| 71 | 67 | $date_format = get_option( 'date_format', 'j F Y' ); |
| 72 | 68 | $time_format = get_option( 'time_format', 'G \h i \m\i\n' ); |
| 73 | 69 | if ( empty( $metadata ) ) : ?> |
| @@ -83,25 +79,40 @@ | ||
| 83 | 79 | <?php elseif ( isset( $metadata['paid'] ) && true === $metadata['paid'] ) : _e( 'Paid', 'payplug' ); ?> |
| 84 | 80 | <?php else : _e( 'Not Paid', 'payplug' ); ?> |
| 85 | 81 | <?php endif; ?> |
| 86 | 82 | </li> |
| 83 | + <!-- PPRO methods don't have card brand info--> | |
| 84 | + <?php if( empty( $metadata['card_brand'] ) && $order->get_payment_method() != 'payplug' ){ ?> | |
| 85 | + <li><span><?php _e( 'payment_method', 'payplug' ); ?>:</span> <?php echo str_replace("_", " ",ucfirst($order->get_payment_method())); ?></li> | |
| 86 | + <?php } ?> | |
| 87 | 87 | <li><span><?php _e( 'Amount', 'payplug' ); ?> |
| 88 | 88 | :</span> <?php echo wc_price( (int) $metadata['amount'] / 100 ); ?></li> |
| 89 | 89 | <li><span><?php _e( 'Paid at', 'payplug' ); ?> |
| 90 | 90 | :</span> <?php echo ! empty( $metadata['paid_at'] ) ? esc_html( date_i18n( sprintf( '%s %s', $date_format, $time_format ), $metadata['paid_at'] ) ) : ''; ?> |
| 91 | 91 | </li> |
| 92 | - <li><span><?php _e( 'Credit card', 'payplug' ); ?> | |
| 93 | - :</span> <?php echo ! empty( $metadata['card_brand'] ) ? esc_html( sprintf( '%s (%s)', $metadata['card_brand'], $metadata['card_country'] ) ) : ''; ?> | |
| 94 | - </li> | |
| 95 | - <li><span><?php _e( 'Card mask', 'payplug' ); ?> | |
| 96 | - :</span> <?php echo ! empty( $metadata['card_last4'] ) ? esc_html( sprintf( '**** **** **** %s', $metadata['card_last4'] ) ) : ''; ?> | |
| 97 | - </li> | |
| 92 | + | |
| 93 | + <?php if(!empty( $metadata['card_brand'])){ ?> | |
| 94 | + <li><span><?php _e( 'Credit card', 'payplug' ); ?> | |
| 95 | + :</span> <?php echo ! empty( $metadata['card_brand'] ) ? esc_html( sprintf( '%s (%s)', $metadata['card_brand'], $metadata['card_country'] ) ) : ''; ?> | |
| 96 | + </li> | |
| 97 | + <?php } ?> | |
| 98 | + | |
| 99 | + <?php if(!empty( $metadata['card_last4'])){ ?> | |
| 100 | + <li><span><?php _e( 'Card mask', 'payplug' ); ?> | |
| 101 | + :</span> <?php echo ! empty( $metadata['card_last4'] ) ? esc_html( sprintf( '**** **** **** %s', $metadata['card_last4'] ) ) : ''; ?> | |
| 102 | + </li> | |
| 103 | + <?php } ?> | |
| 104 | + | |
| 98 | 105 | <li><span><?php _e( '3 D Secure', 'payplug' ); ?> |
| 99 | 106 | :</span> <?php echo isset( $metadata['3ds'] ) ? true === $metadata['3ds'] ? __( 'Yes', 'payplug' ) : __( 'No', 'payplug' ) : ''; ?> |
| 100 | 107 | </li> |
| 101 | - <li><span><?php _e( 'Expiration date', 'payplug' ); ?> | |
| 102 | - :</span> <?php echo ( ! empty( $metadata['card_exp_month'] ) && ! empty( $metadata['card_exp_year'] ) ) ? esc_html( sprintf( '%s/%s', zeroise( $metadata['card_exp_month'], 2 ), zeroise( $metadata['card_exp_year'], 2 ) ) ) : ''; ?> | |
| 103 | - </li> | |
| 108 | + | |
| 109 | + <?php if( ! empty( $metadata['card_exp_month'] ) && ! empty( $metadata['card_exp_year'] ) ){ ?> | |
| 110 | + <li><span><?php _e( 'Expiration date', 'payplug' ); ?> | |
| 111 | + :</span> <?php echo ( ! empty( $metadata['card_exp_month'] ) && ! empty( $metadata['card_exp_year'] ) ) ? esc_html( sprintf( '%s/%s', zeroise( $metadata['card_exp_month'], 2 ), zeroise( $metadata['card_exp_year'], 2 ) ) ) : ''; ?> | |
| 112 | + </li> | |
| 113 | + <?php } ?> | |
| 114 | + | |
| 104 | 115 | <li><span><?php _e( 'Mode', 'payplug' ); ?> |
| 105 | 116 | :</span> <?php echo true === $metadata['live'] ? _e( 'Live', 'payplug' ) : _e( 'Test', 'payplug' ); ?> |
| 106 | 117 | </li> |
| 107 | 118 | </ul> |
| @@ -106,5 +117,5 @@ | ||
| 106 | 117 | </li> |
| 107 | 118 | </ul> |
| 108 | 119 | <?php endif; |
| 109 | 120 | } |
| 110 | -} | |
| 121 | +} | |