1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
<?php
namespace YayMail\Shortcodes;
use YayMail\Utils\Helpers; use YayMail\Utils\SingletonTrait; use YayMail\Abstracts\BaseShortcode; use YayMail\Utils\TemplateHelpers;
/** * @method: static PaymentsShortcodes get_instance() */ class PaymentsShortcodes extends BaseShortcode { use SingletonTrait;
public function get_shortcodes() { $shortcodes = []; $shortcodes[] = [ 'name' => 'yaymail_order_payment_method', 'description' => __( 'Payment method', 'yaymail' ), 'group' => 'payments', 'callback' => [ $this, 'yaymail_order_payment_method' ], ]; $shortcodes[] = [ 'name' => 'yaymail_order_payment_link', 'description' => __( 'Payment Link', 'yaymail' ), 'attributes' => [ 'text_link' => __( 'Payment page', 'yaymail' ), ], 'group' => 'payments', 'callback' => [ $this, 'yaymail_order_payment_link' ], ]; $shortcodes[] = [ 'name' => 'yaymail_order_payment_url', 'description' => __( 'Payment URL (String)', 'yaymail' ), 'group' => 'payments', 'callback' => [ $this, 'yaymail_order_payment_url' ], ]; $shortcodes[] = [ 'name' => 'yaymail_payment_instructions', 'description' => __( 'Payment Instructions', 'yaymail' ), 'group' => 'payments', 'callback' => [ $this, 'yaymail_payment_instructions' ], ]; $shortcodes[] = [ 'name' => 'yaymail_payment_transaction_id', 'description' => __( 'Payment Transaction ID', 'yaymail' ), 'group' => 'payments', 'callback' => [ $this, 'yaymail_payment_transaction_id' ], ]; return $shortcodes; }
public function yaymail_order_payment_method( $data ) {
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
if ( ! empty( $render_data['is_sample'] ) ) { /** * Is sample order */ return __( 'Direct bank transfer', 'yaymail' ); }
$order = Helpers::get_order_from_shortcode_data( $render_data );
if ( empty( $order ) ) { /** * Not having order_id */ return ''; }
$order_item_totals = $order->get_order_item_totals();
return isset( $order_item_totals['payment_method']['value'] ) ? $order_item_totals['payment_method']['value'] : ''; }
public function yaymail_order_payment_link( $data, $shortcode_atts = [] ) {
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
$template = ! empty( $data['template'] ) ? $data['template'] : null;
$text_link_color = ! empty( $template ) ? $template->get_text_link_color() : YAYMAIL_COLOR_WC_DEFAULT;
$is_placeholder = isset( $data['is_placeholder'] ) ? $data['is_placeholder'] : false;
$text_link = isset( $shortcode_atts['text_link'] ) ? $shortcode_atts['text_link'] : TemplateHelpers::get_content_as_placeholder( 'text_link', __( 'Payment page', 'yaymail' ), $is_placeholder );
if ( ! empty( $render_data['is_sample'] ) ) { /** * Is sample order */ return '<a href="#" style="color:' . esc_attr( $text_link_color ) . ';">' . $text_link . '</a>'; }
$order = Helpers::get_order_from_shortcode_data( $render_data );
if ( empty( $order ) ) { /** * Not having order_id */ return ''; }
return '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '" style="color:' . esc_attr( $text_link_color ) . ';">' . $text_link . '</a>'; }
public function yaymail_order_payment_url( $data ) {
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
if ( ! empty( $render_data['is_sample'] ) ) { /** * Is sample order */ return esc_url( wc_get_endpoint_url( 'order-pay', 0, wc_get_checkout_url() ) ); }
$order = Helpers::get_order_from_shortcode_data( $render_data );
if ( empty( $order ) ) { /** * Not having order_id */ return ''; }
return $order->get_checkout_payment_url(); }
public function yaymail_payment_instructions( $data ) {
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
if ( ! empty( $render_data['is_sample'] ) ) { /** * Is sample order */ return __( 'Payment Instructions', 'yaymail' ); }
$order = Helpers::get_order_from_shortcode_data( $render_data );
if ( empty( $order ) ) { /** * Not having order_id */ return ''; } $args = [ 'order' => $order, ];
$html = yaymail_get_content( 'templates/shortcodes/payment-instruction/main.php', $args ); return $html; }
public function yaymail_payment_transaction_id( $data ) {
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : [];
if ( ! empty( $render_data['is_sample'] ) ) { /** * Is sample order */ return '1'; }
$order = Helpers::get_order_from_shortcode_data( $render_data );
if ( empty( $order ) || empty( $order->get_transaction_id() ) ) { /** * Not having order_id */ return ''; }
return $order->get_transaction_id(); } }
|