| @@ -38,8 +38,9 @@ | ||
| 38 | 38 | */ |
| 39 | 39 | public static function payments_table_exists() { |
| 40 | 40 | $db = new FrmTransLiteDb(); |
| 41 | 41 | $option = get_option( $db->db_opt_name ); |
| 42 | + | |
| 42 | 43 | if ( false !== $option ) { |
| 43 | 44 | return true; |
| 44 | 45 | } |
| 45 | 46 | |
| @@ -44,8 +45,9 @@ | ||
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | if ( class_exists( 'FrmPaymentsController' ) && isset( FrmPaymentsController::$db_opt_name ) ) { |
| 47 | 48 | $option = get_option( FrmPaymentsController::$db_opt_name ); |
| 49 | + | |
| 48 | 50 | if ( false !== $option ) { |
| 49 | 51 | return true; |
| 50 | 52 | } |
| 51 | 53 | } |
| @@ -56,13 +58,14 @@ | ||
| 56 | 58 | /** |
| 57 | 59 | * Get a payment status label. |
| 58 | 60 | * |
| 59 | 61 | * @param string $status The lowercase payment status value. |
| 62 | + * | |
| 60 | 63 | * @return string |
| 61 | 64 | */ |
| 62 | 65 | public static function show_status( $status ) { |
| 63 | 66 | $statuses = array_merge( self::get_payment_statuses(), self::get_subscription_statuses() ); |
| 64 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status; | |
| 67 | + return $statuses[ $status ] ?? $status; | |
| 65 | 68 | } |
| 66 | 69 | |
| 67 | 70 | /** |
| 68 | 71 | * Get Payment status from a payment with support for PayPal backward compatibility. |
| @@ -67,12 +70,13 @@ | ||
| 67 | 70 | /** |
| 68 | 71 | * Get Payment status from a payment with support for PayPal backward compatibility. |
| 69 | 72 | * |
| 70 | 73 | * @param stdClass $payment |
| 74 | + * | |
| 71 | 75 | * @return string |
| 72 | 76 | */ |
| 73 | 77 | public static function get_payment_status( $payment ) { |
| 74 | - if ( $payment->status ) { | |
| 78 | + if ( ! empty( $payment->status ) ) { | |
| 75 | 79 | return $payment->status; |
| 76 | 80 | } |
| 77 | 81 | // PayPal fallback. |
| 78 | 82 | return ! empty( $payment->completed ) ? 'complete' : 'pending'; |
| @@ -111,8 +115,9 @@ | ||
| 111 | 115 | * This is called when processing events in the Stripe add on. |
| 112 | 116 | * |
| 113 | 117 | * @param array $payment_values |
| 114 | 118 | * @param string $message |
| 119 | + * | |
| 115 | 120 | * @return void |
| 116 | 121 | */ |
| 117 | 122 | public static function add_note_to_payment( &$payment_values, $message = '' ) { |
| 118 | 123 | if ( ! $message ) { |
| @@ -121,14 +126,15 @@ | ||
| 121 | 126 | __( 'Payment %s', 'formidable' ), |
| 122 | 127 | $payment_values['status'] |
| 123 | 128 | ); |
| 124 | 129 | } |
| 125 | - $payment_values['meta_value'] = isset( $payment_values['meta_value'] ) ? $payment_values['meta_value'] : array(); | |
| 130 | + $payment_values['meta_value'] = $payment_values['meta_value'] ?? array(); | |
| 126 | 131 | $payment_values['meta_value'] = self::add_meta_to_payment( $payment_values['meta_value'], $message ); |
| 127 | 132 | } |
| 128 | 133 | |
| 129 | 134 | /** |
| 130 | - * @param string $note | |
| 135 | + * @param array|string $meta_value | |
| 136 | + * @param string $note | |
| 131 | 137 | * |
| 132 | 138 | * @return array |
| 133 | 139 | */ |
| 134 | 140 | public static function add_meta_to_payment( $meta_value, $note ) { |
| @@ -141,18 +147,21 @@ | ||
| 141 | 147 | } |
| 142 | 148 | |
| 143 | 149 | /** |
| 144 | 150 | * @param string $option |
| 145 | - * @param array $atts | |
| 151 | + * @param array $atts | |
| 152 | + * | |
| 153 | + * @return mixed | |
| 146 | 154 | */ |
| 147 | 155 | public static function get_action_setting( $option, $atts ) { |
| 148 | 156 | $settings = self::get_action_settings( $atts ); |
| 149 | - $value = isset( $settings[ $option ] ) ? $settings[ $option ] : ''; | |
| 150 | - return $value; | |
| 157 | + return $settings[ $option ] ?? ''; | |
| 151 | 158 | } |
| 152 | 159 | |
| 153 | 160 | /** |
| 154 | 161 | * @param array $atts |
| 162 | + * | |
| 163 | + * @return array | |
| 155 | 164 | */ |
| 156 | 165 | public static function get_action_settings( $atts ) { |
| 157 | 166 | if ( ! isset( $atts['payment'] ) ) { |
| 158 | 167 | return array(); |
| @@ -158,29 +167,29 @@ | ||
| 158 | 167 | return array(); |
| 159 | 168 | } |
| 160 | 169 | |
| 161 | 170 | $atts['payment'] = (array) $atts['payment']; |
| 171 | + | |
| 162 | 172 | if ( empty( $atts['payment']['action_id'] ) ) { |
| 163 | 173 | return array(); |
| 164 | 174 | } |
| 165 | 175 | |
| 166 | 176 | $form_action = FrmTransLiteAction::get_single_action_type( $atts['payment']['action_id'], 'payment' ); |
| 167 | - if ( ! $form_action ) { | |
| 168 | - return array(); | |
| 169 | - } | |
| 170 | 177 | |
| 171 | - return $form_action->post_content; | |
| 178 | + return $form_action ? $form_action->post_content : array(); | |
| 172 | 179 | } |
| 173 | 180 | |
| 174 | 181 | /** |
| 175 | 182 | * Allow entry values, default values, and other shortcodes |
| 176 | 183 | * |
| 177 | - * @param array $atts - Includes value (required), form, entry | |
| 178 | - * @return string|int | |
| 184 | + * @param array $atts Includes value (required), form, entry. | |
| 185 | + * | |
| 186 | + * @return int|string | |
| 179 | 187 | */ |
| 180 | 188 | public static function process_shortcodes( $atts ) { |
| 181 | 189 | $value = $atts['value']; |
| 182 | - if ( strpos( $value, '[' ) === false ) { | |
| 190 | + | |
| 191 | + if ( ! str_contains( $value, '[' ) ) { | |
| 183 | 192 | return $value; |
| 184 | 193 | } |
| 185 | 194 | |
| 186 | 195 | if ( is_callable( 'FrmProFieldsHelper::replace_non_standard_formidable_shortcodes' ) ) { |
| @@ -190,28 +199,29 @@ | ||
| 190 | 199 | if ( ! empty( $atts['entry'] ) ) { |
| 191 | 200 | if ( ! isset( $atts['form'] ) ) { |
| 192 | 201 | $atts['form'] = FrmForm::getOne( $atts['entry']->form_id ); |
| 193 | 202 | } |
| 203 | + | |
| 194 | 204 | $value = apply_filters( 'frm_content', $value, $atts['form'], $atts['entry'] ); |
| 195 | 205 | } |
| 196 | 206 | |
| 197 | - $value = do_shortcode( $value ); | |
| 198 | - return $value; | |
| 207 | + return do_shortcode( $value ); | |
| 199 | 208 | } |
| 200 | 209 | |
| 201 | 210 | /** |
| 202 | 211 | * @param object $sub |
| 212 | + * | |
| 203 | 213 | * @return string |
| 204 | 214 | */ |
| 205 | 215 | public static function format_billing_cycle( $sub ) { |
| 206 | 216 | $amount = self::formatted_amount( $sub ); |
| 207 | 217 | $interval = self::get_repeat_label_from_value( $sub->time_interval, $sub->interval_count ); |
| 208 | - if ( $sub->interval_count == 1 ) { | |
| 209 | - $amount = $amount . '/' . $interval; | |
| 210 | - } else { | |
| 211 | - $amount = $amount . ' every ' . $sub->interval_count . ' ' . $interval; | |
| 218 | + | |
| 219 | + if ( (int) $sub->interval_count === 1 ) { | |
| 220 | + return $amount . '/' . $interval; | |
| 212 | 221 | } |
| 213 | - return $amount; | |
| 222 | + | |
| 223 | + return $amount . ' every ' . $sub->interval_count . ' ' . $interval; | |
| 214 | 224 | } |
| 215 | 225 | |
| 216 | 226 | /** |
| 217 | 227 | * @return array |
| @@ -228,8 +238,9 @@ | ||
| 228 | 238 | /** |
| 229 | 239 | * @since 6.5, introduced in v1.16 of the Payments submodule. |
| 230 | 240 | * |
| 231 | 241 | * @param int $number |
| 242 | + * | |
| 232 | 243 | * @return array |
| 233 | 244 | */ |
| 234 | 245 | private static function get_plural_repeat_times( $number ) { |
| 235 | 246 | return array( |
| @@ -243,19 +254,22 @@ | ||
| 243 | 254 | /** |
| 244 | 255 | * @since 6.5, introduced in v1.16 of the Payments submodule. |
| 245 | 256 | * |
| 246 | 257 | * @param string $value |
| 247 | - * @param int $number | |
| 258 | + * @param int $number | |
| 259 | + * | |
| 248 | 260 | * @return string |
| 249 | 261 | */ |
| 250 | 262 | public static function get_repeat_label_from_value( $value, $number ) { |
| 251 | 263 | $times = self::get_plural_repeat_times( $number ); |
| 252 | - if ( isset( $times[ $value ] ) ) { | |
| 253 | - $value = $times[ $value ]; | |
| 254 | - } | |
| 255 | - return $value; | |
| 264 | + return $times[ $value ] ?? $value; | |
| 256 | 265 | } |
| 257 | 266 | |
| 267 | + /** | |
| 268 | + * @param array|float|int|object $payment | |
| 269 | + * | |
| 270 | + * @return string | |
| 271 | + */ | |
| 258 | 272 | public static function formatted_amount( $payment ) { |
| 259 | 273 | $currency = ''; |
| 260 | 274 | $amount = $payment; |
| 261 | 275 | |
| @@ -276,10 +290,37 @@ | ||
| 276 | 290 | return $amount; |
| 277 | 291 | } |
| 278 | 292 | |
| 279 | 293 | /** |
| 294 | + * Gets amount and currency from payment object or amount. | |
| 295 | + * | |
| 296 | + * @since 6.7 | |
| 297 | + * | |
| 298 | + * @param array|float|object|string $payment Payment object, payment array or amount. | |
| 299 | + * | |
| 300 | + * @return array Return the array with the first element is the amount, the second one is the currency value. | |
| 301 | + */ | |
| 302 | + public static function get_amount_and_currency_from_payment( $payment ) { | |
| 303 | + $currency = ''; | |
| 304 | + $amount = $payment; | |
| 305 | + | |
| 306 | + if ( is_object( $payment ) || is_array( $payment ) ) { | |
| 307 | + $payment = (array) $payment; | |
| 308 | + $amount = $payment['amount']; | |
| 309 | + $currency = self::get_action_setting( 'currency', array( 'payment' => $payment ) ); | |
| 310 | + } | |
| 311 | + | |
| 312 | + if ( ! $currency ) { | |
| 313 | + $currency = 'usd'; | |
| 314 | + } | |
| 315 | + | |
| 316 | + return array( $amount, $currency ); | |
| 317 | + } | |
| 318 | + | |
| 319 | + /** | |
| 280 | 320 | * @param array $currency |
| 281 | 321 | * @param float $amount |
| 322 | + * | |
| 282 | 323 | * @return void |
| 283 | 324 | */ |
| 284 | 325 | public static function format_amount_for_currency( $currency, &$amount ) { |
| 285 | 326 | $amount = number_format( $amount, $currency['decimals'], $currency['decimal_separator'], $currency['thousand_separator'] ); |
| @@ -291,28 +332,26 @@ | ||
| 291 | 332 | /** |
| 292 | 333 | * @return string |
| 293 | 334 | */ |
| 294 | 335 | public static function get_date_format() { |
| 295 | - $date_format = 'm/d/Y'; | |
| 296 | - if ( class_exists( 'FrmProAppHelper' ) ) { | |
| 297 | - $frmpro_settings = FrmProAppHelper::get_settings(); | |
| 298 | - if ( $frmpro_settings ) { | |
| 299 | - $date_format = $frmpro_settings->date_format; | |
| 300 | - } | |
| 301 | - } else { | |
| 302 | - $date_format = get_option( 'date_format' ); | |
| 336 | + if ( ! class_exists( 'FrmProAppHelper' ) ) { | |
| 337 | + return get_option( 'date_format' ); | |
| 303 | 338 | } |
| 304 | 339 | |
| 305 | - 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; | |
| 306 | 344 | } |
| 307 | 345 | |
| 308 | 346 | /** |
| 309 | 347 | * @param string $date |
| 310 | 348 | * @param string $format |
| 349 | + * | |
| 311 | 350 | * @return string |
| 312 | 351 | */ |
| 313 | 352 | public static function format_the_date( $date, $format = '' ) { |
| 314 | - if ( empty( $format ) ) { | |
| 353 | + if ( ! $format ) { | |
| 315 | 354 | $format = self::get_date_format(); |
| 316 | 355 | } |
| 317 | 356 | return date_i18n( $format, strtotime( $date ) ); |
| 318 | 357 | } |
| @@ -322,45 +361,62 @@ | ||
| 322 | 361 | * |
| 323 | 362 | * @return int |
| 324 | 363 | */ |
| 325 | 364 | public static function get_user_id_for_current_payment() { |
| 326 | - $user_id = 0; | |
| 327 | - if ( is_user_logged_in() ) { | |
| 328 | - $user_id = get_current_user_id(); | |
| 329 | - } | |
| 330 | - 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 ); | |
| 331 | 379 | } |
| 332 | 380 | |
| 333 | 381 | /** |
| 334 | 382 | * @param int $user_id |
| 383 | + * | |
| 335 | 384 | * @return string |
| 336 | 385 | */ |
| 337 | 386 | public static function get_user_link( $user_id ) { |
| 338 | - $user_link = esc_html__( 'Guest', 'formidable' ); | |
| 339 | 387 | if ( $user_id ) { |
| 340 | 388 | $user = get_userdata( $user_id ); |
| 389 | + | |
| 341 | 390 | if ( $user ) { |
| 342 | - $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>'; | |
| 343 | 392 | } |
| 344 | 393 | } |
| 345 | - return $user_link; | |
| 394 | + | |
| 395 | + return esc_html__( 'Guest', 'formidable' ); | |
| 346 | 396 | } |
| 347 | 397 | |
| 348 | 398 | /** |
| 349 | 399 | * @param mixed $value |
| 350 | 400 | * @param string $label |
| 401 | + * | |
| 351 | 402 | * @return void |
| 352 | 403 | */ |
| 353 | 404 | public static function show_in_table( $value, $label ) { |
| 354 | - if ( ! empty( $value ) ) { ?> | |
| 355 | - <tr> | |
| 356 | - <th scope="row"><?php echo esc_html( $label ); ?>:</th> | |
| 357 | - <td> | |
| 358 | - <?php echo esc_html( $value ); ?> | |
| 359 | - </td> | |
| 360 | - </tr> | |
| 361 | - <?php | |
| 405 | + if ( ! $value ) { | |
| 406 | + return; | |
| 362 | 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 | |
| 363 | 419 | } |
| 364 | 420 | |
| 365 | 421 | /** |
| 366 | 422 | * Echo a link that includes a data-deleteconfirm attribute. |
| @@ -368,14 +424,15 @@ | ||
| 368 | 424 | * |
| 369 | 425 | * @since 6.5 |
| 370 | 426 | * |
| 371 | 427 | * @param string $link |
| 428 | + * | |
| 372 | 429 | * @return void |
| 373 | 430 | */ |
| 374 | 431 | public static function echo_confirmation_link( $link ) { |
| 375 | - $filter = __CLASS__ . '::allow_deleteconfirm_data_attribute'; | |
| 432 | + $filter = self::class . '::allow_deleteconfirm_data_attribute'; | |
| 376 | 433 | add_filter( 'frm_striphtml_allowed_tags', $filter ); |
| 377 | - echo FrmAppHelper::kses( $link, array( 'a' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 434 | + FrmAppHelper::kses_echo( $link, array( 'a' ) ); | |
| 378 | 435 | remove_filter( 'frm_striphtml_allowed_tags', $filter ); |
| 379 | 436 | } |
| 380 | 437 | |
| 381 | 438 | /** |
| @@ -384,8 +441,9 @@ | ||
| 384 | 441 | * |
| 385 | 442 | * @since 6.5 |
| 386 | 443 | * |
| 387 | 444 | * @param array $allowed |
| 445 | + * | |
| 388 | 446 | * @return array |
| 389 | 447 | */ |
| 390 | 448 | public static function allow_deleteconfirm_data_attribute( $allowed ) { |
| 391 | 449 | $allowed['a']['data-deleteconfirm'] = true; |
| @@ -398,9 +456,9 @@ | ||
| 398 | 456 | * Formats non zero-decimal currencies. |
| 399 | 457 | * |
| 400 | 458 | * @since 6.5 |
| 401 | 459 | * |
| 402 | - * @param string|int $amount | |
| 460 | + * @param int|string $amount | |
| 403 | 461 | * @param WP_Post $action |
| 404 | 462 | * |
| 405 | 463 | * @return string |
| 406 | 464 | */ |
| @@ -409,11 +467,209 @@ | ||
| 409 | 467 | return $amount; |
| 410 | 468 | } |
| 411 | 469 | |
| 412 | 470 | $currency = FrmCurrencyHelper::get_currency( $action->post_content['currency'] ); |
| 471 | + | |
| 413 | 472 | if ( ! empty( $currency['decimals'] ) ) { |
| 414 | - $amount = number_format( ( $amount / 100 ), 2, '.', '' ); | |
| 473 | + return number_format( $amount / 100, 2, '.', '' ); | |
| 415 | 474 | } |
| 416 | 475 | |
| 417 | 476 | return $amount; |
| 477 | + } | |
| 478 | + | |
| 479 | + /** | |
| 480 | + * Get a human readable translated 'Test' or 'Live' string if the column value is defined. | |
| 481 | + * Old payments will just output an empty string. | |
| 482 | + * | |
| 483 | + * @since 6.6 | |
| 484 | + * | |
| 485 | + * @param stdClass $payment | |
| 486 | + * | |
| 487 | + * @return string | |
| 488 | + */ | |
| 489 | + public static function get_test_mode_display_string( $payment ) { | |
| 490 | + if ( ! isset( $payment->test ) ) { | |
| 491 | + return ''; | |
| 492 | + } | |
| 493 | + return $payment->test ? __( 'Test', 'formidable' ) : __( 'Live', 'formidable' ); | |
| 494 | + } | |
| 495 | + | |
| 496 | + /** | |
| 497 | + * Returns the count of completed payments. | |
| 498 | + * | |
| 499 | + * @since 6.11 | |
| 500 | + * | |
| 501 | + * @param array $payments | |
| 502 | + * | |
| 503 | + * @return int | |
| 504 | + */ | |
| 505 | + public static function count_completed_payments( $payments ) { | |
| 506 | + $count = 0; | |
| 507 | + | |
| 508 | + foreach ( $payments as $payment ) { | |
| 509 | + if ( $payment->status === 'complete' ) { | |
| 510 | + $count++; | |
| 511 | + } | |
| 512 | + } | |
| 513 | + | |
| 514 | + return $count; | |
| 515 | + } | |
| 516 | + | |
| 517 | + /** | |
| 518 | + * @return array | |
| 519 | + */ | |
| 520 | + public static function get_gateways() { | |
| 521 | + return apply_filters( 'frm_payment_gateways', array() ); | |
| 522 | + } | |
| 523 | + | |
| 524 | + /** | |
| 525 | + * @param array|string $gateway | |
| 526 | + * @param string $setting | |
| 527 | + * | |
| 528 | + * @return mixed | |
| 529 | + */ | |
| 530 | + public static function get_setting_for_gateway( $gateway, $setting ) { | |
| 531 | + $gateways = self::get_gateways(); | |
| 532 | + $value = ''; | |
| 533 | + | |
| 534 | + if ( is_array( $gateway ) ) { | |
| 535 | + $gateway = reset( $gateway ); | |
| 536 | + } | |
| 537 | + | |
| 538 | + if ( isset( $gateways[ $gateway ] ) ) { | |
| 539 | + return $gateways[ $gateway ][ $setting ]; | |
| 540 | + } | |
| 541 | + | |
| 542 | + return $value; | |
| 543 | + } | |
| 544 | + | |
| 545 | + /** | |
| 546 | + * Show the currency dropdown for a Payment action. | |
| 547 | + * When Square is selected, this dropdown is disabled and will always use "Use Square Merchant Currency". | |
| 548 | + * | |
| 549 | + * @since 6.22 | |
| 550 | + * | |
| 551 | + * @param string $id | |
| 552 | + * @param string $name | |
| 553 | + * @param array $action_settings | |
| 554 | + * | |
| 555 | + * @return void | |
| 556 | + */ | |
| 557 | + public static function show_currency_dropdown( $id, $name, $action_settings ) { | |
| 558 | + $selected = $action_settings['currency']; | |
| 559 | + $gateways = (array) $action_settings['gateway']; | |
| 560 | + $select_attrs = array( | |
| 561 | + 'id' => $id, | |
| 562 | + 'name' => $name, | |
| 563 | + ); | |
| 564 | + | |
| 565 | + if ( in_array( 'square', $gateways, true ) ) { | |
| 566 | + $select_attrs['disabled'] = 'disabled'; | |
| 567 | + $selected = ''; | |
| 568 | + } | |
| 569 | + | |
| 570 | + $currencies = FrmCurrencyHelper::get_currencies(); | |
| 571 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 572 | + ?> | |
| 573 | + <select <?php FrmAppHelper::array_to_html_params( $select_attrs, true ); ?>> | |
| 574 | + <?php | |
| 575 | + if ( in_array( 'square', $gateways, true ) ) { | |
| 576 | + $option_params = array( | |
| 577 | + 'class' => 'square-currency', | |
| 578 | + 'selected' => 'selected', | |
| 579 | + 'value' => 'square', | |
| 580 | + ); | |
| 581 | + ?> | |
| 582 | + <option <?php FrmAppHelper::array_to_html_params( $option_params, true ); ?>><?php esc_html_e( 'Use Square Merchant Currency', 'formidable' ); ?></option> | |
| 583 | + <?php | |
| 584 | + } | |
| 585 | + | |
| 586 | + foreach ( $currencies as $code => $currency ) { | |
| 587 | + FrmHtmlHelper::echo_dropdown_option( | |
| 588 | + $currency['name'] . ' (' . strtoupper( $code ) . ')', | |
| 589 | + $selected === strtolower( $code ), | |
| 590 | + array( | |
| 591 | + 'value' => strtolower( $code ), | |
| 592 | + ) | |
| 593 | + ); | |
| 594 | + unset( $currency, $code ); | |
| 595 | + } | |
| 596 | + ?> | |
| 597 | + </select> | |
| 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 ); | |
| 418 | 674 | } |
| 419 | 675 | } |