← All changes
|
includes/Admin/Elementor/Form_Actions/Paystack_Integration.php
+17
-11
2.1.1
→
2.4.1
View file →
| @@ -2,9 +2,11 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Better_Payment\Lite\Admin\Elementor\Form_Actions; |
| 4 | 4 | |
| 5 | 5 | use Better_Payment\Lite\Admin\DB; |
| 6 | +use Better_Payment\Lite\Campaign\CampaignStats; | |
| 6 | 7 | use Better_Payment\Lite\Classes\Handler; |
| 8 | +use Better_Payment\Lite\Classes\PaymentRequestGuard; | |
| 7 | 9 | use Better_Payment\Lite\Traits\Helper; |
| 8 | 10 | use Elementor\Controls_Manager; |
| 9 | 11 | use ElementorPro\Modules\Forms\Classes\Action_Base; |
| 10 | 12 | use ElementorPro\Modules\Forms\Classes\Ajax_Handler; |
| @@ -167,21 +169,21 @@ | ||
| 167 | 169 | $ajax_handler->add_error_message( 'Amount field is required!' ); |
| 168 | 170 | return false; |
| 169 | 171 | } |
| 170 | 172 | |
| 171 | - $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 ); | |
| 172 | 176 | |
| 173 | - if ( empty( $amount ) && ! empty( $sent_data['primary_payment_amount_radio'] ) ) { | |
| 174 | - $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; | |
| 175 | 180 | } |
| 176 | 181 | |
| 177 | - $quantity = 1; | |
| 178 | - if ( !empty( $sent_data[ 'pay_quantity' ] ) ) { | |
| 179 | - $quantity = intval( $sent_data[ 'pay_quantity' ][ 'value' ] ); | |
| 180 | - $amount *= $quantity; | |
| 181 | - } | |
| 182 | + $quantity = $guarded['quantity']; | |
| 183 | + $amount = $guarded['amount']; | |
| 182 | 184 | |
| 183 | - $order_id = 'paystack_' . uniqid(); | |
| 185 | + $order_id = Handler::new_order_id( 'paystack' ); | |
| 184 | 186 | |
| 185 | 187 | $redirection_url_success = get_permalink( $page_id ); |
| 186 | 188 | $redirection_url_error = get_permalink( $page_id ); |
| 187 | 189 | |
| @@ -253,9 +255,9 @@ | ||
| 253 | 255 | 'source' => 'paystack' |
| 254 | 256 | ]; |
| 255 | 257 | |
| 256 | 258 | // Get campaign_id from form data if available |
| 257 | - $campaign_id = ! empty( $sent_data['campaign_id'] ) ? sanitize_text_field( $sent_data['campaign_id'] ) : ''; | |
| 259 | + $campaign_id = $guarded['campaign_id']; | |
| 258 | 260 | |
| 259 | 261 | Handler::payment_create( |
| 260 | 262 | [ |
| 261 | 263 | 'amount' => $amount, |
| @@ -261,9 +263,10 @@ | ||
| 261 | 263 | 'amount' => $amount, |
| 262 | 264 | 'order_id' => $order_id, |
| 263 | 265 | 'payment_date' => date( 'Y-m-d H:i:s' ), |
| 264 | 266 | 'source' => 'paystack', |
| 265 | - '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 ) : '', | |
| 266 | 269 | 'customer_info' => maybe_serialize( $response_ar ), |
| 267 | 270 | 'form_fields_info' => maybe_serialize( $better_form_fields ), |
| 268 | 271 | 'obj_id' => !empty($response_ar->id) ? sanitize_text_field($response_ar->id) : '', |
| 269 | 272 | 'status' => 'unpaid', |
| @@ -271,8 +274,11 @@ | ||
| 271 | 274 | 'referer' => "elementor-form", |
| 272 | 275 | 'campaign_id' => $campaign_id, |
| 273 | 276 | ] |
| 274 | 277 | ); |
| 278 | + if ( $campaign_id ) { | |
| 279 | + CampaignStats::bust_cache( (int) $campaign_id ); | |
| 280 | + } | |
| 275 | 281 | |
| 276 | 282 | $authorization_url = ! empty( $response_ar->data->authorization_url ) ? esc_url_raw( $response_ar->data->authorization_url ) : ''; |
| 277 | 283 | |
| 278 | 284 | $ajax_handler->add_response_data( 'better_paystack_data', [ |