| @@ -5,13 +5,8 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmTransLiteAppHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * @var bool|null | |
| 10 | - */ | |
| 11 | - private static $should_fallback_to_paypal; | |
| 12 | - | |
| 13 | - /** | |
| 14 | 9 | * @return string |
| 15 | 10 | */ |
| 16 | 11 | public static function plugin_path() { |
| 17 | 12 | return FrmAppHelper::plugin_path() . '/stripe/'; |
| @@ -43,8 +38,9 @@ | ||
| 43 | 38 | */ |
| 44 | 39 | public static function payments_table_exists() { |
| 45 | 40 | $db = new FrmTransLiteDb(); |
| 46 | 41 | $option = get_option( $db->db_opt_name ); |
| 42 | + | |
| 47 | 43 | if ( false !== $option ) { |
| 48 | 44 | return true; |
| 49 | 45 | } |
| 50 | 46 | |
| @@ -49,8 +45,9 @@ | ||
| 49 | 45 | } |
| 50 | 46 | |
| 51 | 47 | if ( class_exists( 'FrmPaymentsController' ) && isset( FrmPaymentsController::$db_opt_name ) ) { |
| 52 | 48 | $option = get_option( FrmPaymentsController::$db_opt_name ); |
| 49 | + | |
| 53 | 50 | if ( false !== $option ) { |
| 54 | 51 | return true; |
| 55 | 52 | } |
| 56 | 53 | } |
| @@ -61,8 +58,9 @@ | ||
| 61 | 58 | /** |
| 62 | 59 | * Get a payment status label. |
| 63 | 60 | * |
| 64 | 61 | * @param string $status The lowercase payment status value. |
| 62 | + * | |
| 65 | 63 | * @return string |
| 66 | 64 | */ |
| 67 | 65 | public static function show_status( $status ) { |
| 68 | 66 | $statuses = array_merge( self::get_payment_statuses(), self::get_subscription_statuses() ); |
| @@ -72,12 +70,13 @@ | ||
| 72 | 70 | /** |
| 73 | 71 | * Get Payment status from a payment with support for PayPal backward compatibility. |
| 74 | 72 | * |
| 75 | 73 | * @param stdClass $payment |
| 74 | + * | |
| 76 | 75 | * @return string |
| 77 | 76 | */ |
| 78 | 77 | public static function get_payment_status( $payment ) { |
| 79 | - if ( $payment->status ) { | |
| 78 | + if ( ! empty( $payment->status ) ) { | |
| 80 | 79 | return $payment->status; |
| 81 | 80 | } |
| 82 | 81 | // PayPal fallback. |
| 83 | 82 | return ! empty( $payment->completed ) ? 'complete' : 'pending'; |
| @@ -116,8 +115,9 @@ | ||
| 116 | 115 | * This is called when processing events in the Stripe add on. |
| 117 | 116 | * |
| 118 | 117 | * @param array $payment_values |
| 119 | 118 | * @param string $message |
| 119 | + * | |
| 120 | 120 | * @return void |
| 121 | 121 | */ |
| 122 | 122 | public static function add_note_to_payment( &$payment_values, $message = '' ) { |
| 123 | 123 | if ( ! $message ) { |
| @@ -148,17 +148,20 @@ | ||
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * @param string $option |
| 151 | 151 | * @param array $atts |
| 152 | + * | |
| 153 | + * @return mixed | |
| 152 | 154 | */ |
| 153 | 155 | public static function get_action_setting( $option, $atts ) { |
| 154 | 156 | $settings = self::get_action_settings( $atts ); |
| 155 | - $value = $settings[ $option ] ?? ''; | |
| 156 | - return $value; | |
| 157 | + return $settings[ $option ] ?? ''; | |
| 157 | 158 | } |
| 158 | 159 | |
| 159 | 160 | /** |
| 160 | 161 | * @param array $atts |
| 162 | + * | |
| 163 | + * @return array | |
| 161 | 164 | */ |
| 162 | 165 | public static function get_action_settings( $atts ) { |
| 163 | 166 | if ( ! isset( $atts['payment'] ) ) { |
| 164 | 167 | return array(); |
| @@ -164,18 +167,16 @@ | ||
| 164 | 167 | return array(); |
| 165 | 168 | } |
| 166 | 169 | |
| 167 | 170 | $atts['payment'] = (array) $atts['payment']; |
| 171 | + | |
| 168 | 172 | if ( empty( $atts['payment']['action_id'] ) ) { |
| 169 | 173 | return array(); |
| 170 | 174 | } |
| 171 | 175 | |
| 172 | 176 | $form_action = FrmTransLiteAction::get_single_action_type( $atts['payment']['action_id'], 'payment' ); |
| 173 | - if ( ! $form_action ) { | |
| 174 | - return array(); | |
| 175 | - } | |
| 176 | 177 | |
| 177 | - return $form_action->post_content; | |
| 178 | + return $form_action ? $form_action->post_content : array(); | |
| 178 | 179 | } |
| 179 | 180 | |
| 180 | 181 | /** |
| 181 | 182 | * Allow entry values, default values, and other shortcodes |
| @@ -180,13 +181,15 @@ | ||
| 180 | 181 | /** |
| 181 | 182 | * Allow entry values, default values, and other shortcodes |
| 182 | 183 | * |
| 183 | 184 | * @param array $atts Includes value (required), form, entry. |
| 185 | + * | |
| 184 | 186 | * @return int|string |
| 185 | 187 | */ |
| 186 | 188 | public static function process_shortcodes( $atts ) { |
| 187 | 189 | $value = $atts['value']; |
| 188 | - if ( strpos( $value, '[' ) === false ) { | |
| 190 | + | |
| 191 | + if ( ! str_contains( $value, '[' ) ) { | |
| 189 | 192 | return $value; |
| 190 | 193 | } |
| 191 | 194 | |
| 192 | 195 | if ( is_callable( 'FrmProFieldsHelper::replace_non_standard_formidable_shortcodes' ) ) { |
| @@ -196,28 +199,29 @@ | ||
| 196 | 199 | if ( ! empty( $atts['entry'] ) ) { |
| 197 | 200 | if ( ! isset( $atts['form'] ) ) { |
| 198 | 201 | $atts['form'] = FrmForm::getOne( $atts['entry']->form_id ); |
| 199 | 202 | } |
| 203 | + | |
| 200 | 204 | $value = apply_filters( 'frm_content', $value, $atts['form'], $atts['entry'] ); |
| 201 | 205 | } |
| 202 | 206 | |
| 203 | - $value = do_shortcode( $value ); | |
| 204 | - return $value; | |
| 207 | + return do_shortcode( $value ); | |
| 205 | 208 | } |
| 206 | 209 | |
| 207 | 210 | /** |
| 208 | 211 | * @param object $sub |
| 212 | + * | |
| 209 | 213 | * @return string |
| 210 | 214 | */ |
| 211 | 215 | public static function format_billing_cycle( $sub ) { |
| 212 | 216 | $amount = self::formatted_amount( $sub ); |
| 213 | 217 | $interval = self::get_repeat_label_from_value( $sub->time_interval, $sub->interval_count ); |
| 214 | - if ( $sub->interval_count == 1 ) { | |
| 215 | - $amount = $amount . '/' . $interval; | |
| 216 | - } else { | |
| 217 | - $amount = $amount . ' every ' . $sub->interval_count . ' ' . $interval; | |
| 218 | + | |
| 219 | + if ( (int) $sub->interval_count === 1 ) { | |
| 220 | + return $amount . '/' . $interval; | |
| 218 | 221 | } |
| 219 | - return $amount; | |
| 222 | + | |
| 223 | + return $amount . ' every ' . $sub->interval_count . ' ' . $interval; | |
| 220 | 224 | } |
| 221 | 225 | |
| 222 | 226 | /** |
| 223 | 227 | * @return array |
| @@ -234,8 +238,9 @@ | ||
| 234 | 238 | /** |
| 235 | 239 | * @since 6.5, introduced in v1.16 of the Payments submodule. |
| 236 | 240 | * |
| 237 | 241 | * @param int $number |
| 242 | + * | |
| 238 | 243 | * @return array |
| 239 | 244 | */ |
| 240 | 245 | private static function get_plural_repeat_times( $number ) { |
| 241 | 246 | return array( |
| @@ -250,18 +255,21 @@ | ||
| 250 | 255 | * @since 6.5, introduced in v1.16 of the Payments submodule. |
| 251 | 256 | * |
| 252 | 257 | * @param string $value |
| 253 | 258 | * @param int $number |
| 259 | + * | |
| 254 | 260 | * @return string |
| 255 | 261 | */ |
| 256 | 262 | public static function get_repeat_label_from_value( $value, $number ) { |
| 257 | 263 | $times = self::get_plural_repeat_times( $number ); |
| 258 | - if ( isset( $times[ $value ] ) ) { | |
| 259 | - $value = $times[ $value ]; | |
| 260 | - } | |
| 261 | - return $value; | |
| 264 | + return $times[ $value ] ?? $value; | |
| 262 | 265 | } |
| 263 | 266 | |
| 267 | + /** | |
| 268 | + * @param array|float|int|object $payment | |
| 269 | + * | |
| 270 | + * @return string | |
| 271 | + */ | |
| 264 | 272 | public static function formatted_amount( $payment ) { |
| 265 | 273 | $currency = ''; |
| 266 | 274 | $amount = $payment; |
| 267 | 275 | |
| @@ -287,8 +295,9 @@ | ||
| 287 | 295 | * |
| 288 | 296 | * @since 6.7 |
| 289 | 297 | * |
| 290 | 298 | * @param array|float|object|string $payment Payment object, payment array or amount. |
| 299 | + * | |
| 291 | 300 | * @return array Return the array with the first element is the amount, the second one is the currency value. |
| 292 | 301 | */ |
| 293 | 302 | public static function get_amount_and_currency_from_payment( $payment ) { |
| 294 | 303 | $currency = ''; |
| @@ -309,8 +318,9 @@ | ||
| 309 | 318 | |
| 310 | 319 | /** |
| 311 | 320 | * @param array $currency |
| 312 | 321 | * @param float $amount |
| 322 | + * | |
| 313 | 323 | * @return void |
| 314 | 324 | */ |
| 315 | 325 | public static function format_amount_for_currency( $currency, &$amount ) { |
| 316 | 326 | $amount = number_format( $amount, $currency['decimals'], $currency['decimal_separator'], $currency['thousand_separator'] ); |
| @@ -322,28 +332,26 @@ | ||
| 322 | 332 | /** |
| 323 | 333 | * @return string |
| 324 | 334 | */ |
| 325 | 335 | public static function get_date_format() { |
| 326 | - $date_format = 'm/d/Y'; | |
| 327 | - if ( class_exists( 'FrmProAppHelper' ) ) { | |
| 328 | - $frmpro_settings = FrmProAppHelper::get_settings(); | |
| 329 | - if ( $frmpro_settings ) { | |
| 330 | - $date_format = $frmpro_settings->date_format; | |
| 331 | - } | |
| 332 | - } else { | |
| 333 | - $date_format = get_option( 'date_format' ); | |
| 336 | + if ( ! class_exists( 'FrmProAppHelper' ) ) { | |
| 337 | + return get_option( 'date_format' ); | |
| 334 | 338 | } |
| 335 | 339 | |
| 336 | - return $date_format; | |
| 340 | + $date_format = 'm/d/Y'; | |
| 341 | + $frmpro_settings = FrmProAppHelper::get_settings(); | |
| 342 | + | |
| 343 | + return $frmpro_settings ? $frmpro_settings->date_format : $date_format; | |
| 337 | 344 | } |
| 338 | 345 | |
| 339 | 346 | /** |
| 340 | 347 | * @param string $date |
| 341 | 348 | * @param string $format |
| 349 | + * | |
| 342 | 350 | * @return string |
| 343 | 351 | */ |
| 344 | 352 | public static function format_the_date( $date, $format = '' ) { |
| 345 | - if ( empty( $format ) ) { | |
| 353 | + if ( ! $format ) { | |
| 346 | 354 | $format = self::get_date_format(); |
| 347 | 355 | } |
| 348 | 356 | return date_i18n( $format, strtotime( $date ) ); |
| 349 | 357 | } |
| @@ -353,45 +361,62 @@ | ||
| 353 | 361 | * |
| 354 | 362 | * @return int |
| 355 | 363 | */ |
| 356 | 364 | public static function get_user_id_for_current_payment() { |
| 357 | - $user_id = 0; | |
| 358 | - if ( is_user_logged_in() ) { | |
| 359 | - $user_id = get_current_user_id(); | |
| 360 | - } | |
| 361 | - return $user_id; | |
| 365 | + $user_id = is_user_logged_in() ? get_current_user_id() : 0; | |
| 366 | + | |
| 367 | + /** | |
| 368 | + * Set the user who owns the payment being made. | |
| 369 | + * This makes it possible for an add on to claim the payment for a user who isn't logged in yet, | |
| 370 | + * for example when the same submission registers them. | |
| 371 | + * | |
| 372 | + * @since 6.35 | |
| 373 | + * | |
| 374 | + * @param int $user_id The logged in user, or 0 for a guest. | |
| 375 | + */ | |
| 376 | + $user_id = (int) apply_filters( 'frm_payment_user_id', $user_id ); | |
| 377 | + | |
| 378 | + return max( 0, $user_id ); | |
| 362 | 379 | } |
| 363 | 380 | |
| 364 | 381 | /** |
| 365 | 382 | * @param int $user_id |
| 383 | + * | |
| 366 | 384 | * @return string |
| 367 | 385 | */ |
| 368 | 386 | public static function get_user_link( $user_id ) { |
| 369 | - $user_link = esc_html__( 'Guest', 'formidable' ); | |
| 370 | 387 | if ( $user_id ) { |
| 371 | 388 | $user = get_userdata( $user_id ); |
| 389 | + | |
| 372 | 390 | if ( $user ) { |
| 373 | - $user_link = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>'; | |
| 391 | + return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>'; | |
| 374 | 392 | } |
| 375 | 393 | } |
| 376 | - return $user_link; | |
| 394 | + | |
| 395 | + return esc_html__( 'Guest', 'formidable' ); | |
| 377 | 396 | } |
| 378 | 397 | |
| 379 | 398 | /** |
| 380 | 399 | * @param mixed $value |
| 381 | 400 | * @param string $label |
| 401 | + * | |
| 382 | 402 | * @return void |
| 383 | 403 | */ |
| 384 | 404 | public static function show_in_table( $value, $label ) { |
| 385 | - if ( ! empty( $value ) ) { ?> | |
| 386 | - <tr> | |
| 387 | - <th scope="row"><?php echo esc_html( $label ); ?>:</th> | |
| 388 | - <td> | |
| 389 | - <?php echo esc_html( $value ); ?> | |
| 390 | - </td> | |
| 391 | - </tr> | |
| 392 | - <?php | |
| 405 | + if ( ! $value ) { | |
| 406 | + return; | |
| 393 | 407 | } |
| 408 | + | |
| 409 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 410 | + ?> | |
| 411 | + <tr> | |
| 412 | + <th scope="row"><?php echo esc_html( $label ); ?>:</th> | |
| 413 | + <td> | |
| 414 | + <?php echo esc_html( $value ); ?> | |
| 415 | + </td> | |
| 416 | + </tr> | |
| 417 | + <?php | |
| 418 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 394 | 419 | } |
| 395 | 420 | |
| 396 | 421 | /** |
| 397 | 422 | * Echo a link that includes a data-deleteconfirm attribute. |
| @@ -399,8 +424,9 @@ | ||
| 399 | 424 | * |
| 400 | 425 | * @since 6.5 |
| 401 | 426 | * |
| 402 | 427 | * @param string $link |
| 428 | + * | |
| 403 | 429 | * @return void |
| 404 | 430 | */ |
| 405 | 431 | public static function echo_confirmation_link( $link ) { |
| 406 | 432 | $filter = self::class . '::allow_deleteconfirm_data_attribute'; |
| @@ -415,8 +441,9 @@ | ||
| 415 | 441 | * |
| 416 | 442 | * @since 6.5 |
| 417 | 443 | * |
| 418 | 444 | * @param array $allowed |
| 445 | + * | |
| 419 | 446 | * @return array |
| 420 | 447 | */ |
| 421 | 448 | public static function allow_deleteconfirm_data_attribute( $allowed ) { |
| 422 | 449 | $allowed['a']['data-deleteconfirm'] = true; |
| @@ -440,10 +467,11 @@ | ||
| 440 | 467 | return $amount; |
| 441 | 468 | } |
| 442 | 469 | |
| 443 | 470 | $currency = FrmCurrencyHelper::get_currency( $action->post_content['currency'] ); |
| 471 | + | |
| 444 | 472 | if ( ! empty( $currency['decimals'] ) ) { |
| 445 | - $amount = number_format( $amount / 100, 2, '.', '' ); | |
| 473 | + return number_format( $amount / 100, 2, '.', '' ); | |
| 446 | 474 | } |
| 447 | 475 | |
| 448 | 476 | return $amount; |
| 449 | 477 | } |
| @@ -448,35 +476,8 @@ | ||
| 448 | 476 | return $amount; |
| 449 | 477 | } |
| 450 | 478 | |
| 451 | 479 | /** |
| 452 | - * @return bool | |
| 453 | - */ | |
| 454 | - public static function should_fallback_to_paypal() { | |
| 455 | - if ( isset( self::$should_fallback_to_paypal ) ) { | |
| 456 | - return self::$should_fallback_to_paypal; | |
| 457 | - } | |
| 458 | - | |
| 459 | - if ( ! class_exists( 'FrmPaymentsController' ) || ! isset( FrmPaymentsController::$db_opt_name ) ) { | |
| 460 | - self::$should_fallback_to_paypal = false; | |
| 461 | - return false; | |
| 462 | - } | |
| 463 | - | |
| 464 | - $db = new FrmTransLiteDb(); | |
| 465 | - $option = get_option( $db->db_opt_name ); | |
| 466 | - if ( false !== $option ) { | |
| 467 | - // Don't fallback to PayPal if Stripe migrations have run. | |
| 468 | - self::$should_fallback_to_paypal = false; | |
| 469 | - return false; | |
| 470 | - } | |
| 471 | - | |
| 472 | - $option = get_option( FrmPaymentsController::$db_opt_name ); | |
| 473 | - self::$should_fallback_to_paypal = false !== $option; | |
| 474 | - | |
| 475 | - return self::$should_fallback_to_paypal; | |
| 476 | - } | |
| 477 | - | |
| 478 | - /** | |
| 479 | 480 | * Get a human readable translated 'Test' or 'Live' string if the column value is defined. |
| 480 | 481 | * Old payments will just output an empty string. |
| 481 | 482 | * |
| 482 | 483 | * @since 6.6 |
| @@ -481,8 +482,9 @@ | ||
| 481 | 482 | * |
| 482 | 483 | * @since 6.6 |
| 483 | 484 | * |
| 484 | 485 | * @param stdClass $payment |
| 486 | + * | |
| 485 | 487 | * @return string |
| 486 | 488 | */ |
| 487 | 489 | public static function get_test_mode_display_string( $payment ) { |
| 488 | 490 | if ( ! isset( $payment->test ) ) { |
| @@ -501,8 +503,9 @@ | ||
| 501 | 503 | * @return int |
| 502 | 504 | */ |
| 503 | 505 | public static function count_completed_payments( $payments ) { |
| 504 | 506 | $count = 0; |
| 507 | + | |
| 505 | 508 | foreach ( $payments as $payment ) { |
| 506 | 509 | if ( $payment->status === 'complete' ) { |
| 507 | 510 | $count++; |
| 508 | 511 | } |
| @@ -510,26 +513,33 @@ | ||
| 510 | 513 | |
| 511 | 514 | return $count; |
| 512 | 515 | } |
| 513 | 516 | |
| 517 | + /** | |
| 518 | + * @return array | |
| 519 | + */ | |
| 514 | 520 | public static function get_gateways() { |
| 515 | - $gateways = apply_filters( 'frm_payment_gateways', array() ); | |
| 516 | - return $gateways; | |
| 521 | + return apply_filters( 'frm_payment_gateways', array() ); | |
| 517 | 522 | } |
| 518 | 523 | |
| 519 | 524 | /** |
| 520 | 525 | * @param array|string $gateway |
| 521 | 526 | * @param string $setting |
| 527 | + * | |
| 528 | + * @return mixed | |
| 522 | 529 | */ |
| 523 | 530 | public static function get_setting_for_gateway( $gateway, $setting ) { |
| 524 | 531 | $gateways = self::get_gateways(); |
| 525 | 532 | $value = ''; |
| 533 | + | |
| 526 | 534 | if ( is_array( $gateway ) ) { |
| 527 | 535 | $gateway = reset( $gateway ); |
| 528 | 536 | } |
| 537 | + | |
| 529 | 538 | if ( isset( $gateways[ $gateway ] ) ) { |
| 530 | - $value = $gateways[ $gateway ][ $setting ]; | |
| 539 | + return $gateways[ $gateway ][ $setting ]; | |
| 531 | 540 | } |
| 541 | + | |
| 532 | 542 | return $value; |
| 533 | 543 | } |
| 534 | 544 | |
| 535 | 545 | /** |
| @@ -540,8 +550,10 @@ | ||
| 540 | 550 | * |
| 541 | 551 | * @param string $id |
| 542 | 552 | * @param string $name |
| 543 | 553 | * @param array $action_settings |
| 554 | + * | |
| 555 | + * @return void | |
| 544 | 556 | */ |
| 545 | 557 | public static function show_currency_dropdown( $id, $name, $action_settings ) { |
| 546 | 558 | $selected = $action_settings['currency']; |
| 547 | 559 | $gateways = (array) $action_settings['gateway']; |
| @@ -548,13 +560,16 @@ | ||
| 548 | 560 | $select_attrs = array( |
| 549 | 561 | 'id' => $id, |
| 550 | 562 | 'name' => $name, |
| 551 | 563 | ); |
| 564 | + | |
| 552 | 565 | if ( in_array( 'square', $gateways, true ) ) { |
| 553 | 566 | $select_attrs['disabled'] = 'disabled'; |
| 554 | 567 | $selected = ''; |
| 555 | 568 | } |
| 569 | + | |
| 556 | 570 | $currencies = FrmCurrencyHelper::get_currencies(); |
| 571 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 557 | 572 | ?> |
| 558 | 573 | <select <?php FrmAppHelper::array_to_html_params( $select_attrs, true ); ?>> |
| 559 | 574 | <?php |
| 560 | 575 | if ( in_array( 'square', $gateways, true ) ) { |
| @@ -580,6 +595,81 @@ | ||
| 580 | 595 | } |
| 581 | 596 | ?> |
| 582 | 597 | </select> |
| 583 | 598 | <?php |
| 599 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 600 | + } | |
| 601 | + | |
| 602 | + /** | |
| 603 | + * @since 6.27 | |
| 604 | + * | |
| 605 | + * @return bool | |
| 606 | + */ | |
| 607 | + public static function payments_submodule_or_paypal_is_active() { | |
| 608 | + return class_exists( 'FrmTransAppController' ) || class_exists( 'FrmPaymentsController' ); | |
| 609 | + } | |
| 610 | + | |
| 611 | + /** | |
| 612 | + * @deprecated 6.27 | |
| 613 | + * | |
| 614 | + * @return bool | |
| 615 | + */ | |
| 616 | + public static function should_fallback_to_paypal() { | |
| 617 | + _deprecated_function( __METHOD__, '6.27' ); | |
| 618 | + return false; | |
| 619 | + } | |
| 620 | + | |
| 621 | + /** | |
| 622 | + * Render the gateway icon buttons for the payment action settings. | |
| 623 | + * | |
| 624 | + * @param array $gateways | |
| 625 | + * @param WP_Post $form_action | |
| 626 | + * @param FrmFormAction $action_control | |
| 627 | + * | |
| 628 | + * @return void | |
| 629 | + */ | |
| 630 | + public static function show_gateway_buttons( $gateways, $form_action, $action_control ) { | |
| 631 | + $gateway_order = array( 'stripe', 'square', 'paypal' ); | |
| 632 | + $gateways = self::sort_gateways( $gateways, $gateway_order ); | |
| 633 | + | |
| 634 | + include self::plugin_path() . '/views/action-settings/gateway-buttons.php'; | |
| 635 | + } | |
| 636 | + | |
| 637 | + /** | |
| 638 | + * Sort gateways by a predefined order. | |
| 639 | + * Unlisted gateways are appended at the end. | |
| 640 | + * | |
| 641 | + * @param array $gateways | |
| 642 | + * @param array $order Gateway keys in desired order. | |
| 643 | + * | |
| 644 | + * @return array | |
| 645 | + */ | |
| 646 | + private static function sort_gateways( $gateways, $order ) { | |
| 647 | + $sorted = array(); | |
| 648 | + | |
| 649 | + foreach ( $order as $key ) { | |
| 650 | + if ( isset( $gateways[ $key ] ) ) { | |
| 651 | + $sorted[ $key ] = $gateways[ $key ]; | |
| 652 | + } | |
| 653 | + } | |
| 654 | + | |
| 655 | + return $sorted + $gateways; | |
| 656 | + } | |
| 657 | + | |
| 658 | + /** | |
| 659 | + * @since 6.32.1 | |
| 660 | + * | |
| 661 | + * @param string $gateway 'stripe', 'square', or 'paypal'. | |
| 662 | + * @param string $mode 'test' or 'live'. | |
| 663 | + * | |
| 664 | + * @return void | |
| 665 | + */ | |
| 666 | + public static function trigger_gateway_disconnected_hook( $gateway, $mode ) { | |
| 667 | + /** | |
| 668 | + * @since 6.32.1 | |
| 669 | + * | |
| 670 | + * @param string $gateway 'stripe', 'square', or 'paypal'. | |
| 671 | + * @param string $mode 'test' or 'live'. | |
| 672 | + */ | |
| 673 | + do_action( 'frm_disconnected_gateway', $gateway, $mode ); | |
| 584 | 674 | } |
| 585 | 675 | } |