PluginProbe
PayPlug for WooCommerce (Official) / trunk
PayPlug for WooCommerce (Official) vtrunk
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Admin / Metabox.php

Metabox.php in PayPlug for WooCommerce (Official) trunk, at src/Admin/Metabox.php

122 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Admin;
4
5 // Exit if accessed directly
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
11 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
12 use WP_Post;
13
14 /**
15 * PayPlug metadata metabox.
16 */
17 class Metabox
18 {
19 /**
20 * Metabox constructor.
21 */
22 public function __construct()
23 {
24 add_action('add_meta_boxes', [$this, 'register_payplug_metabox'], 100);
25 }
26
27 /**
28 * Register a custom metabox to display metadata for the current order.
29 *
30 * This metabox is only register if the current order has been paid via PayPlug.
31 */
32 public function register_payplug_metabox(): void
33 {
34 global $post;
35
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';
39
40 add_meta_box(
41 'payplug-transaction-details',
42 __('PayPlug payment details', 'payplug'),
43 [$this, 'render'],
44 $screen,
45 'side'
46 );
47 }
48
49 /**
50 * Render the metabox content.
51 *
52 * @param WP_Post $post
53 */
54 public function render($post): void
55 {
56 $order = ($post instanceof WP_Post) ? wc_get_order($post->ID) : $post;
57
58 if (false === $order) {
59 return;
60 }
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', 'wero', 'bizum', 'scalapay'])) {
63 return;
64 }
65
66 $metadata = PayplugWoocommerceHelper::get_transaction_metadata($order);
67 $date_format = get_option('date_format', 'j F Y');
68 $time_format = get_option('time_format', 'G \h i \m\i\n');
69 if (empty($metadata)) : ?>
70 <p><?php _e('No metadata available for the current order.', 'payplug'); ?></p>
71 <?php else : ?>
72 <ul>
73 <li><span><?php _e('PayPlug Payment ID', 'payplug'); ?>
74 :</span> <?php echo esc_html($metadata['transaction_id']); ?></li>
75 <li><span><?php _e('Status', 'payplug'); ?>
76 :</span>
77 <?php if (isset($metadata['refunded']) && true === $metadata['refunded']) : _e('Refunded', 'payplug'); ?>
78 <?php elseif (isset($metadata['refunded']) && false === $metadata['refunded'] && (int) $metadata['amount_refunded'] > 0) : _e('Partially refunded', 'payplug'); ?>
79 <?php elseif (isset($metadata['paid']) && true === $metadata['paid']) : _e('Paid', 'payplug'); ?>
80 <?php else : _e('Not Paid', 'payplug'); ?>
81 <?php endif; ?>
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 <li><span><?php _e('Amount', 'payplug'); ?>
88 :</span> <?php echo wc_price((int) $metadata['amount'] / 100); ?></li>
89 <li><span><?php _e('Paid at', 'payplug'); ?>
90 :</span> <?php echo !empty($metadata['paid_at']) ? esc_html(date_i18n(sprintf('%s %s', $date_format, $time_format), $metadata['paid_at'])) : ''; ?>
91 </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
105 <li><span><?php _e('3 D Secure', 'payplug'); ?>
106 :</span> <?php echo isset($metadata['3ds']) ? true === $metadata['3ds'] ? __('Yes', 'payplug') : __('No', 'payplug') : ''; ?>
107 </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
115 <li><span><?php _e('Mode', 'payplug'); ?>
116 :</span> <?php echo true === $metadata['live'] ? _e('Live', 'payplug') : _e('Test', 'payplug'); ?>
117 </li>
118 </ul>
119 <?php endif;
120 }
121 }
122