@@ -532,10 +532,38 @@ public function payment_scripts() {
532
532
$ the_order_key = $ order ->get_order_key ();
533
533
$ currency = $ order ->get_currency ();
534
534
$ custom_nonce = wp_create_nonce ();
535
- $ redirect_url = WC ()-> api_request_url ( ' FLW_WC_Payment_Gateway ' ) . ' ?order_id= ' . $ order_id . ' &_wpnonce= ' . $ custom_nonce ;
535
+ $ redirect_url = '' ;
536
536
537
- if ( $ the_order_id === $ order_id && $ the_order_key === $ order_key ) {
537
+ $ flutterwave_woo_url = WC ()->api_request_url ( 'FLW_WC_Payment_Gateway ' );
538
+
539
+ // Parse the base URL to check for existing query parameters.
540
+ $ url_parts = wp_parse_url ( $ flutterwave_woo_url );
541
+
542
+ // If the base URL already has query parameters, merge them with new ones.
543
+ if ( isset ( $ url_parts ['query ' ] ) ) {
544
+ // Convert the query string to an array.
545
+ parse_str ( $ url_parts ['query ' ], $ query_array );
546
+
547
+ // Add the new parameters to the existing query array.
548
+ $ query_array ['order_id ' ] = $ order_id ;
549
+
550
+ // Rebuild the query string with the new parameters.
551
+ $ new_query_string = http_build_query ( $ query_array );
552
+
553
+ // Rebuild the final URL with the new query string.
554
+ $ redirect_url = $ url_parts ['scheme ' ] . ':// ' . $ url_parts ['host ' ] . $ url_parts ['path ' ] . '? ' . $ new_query_string ;
555
+ } else {
556
+ // If no existing query parameters, simply append the new ones.
557
+ $ redirect_url = add_query_arg (
558
+ array (
559
+ 'order_id ' => $ order_id ,
560
+ '_wpnonce ' => $ custom_nonce ,
561
+ ),
562
+ $ flutterwave_woo_url
563
+ );
564
+ }
538
565
566
+ if ( $ the_order_id === $ order_id && $ the_order_key === $ order_key ) {
539
567
$ payment_args ['email ' ] = $ email ;
540
568
$ payment_args ['amount ' ] = $ amount ;
541
569
$ payment_args ['tx_ref ' ] = $ txnref ;
@@ -560,7 +588,7 @@ public function payment_scripts() {
560
588
}
561
589
562
590
/**
563
- * Verify payment made on the checkout page
591
+ * Verify payment made on the checkout page.
564
592
*
565
593
* @return void
566
594
*/
@@ -599,7 +627,7 @@ public function flw_verify_payment() {
599
627
}
600
628
601
629
/**
602
- * Process Webhook
630
+ * Process Webhook.
603
631
*/
604
632
public function flutterwave_webhooks () {
605
633
$ public_key = $ this ->public_key ;
@@ -680,6 +708,18 @@ public function flutterwave_webhooks() {
680
708
$ o = explode ( '_ ' , $ txn_ref );
681
709
$ order_id = intval ( $ o [1 ] );
682
710
$ order = wc_get_order ( $ order_id );
711
+
712
+ if ( ! $ order ) {
713
+ wp_send_json (
714
+ array (
715
+ 'status ' => 'error ' ,
716
+ 'message ' => 'Invalid Reference ' ,
717
+ 'reason ' => 'Order does not belong to store ' ,
718
+ ),
719
+ WP_Http::BAD_REQUEST
720
+ );
721
+ }
722
+
683
723
// get order status.
684
724
$ current_order_status = $ order ->get_status ();
685
725
0 commit comments