← All changes
|
includes/Admin/Elementor/Form_Actions/Paystack_Integration.php
+13
-11
2.3.3
→
2.4.1
View file →
| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use Better_Payment\Lite\Admin\DB; |
| 6 | 6 | use Better_Payment\Lite\Campaign\CampaignStats; |
| 7 | 7 | use Better_Payment\Lite\Classes\Handler; |
| 8 | +use Better_Payment\Lite\Classes\PaymentRequestGuard; | |
| 8 | 9 | use Better_Payment\Lite\Traits\Helper; |
| 9 | 10 | use Elementor\Controls_Manager; |
| 10 | 11 | use ElementorPro\Modules\Forms\Classes\Action_Base; |
| 11 | 12 | use ElementorPro\Modules\Forms\Classes\Ajax_Handler; |
| @@ -168,21 +169,21 @@ | ||
| 168 | 169 | $ajax_handler->add_error_message( 'Amount field is required!' ); |
| 169 | 170 | return false; |
| 170 | 171 | } |
| 171 | 172 | |
| 172 | - $amount = isset( $sent_data['payment_amount'] ) ? floatval($sent_data['payment_amount']) : 0; | |
| 173 | + // Amount and quantity come from the form's field settings, never from the | |
| 174 | + // request — see PaymentRequestGuard. | |
| 175 | + $guarded = ( new PaymentRequestGuard() )->resolve_elementor_form_payment( (array) $el_form_form_settings, (array) $sent_data ); | |
| 173 | 176 | |
| 174 | - if ( empty( $amount ) && ! empty( $sent_data['primary_payment_amount_radio'] ) ) { | |
| 175 | - $amount = floatval( $sent_data['primary_payment_amount_radio'] ); | |
| 177 | + if ( is_wp_error( $guarded ) ) { | |
| 178 | + $ajax_handler->add_error_message( $guarded->get_error_message() ); | |
| 179 | + return false; | |
| 176 | 180 | } |
| 177 | 181 | |
| 178 | - $quantity = 1; | |
| 179 | - if ( !empty( $sent_data[ 'pay_quantity' ] ) ) { | |
| 180 | - $quantity = intval( $sent_data[ 'pay_quantity' ][ 'value' ] ); | |
| 181 | - $amount *= $quantity; | |
| 182 | - } | |
| 182 | + $quantity = $guarded['quantity']; | |
| 183 | + $amount = $guarded['amount']; | |
| 183 | 184 | |
| 184 | - $order_id = 'paystack_' . uniqid(); | |
| 185 | + $order_id = Handler::new_order_id( 'paystack' ); | |
| 185 | 186 | |
| 186 | 187 | $redirection_url_success = get_permalink( $page_id ); |
| 187 | 188 | $redirection_url_error = get_permalink( $page_id ); |
| 188 | 189 | |
| @@ -254,9 +255,9 @@ | ||
| 254 | 255 | 'source' => 'paystack' |
| 255 | 256 | ]; |
| 256 | 257 | |
| 257 | 258 | // Get campaign_id from form data if available |
| 258 | - $campaign_id = ! empty( $sent_data['campaign_id'] ) ? sanitize_text_field( $sent_data['campaign_id'] ) : ''; | |
| 259 | + $campaign_id = $guarded['campaign_id']; | |
| 259 | 260 | |
| 260 | 261 | Handler::payment_create( |
| 261 | 262 | [ |
| 262 | 263 | 'amount' => $amount, |
| @@ -262,9 +263,10 @@ | ||
| 262 | 263 | 'amount' => $amount, |
| 263 | 264 | 'order_id' => $order_id, |
| 264 | 265 | 'payment_date' => date( 'Y-m-d H:i:s' ), |
| 265 | 266 | 'source' => 'paystack', |
| 266 | - 'transaction_id' => '', | |
| 267 | + // Paystack's reference, so verification can bind it to this order. | |
| 268 | + 'transaction_id' => ! empty( $response_ar->data->reference ) ? sanitize_text_field( $response_ar->data->reference ) : '', | |
| 267 | 269 | 'customer_info' => maybe_serialize( $response_ar ), |
| 268 | 270 | 'form_fields_info' => maybe_serialize( $better_form_fields ), |
| 269 | 271 | 'obj_id' => !empty($response_ar->id) ? sanitize_text_field($response_ar->id) : '', |
| 270 | 272 | 'status' => 'unpaid', |