| @@ -12,22 +12,42 @@ | ||
| 12 | 12 | /** |
| 13 | 13 | * Show a table of either payments for subscriptions. |
| 14 | 14 | * |
| 15 | 15 | * @param int $id |
| 16 | + * | |
| 16 | 17 | * @return void |
| 17 | 18 | */ |
| 18 | 19 | public static function show( $id = 0 ) { |
| 19 | 20 | if ( ! $id ) { |
| 20 | 21 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
| 22 | + | |
| 21 | 23 | if ( ! $id ) { |
| 22 | 24 | wp_die( esc_html__( 'Please select a payment to view', 'formidable' ) ); |
| 23 | 25 | } |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | - $payment = self::get_payment_row( $id ); | |
| 28 | + FrmAppHelper::include_svg(); | |
| 29 | + | |
| 30 | + $table_name = self::table_name(); | |
| 31 | + $payment = self::get_payment_row( $id ); | |
| 32 | + | |
| 33 | + if ( ! $payment ) { | |
| 34 | + $trans_type = $table_name === 'subscriptions' ? __( 'Subscription', 'formidable' ) : __( 'Payment', 'formidable' ); | |
| 35 | + FrmAppController::show_error_modal( | |
| 36 | + array( | |
| 37 | + /* translators: %s: Transaction type */ | |
| 38 | + 'title' => sprintf( __( 'You can\'t view the %s', 'formidable' ), $trans_type ), | |
| 39 | + /* translators: %s: Transaction type */ | |
| 40 | + 'body' => sprintf( __( 'You are trying to view a %s that does not exist', 'formidable' ), $trans_type ), | |
| 41 | + /* translators: %s: Transaction table name */ | |
| 42 | + 'cancel_url' => sprintf( admin_url( 'admin.php?page=formidable-payments&trans_type=%s' ), $table_name ), | |
| 43 | + ) | |
| 44 | + ); | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 27 | 48 | $date_format = get_option( 'date_format' ); |
| 28 | 49 | $user_name = FrmTransLiteAppHelper::get_user_link( $payment->user_id ); |
| 29 | - $table_name = self::table_name(); | |
| 30 | 50 | $entry = FrmEntry::getOne( $payment->item_id ); |
| 31 | 51 | $form_id = $entry ? $entry->form_id : false; |
| 32 | 52 | |
| 33 | 53 | if ( $table_name !== 'payments' ) { |
| @@ -33,14 +53,14 @@ | ||
| 33 | 53 | if ( $table_name !== 'payments' ) { |
| 34 | 54 | $subscription = $payment; |
| 35 | 55 | } |
| 36 | 56 | |
| 37 | - FrmAppHelper::include_svg(); | |
| 38 | 57 | include FrmTransLiteAppHelper::plugin_path() . '/views/' . $table_name . '/show.php'; |
| 39 | 58 | } |
| 40 | 59 | |
| 41 | 60 | /** |
| 42 | 61 | * @param int $id |
| 62 | + * | |
| 43 | 63 | * @return object|null |
| 44 | 64 | */ |
| 45 | 65 | private static function get_payment_row( $id ) { |
| 46 | 66 | global $wpdb; |
| @@ -47,9 +67,9 @@ | ||
| 47 | 67 | |
| 48 | 68 | $table_name = self::table_name(); |
| 49 | 69 | |
| 50 | 70 | // @codingStandardsIgnoreStart |
| 51 | - $payment = $wpdb->get_row( | |
| 71 | + return $wpdb->get_row( | |
| 52 | 72 | $wpdb->prepare( |
| 53 | 73 | "SELECT |
| 54 | 74 | p.*, e.user_id |
| 55 | 75 | FROM `{$wpdb->prefix}frm_{$table_name}` p |
| @@ -58,10 +78,8 @@ | ||
| 58 | 78 | $id |
| 59 | 79 | ) |
| 60 | 80 | ); |
| 61 | 81 | // @codingStandardsIgnoreEnd |
| 62 | - | |
| 63 | - return $payment; | |
| 64 | 82 | } |
| 65 | 83 | |
| 66 | 84 | /** |
| 67 | 85 | * Handle routing for deleting a payment. |
| @@ -96,19 +114,18 @@ | ||
| 96 | 114 | $allowed = array( 'payments', 'subscriptions' ); |
| 97 | 115 | $default = reset( $allowed ); |
| 98 | 116 | $name = FrmAppHelper::get_param( 'type', $default, 'get', 'sanitize_text_field' ); |
| 99 | 117 | |
| 100 | - if ( ! in_array( $name, $allowed, true ) ) { | |
| 101 | - $name = $default; | |
| 102 | - } | |
| 103 | - | |
| 104 | - return $name; | |
| 118 | + return in_array( $name, $allowed, true ) ? $name : $default; | |
| 105 | 119 | } |
| 106 | 120 | |
| 107 | 121 | /** |
| 108 | - * @return FrmTransLiteSubscription|FrmTransLitePayment | |
| 122 | + * @return FrmTransLitePayment|FrmTransLiteSubscription | |
| 109 | 123 | */ |
| 110 | 124 | private static function the_class() { |
| 111 | - $class_name = self::table_name() === 'subscriptions' ? 'FrmTransLiteSubscription' : 'FrmTransLitePayment'; | |
| 112 | - return new $class_name(); | |
| 125 | + if ( self::table_name() === 'subscriptions' ) { | |
| 126 | + return new FrmTransLiteSubscription(); | |
| 127 | + } | |
| 128 | + | |
| 129 | + return new FrmTransLitePayment(); | |
| 113 | 130 | } |
| 114 | 131 | } |