@@ -13,462 +13,462 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | - } |
|
152 | - |
|
153 | - // Invoice addons. |
|
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | - } |
|
157 | - |
|
158 | - // Gateway settings. |
|
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | - |
|
161 | - // Gateway checkout fiellds. |
|
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | - |
|
164 | - // Process payment. |
|
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | - |
|
167 | - // Change the checkout button text. |
|
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | - } |
|
171 | - |
|
172 | - // Check if a gateway is valid for a given currency. |
|
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | - |
|
175 | - // Generate the transaction url. |
|
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | - |
|
178 | - // Generate the subscription url. |
|
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | - |
|
181 | - // Confirm payments. |
|
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | - |
|
184 | - // Verify IPNs. |
|
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Checks if this gateway is a given gateway. |
|
191 | - * |
|
192 | - * @since 1.0.19 |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function is( $gateway ) { |
|
196 | - return $gateway == $this->id; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a users saved tokens for this gateway. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function get_tokens( $sandbox = null ) { |
|
206 | - |
|
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | - |
|
210 | - if ( is_array( $tokens ) ) { |
|
211 | - $this->tokens = $tokens; |
|
212 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | + } |
|
152 | + |
|
153 | + // Invoice addons. |
|
154 | + if ( $this->supports( 'addons' ) ) { |
|
155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | + } |
|
157 | + |
|
158 | + // Gateway settings. |
|
159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | + |
|
161 | + // Gateway checkout fiellds. |
|
162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | + |
|
164 | + // Process payment. |
|
165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + |
|
167 | + // Change the checkout button text. |
|
168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | + } |
|
171 | + |
|
172 | + // Check if a gateway is valid for a given currency. |
|
173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | + |
|
175 | + // Generate the transaction url. |
|
176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | + |
|
178 | + // Generate the subscription url. |
|
179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | + |
|
181 | + // Confirm payments. |
|
182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | + |
|
184 | + // Verify IPNs. |
|
185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Checks if this gateway is a given gateway. |
|
191 | + * |
|
192 | + * @since 1.0.19 |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function is( $gateway ) { |
|
196 | + return $gateway == $this->id; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a users saved tokens for this gateway. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function get_tokens( $sandbox = null ) { |
|
206 | + |
|
207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + |
|
210 | + if ( is_array( $tokens ) ) { |
|
211 | + $this->tokens = $tokens; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1, |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1, |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | '11' => __( 'November', 'invoicing' ), |
487 | 487 | '12' => __( 'December', 'invoicing' ), |
488 | 488 | ); |
489 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
489 | + $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
490 | 490 | |
491 | 491 | $year = (int) current_time( 'Y' ); |
492 | 492 | $years = array(); |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $years[ $year + $i ] = $year + $i; |
496 | 496 | } |
497 | 497 | |
498 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
498 | + $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
499 | 499 | |
500 | 500 | ?> |
501 | 501 | <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | <?php |
533 | 533 | foreach ( $months as $key => $month ) { |
534 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
534 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
535 | 535 | } |
536 | 536 | ?> |
537 | 537 | |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | |
545 | 545 | <?php |
546 | 546 | foreach ( $years as $key => $year ) { |
547 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
547 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
548 | 548 | } |
549 | 549 | ?> |
550 | 550 | |
@@ -562,13 +562,13 @@ discard block |
||
562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
564 | 564 | 'label' => __( 'CCV', 'invoicing' ), |
565 | - 'label_type' => 'vertical', |
|
566 | - 'class' => 'form-control-sm', |
|
567 | - 'extra_attributes' => array( |
|
568 | - 'autocomplete' => 'cc-csc', |
|
569 | - ), |
|
565 | + 'label_type' => 'vertical', |
|
566 | + 'class' => 'form-control-sm', |
|
567 | + 'extra_attributes' => array( |
|
568 | + 'autocomplete' => 'cc-csc', |
|
569 | + ), |
|
570 | 570 | ), |
571 | - true |
|
571 | + true |
|
572 | 572 | ); |
573 | 573 | ?> |
574 | 574 | </div> |
@@ -577,192 +577,192 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
581 | - $this->save_payment_method_checkbox(); |
|
582 | - } |
|
580 | + if ( $save ) { |
|
581 | + $this->save_payment_method_checkbox(); |
|
582 | + } |
|
583 | 583 | |
584 | - ?> |
|
584 | + ?> |
|
585 | 585 | </div> |
586 | 586 | |
587 | 587 | </div> |
588 | 588 | <?php |
589 | 589 | |
590 | - return ob_get_clean(); |
|
590 | + return ob_get_clean(); |
|
591 | + |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Displays a new payment method entry form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + */ |
|
599 | + public function new_payment_method_entry( $form ) { |
|
600 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Grab and display our saved payment methods. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + */ |
|
608 | + public function saved_payment_methods() { |
|
609 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | + |
|
611 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | + $this->get_saved_payment_method_option_html( $token ); |
|
613 | + } |
|
614 | + |
|
615 | + $this->get_new_payment_method_option_html(); |
|
616 | + echo '</ul>'; |
|
591 | 617 | |
592 | 618 | } |
593 | 619 | |
594 | - /** |
|
595 | - * Displays a new payment method entry form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - */ |
|
599 | - public function new_payment_method_entry( $form ) { |
|
600 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Grab and display our saved payment methods. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - */ |
|
608 | - public function saved_payment_methods() { |
|
609 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | - |
|
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $this->get_saved_payment_method_option_html( $token ); |
|
613 | - } |
|
614 | - |
|
615 | - $this->get_new_payment_method_option_html(); |
|
616 | - echo '</ul>'; |
|
617 | - |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Gets saved payment method HTML from a token. |
|
622 | - * |
|
623 | - * @since 1.0.19 |
|
624 | - * @param array $token Payment Token. |
|
625 | - * @return string Generated payment method HTML |
|
626 | - */ |
|
627 | - public function get_saved_payment_method_option_html( $token ) { |
|
628 | - |
|
629 | - printf( |
|
630 | - '<li class="getpaid-payment-method form-group mb-3"> |
|
620 | + /** |
|
621 | + * Gets saved payment method HTML from a token. |
|
622 | + * |
|
623 | + * @since 1.0.19 |
|
624 | + * @param array $token Payment Token. |
|
625 | + * @return string Generated payment method HTML |
|
626 | + */ |
|
627 | + public function get_saved_payment_method_option_html( $token ) { |
|
628 | + |
|
629 | + printf( |
|
630 | + '<li class="getpaid-payment-method form-group mb-3"> |
|
631 | 631 | <label> |
632 | 632 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
633 | 633 | <span>%3$s</span> |
634 | 634 | </label> |
635 | 635 | </li>', |
636 | - esc_attr( $this->id ), |
|
637 | - esc_attr( $token['id'] ), |
|
638 | - esc_html( $token['name'] ), |
|
639 | - checked( empty( $token['default'] ), false, false ), |
|
640 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
641 | - ); |
|
642 | - |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - */ |
|
650 | - public function get_new_payment_method_option_html() { |
|
651 | - |
|
652 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
653 | - |
|
654 | - printf( |
|
655 | - '<li class="getpaid-new-payment-method"> |
|
636 | + esc_attr( $this->id ), |
|
637 | + esc_attr( $token['id'] ), |
|
638 | + esc_html( $token['name'] ), |
|
639 | + checked( empty( $token['default'] ), false, false ), |
|
640 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
641 | + ); |
|
642 | + |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + */ |
|
650 | + public function get_new_payment_method_option_html() { |
|
651 | + |
|
652 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
653 | + |
|
654 | + printf( |
|
655 | + '<li class="getpaid-new-payment-method"> |
|
656 | 656 | <label> |
657 | 657 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
658 | 658 | <span>%2$s</span> |
659 | 659 | </label> |
660 | 660 | </li>', |
661 | - esc_attr( $this->id ), |
|
662 | - esc_html( $label ) |
|
663 | - ); |
|
664 | - |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Outputs a checkbox for saving a new payment method to the database. |
|
669 | - * |
|
670 | - * @since 1.0.19 |
|
671 | - */ |
|
672 | - public function save_payment_method_checkbox() { |
|
673 | - |
|
674 | - aui()->input( |
|
675 | - array( |
|
676 | - 'type' => 'checkbox', |
|
677 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
678 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
679 | - 'required' => false, |
|
680 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
681 | - 'value' => 'true', |
|
682 | - 'checked' => true, |
|
683 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
684 | - ), |
|
685 | - true |
|
686 | - ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Registers the gateway. |
|
692 | - * |
|
693 | - * @return array |
|
694 | - */ |
|
695 | - public function register_gateway( $gateways ) { |
|
696 | - |
|
697 | - $gateways[ $this->id ] = array( |
|
698 | - |
|
699 | - 'admin_label' => $this->method_title, |
|
661 | + esc_attr( $this->id ), |
|
662 | + esc_html( $label ) |
|
663 | + ); |
|
664 | + |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Outputs a checkbox for saving a new payment method to the database. |
|
669 | + * |
|
670 | + * @since 1.0.19 |
|
671 | + */ |
|
672 | + public function save_payment_method_checkbox() { |
|
673 | + |
|
674 | + aui()->input( |
|
675 | + array( |
|
676 | + 'type' => 'checkbox', |
|
677 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
678 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
679 | + 'required' => false, |
|
680 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
681 | + 'value' => 'true', |
|
682 | + 'checked' => true, |
|
683 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
684 | + ), |
|
685 | + true |
|
686 | + ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Registers the gateway. |
|
692 | + * |
|
693 | + * @return array |
|
694 | + */ |
|
695 | + public function register_gateway( $gateways ) { |
|
696 | + |
|
697 | + $gateways[ $this->id ] = array( |
|
698 | + |
|
699 | + 'admin_label' => $this->method_title, |
|
700 | 700 | 'checkout_label' => $this->title, |
701 | - 'ordering' => $this->order, |
|
701 | + 'ordering' => $this->order, |
|
702 | 702 | |
703 | - ); |
|
703 | + ); |
|
704 | 704 | |
705 | - return $gateways; |
|
705 | + return $gateways; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
710 | - * Checks whether or not this is a sandbox request. |
|
711 | - * |
|
712 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | - * @return bool |
|
714 | - */ |
|
715 | - public function is_sandbox( $invoice = null ) { |
|
709 | + /** |
|
710 | + * Checks whether or not this is a sandbox request. |
|
711 | + * |
|
712 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | + public function is_sandbox( $invoice = null ) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | - return $invoice->get_mode() == 'test'; |
|
719 | - } |
|
717 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | + return $invoice->get_mode() == 'test'; |
|
719 | + } |
|
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode( $this->id ); |
|
722 | 722 | |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - /** |
|
726 | - * Renames the checkout button |
|
727 | - * |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - public function rename_checkout_button() { |
|
731 | - return $this->checkout_button_text; |
|
732 | - } |
|
725 | + /** |
|
726 | + * Renames the checkout button |
|
727 | + * |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + public function rename_checkout_button() { |
|
731 | + return $this->checkout_button_text; |
|
732 | + } |
|
733 | 733 | |
734 | - /** |
|
735 | - * Validate gateway currency |
|
736 | - * |
|
737 | - * @return bool |
|
738 | - */ |
|
739 | - public function validate_currency( $validation, $currency ) { |
|
734 | + /** |
|
735 | + * Validate gateway currency |
|
736 | + * |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | + public function validate_currency( $validation, $currency ) { |
|
740 | 740 | |
741 | - // Required currencies. |
|
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | - return false; |
|
744 | - } |
|
741 | + // Required currencies. |
|
742 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | + return false; |
|
744 | + } |
|
745 | 745 | |
746 | - // Excluded currencies. |
|
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | - return false; |
|
749 | - } |
|
746 | + // Excluded currencies. |
|
747 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | + return false; |
|
749 | + } |
|
750 | 750 | |
751 | - return $validation; |
|
752 | - } |
|
751 | + return $validation; |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * Displays an error |
|
756 | - * |
|
757 | - */ |
|
758 | - public function show_error( $code, $message, $type ) { |
|
754 | + /** |
|
755 | + * Displays an error |
|
756 | + * |
|
757 | + */ |
|
758 | + public function show_error( $code, $message, $type ) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
762 | - } |
|
760 | + if ( is_admin() ) { |
|
761 | + getpaid_admin()->{"show_$type"}( $message ); |
|
762 | + } |
|
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error( $code, $message, $type ); |
|
765 | 765 | |
766 | - } |
|
766 | + } |
|
767 | 767 | |
768 | 768 | } |