| @@ -57,8 +57,21 @@ | ||
| 57 | 57 | $tab = in_array( $request->get_param( 'tab' ), [ 'transactions', 'subscriptions' ], true ) |
| 58 | 58 | ? $request->get_param( 'tab' ) |
| 59 | 59 | : 'transactions'; |
| 60 | 60 | |
| 61 | + // Subscription rows are Better Payment's own Stripe recurring and split | |
| 62 | + // payments — Pro features, shown only in the Subscriptions tab Pro renders. | |
| 63 | + // Without Pro nothing can display them, so don't query for them. | |
| 64 | + if ( 'subscriptions' === $tab && ! apply_filters( 'better_payment/pro_enabled', false ) ) { | |
| 65 | + return rest_ensure_response( [ | |
| 66 | + 'transactions' => [], | |
| 67 | + 'total' => 0, | |
| 68 | + 'page' => max( 1, (int) $request->get_param( 'page' ) ), | |
| 69 | + 'per_page' => max( 1, (int) $request->get_param( 'per_page' ) ), | |
| 70 | + 'pages' => 1, | |
| 71 | + ] ); | |
| 72 | + } | |
| 73 | + | |
| 61 | 74 | $result = DB::get_user_transactions_paginated( $email, [ |
| 62 | 75 | 'page' => $request->get_param( 'page' ), |
| 63 | 76 | 'per_page' => $request->get_param( 'per_page' ), |
| 64 | 77 | 'type' => $tab, |
| @@ -63,9 +76,8 @@ | ||
| 63 | 76 | 'per_page' => $request->get_param( 'per_page' ), |
| 64 | 77 | 'type' => $tab, |
| 65 | 78 | ] ); |
| 66 | 79 | |
| 67 | - $helper = new Helper(); | |
| 68 | 80 | $transactions = []; |
| 69 | 81 | |
| 70 | 82 | foreach ( $result['transactions'] as $txn ) { |
| 71 | 83 | $form_fields_info = maybe_unserialize( $txn->form_fields_info ); |
| @@ -101,28 +113,27 @@ | ||
| 101 | 113 | 'id' => intval( $txn->id ), |
| 102 | 114 | 'amount' => floatval( $txn->amount ), |
| 103 | 115 | 'currency' => sanitize_text_field( $txn->currency ), |
| 104 | 116 | 'status' => $status_raw, |
| 105 | - 'status_color' => $helper->get_color_by_transaction_status( $status_raw, 'v2' ), | |
| 106 | - 'status_label' => ucfirst( $helper->get_type_by_transaction_status( $status_raw, 'v2' ) ), | |
| 117 | + // From the stored row: an unconfirmed pre-2.4.0 free checkout reads Incomplete | |
| 118 | + // (Helper::transaction_status_type()), as it is in no dashboard figure. | |
| 119 | + 'status_type' => Helper::transaction_status_type( $txn, 'v2' ), | |
| 120 | + 'status_color' => Helper::transaction_status_color( $txn ), | |
| 121 | + 'status_label' => Helper::transaction_status_label( $txn ), | |
| 107 | 122 | 'payment_date' => $payment_date_formatted, |
| 108 | 123 | 'transaction_id' => sanitize_text_field( $txn->transaction_id ), |
| 109 | 124 | 'source' => strtolower( sanitize_text_field( $txn->source ) ), |
| 110 | 125 | 'customer_name' => $customer_name, |
| 111 | 126 | 'customer_email' => $customer_email, |
| 112 | - 'is_subscription'=> ! empty( $form_fields_info['subscription_id'] ) ? 'Subscription' : 'One Time', | |
| 127 | + // 'One Time' unless Pro labels the row (better_payment/transaction/payment_type). | |
| 128 | + 'is_subscription'=> Helper::payment_type_label( $form_fields_info ), | |
| 113 | 129 | 'is_imported' => ! empty( $form_fields_info['is_imported'] ) && 1 === intval( $form_fields_info['is_imported'] ), |
| 114 | 130 | ]; |
| 115 | 131 | |
| 116 | 132 | if ( 'subscriptions' === $tab ) { |
| 117 | - $row['subscription_id'] = sanitize_text_field( $form_fields_info['subscription_id'] ?? '' ); | |
| 118 | - $row['subscription_plan_id'] = sanitize_text_field( $form_fields_info['subscription_plan_id'] ?? '' ); | |
| 119 | - $row['subscription_status'] = sanitize_text_field( $form_fields_info['subscription_status'] ?? '' ); | |
| 120 | - $row['subscription_interval'] = sanitize_text_field( $form_fields_info['subscription_interval'] ?? '' ); | |
| 121 | - $row['subscription_created_date'] = intval( $form_fields_info['subscription_created_date'] ?? 0 ); | |
| 122 | - $row['subscription_current_period_end'] = intval( $form_fields_info['subscription_current_period_end'] ?? 0 ); | |
| 123 | - $row['is_payment_split_payment'] = ! empty( $form_fields_info['is_payment_split_payment'] ) ? intval( $form_fields_info['is_payment_split_payment'] ) : 0; | |
| 124 | - $row['subscription_product_name'] = ''; | |
| 133 | + // Pro builds the subscription columns on `better_payment/user_api/subscription_row`. | |
| 134 | + $built = apply_filters( 'better_payment/user_api/subscription_row', $row, $form_fields_info, $txn ); | |
| 135 | + $row = is_array( $built ) ? $built : $row; | |
| 125 | 136 | |
| 126 | 137 | $row = apply_filters( 'better_payment/user_api/enrich_subscription_row', $row ); |
| 127 | 138 | } |
| 128 | 139 | |