Skip to content

Commit 75154b7

Browse files
Merge pull request #49 from Flutterwave/dev
Pull changes from dev
2 parents 0adc7f8 + ce75428 commit 75154b7

11 files changed

+200
-55
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog
2+
## 2.3.6 | 01-09-2025
3+
Bug Fixes and Webhook Handler improvements.
4+
### Version Changes
5+
- [FIXED] Dynamic Adjustment to Custom Permalink Set by Merchant.
6+
- [FIXED] Redirect Payment option return a Payment Mismatch Error.
7+
- [FIXED] Reject Invalid Order Reference hooks.
28
## 2.3.5 | 01-01-2024
39
Added Support for WooCommerce HPOS.
410
### Version Changes

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
== Changelog ==
2+
= 2.3.6 =
3+
* Fixed: Dynamic Adjustment to Custom Permalink Set by Merchant.
4+
* Fixed: Redirect Payment option return a Payment Mismatch Error.
25
= 2.3.5 =
36
* Added: Support for WooCommerce HPOS.
47
* Fixed: WooCommerce Blocks Compatibility Issues with WooCommerce 7.0 to 6.9.1.

includes/class-flutterwave.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ final class Flutterwave {
1818
*
1919
* @var string
2020
*/
21-
public string $version = '2.3.5';
21+
public string $version = '2.3.6';
2222

2323
/**
2424
* Plugin API version.
2525
*
2626
* @var string
2727
*/
2828
public string $api_version = 'v3';
29+
2930
/**
3031
* Plugin instance.
3132
*
@@ -119,7 +120,6 @@ private function init() {
119120
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
120121

121122
$this->register_payment_gateway();
122-
123123
}
124124

125125
/**

includes/class-flw-wc-payment-gateway.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,38 @@ public function payment_scripts() {
532532
$the_order_key = $order->get_order_key();
533533
$currency = $order->get_currency();
534534
$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 = '';
536536

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+
}
538565

566+
if ( $the_order_id === $order_id && $the_order_key === $order_key ) {
539567
$payment_args['email'] = $email;
540568
$payment_args['amount'] = $amount;
541569
$payment_args['tx_ref'] = $txnref;
@@ -560,7 +588,7 @@ public function payment_scripts() {
560588
}
561589

562590
/**
563-
* Verify payment made on the checkout page
591+
* Verify payment made on the checkout page.
564592
*
565593
* @return void
566594
*/
@@ -599,7 +627,7 @@ public function flw_verify_payment() {
599627
}
600628

601629
/**
602-
* Process Webhook
630+
* Process Webhook.
603631
*/
604632
public function flutterwave_webhooks() {
605633
$public_key = $this->public_key;
@@ -680,6 +708,18 @@ public function flutterwave_webhooks() {
680708
$o = explode( '_', $txn_ref );
681709
$order_id = intval( $o[1] );
682710
$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+
683723
// get order status.
684724
$current_order_status = $order->get_status();
685725

includes/client/class-flw-wc-payment-gateway-request.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function generate_checkout_hash( array $data ): string {
8282
public function get_prepared_payload( \WC_Order $order, string $secret_key, bool $testing = false ): array {
8383
$order_id = $order->get_id();
8484
$txnref = 'WOOC_' . $order_id . '_' . time();
85-
$amount = $order->get_total();
85+
$amount = (float) $order->get_total();
8686
$currency = $order->get_currency();
8787
$email = $order->get_billing_email();
8888

@@ -95,21 +95,48 @@ public function get_prepared_payload( \WC_Order $order, string $secret_key, bool
9595
throw new \InvalidArgumentException( 'This Payment Method is current unavailable as Administrator is yet to Configure it.Please contact Administrator for more information.' );
9696
}
9797

98-
$data_to_hash = array(
98+
$data_to_hash = array(
9999
'amount' => $amount,
100100
'currency' => $currency,
101101
'email' => $email,
102102
'tx_ref' => $txnref,
103103
'secret_key' => $secret_key,
104104
);
105+
105106
$checkout_hash = $this->generate_checkout_hash( $data_to_hash );
106107

108+
// Parse the base URL to check for existing query parameters.
109+
$url_parts = wp_parse_url( $this->notify_url );
110+
111+
// If the base URL already has query parameters, merge them with new ones.
112+
if ( isset( $url_parts['query'] ) ) {
113+
// Convert the query string to an array.
114+
parse_str( $url_parts['query'], $query_array );
115+
116+
// Add the new parameters to the existing query array.
117+
$query_array['order_id'] = $order_id;
118+
119+
// Rebuild the query string with the new parameters.
120+
$new_query_string = http_build_query( $query_array );
121+
122+
// Rebuild the final URL with the new query string.
123+
$callback_url = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'] . '?' . $new_query_string;
124+
} else {
125+
// If no existing query parameters, simply append the new ones.
126+
$callback_url = add_query_arg(
127+
array(
128+
'order_id' => $order_id,
129+
),
130+
$this->notify_url
131+
);
132+
}
133+
107134
return array(
108135
'amount' => $amount,
109136
'tx_ref' => $txnref,
110137
'currency' => $currency,
111138
'payment_options' => 'card',
112-
'redirect_url' => $this->notify_url . '?order_id=' . $order_id,
139+
'redirect_url' => $callback_url,
113140
'payload_hash' => $checkout_hash,
114141
'customer' => array(
115142
'email' => $email,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rave-woocommerce-payment-gateway",
33
"title": "flutterwave-woocommerce",
4-
"version": "2.3.5",
4+
"version": "2.3.6",
55
"description": "Official WooCommerce payment gateway for Flutterwave",
66
"scripts": {
77
"postinstall": "composer install",

rave-woocommerce-payment-gateway.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* Plugin Name: Flutterwave WooCommerce
44
* Plugin URI: https://developer.flutterwave.com/
55
* Description: Official WooCommerce payment gateway for Flutterwave.
6-
* Version: 2.3.5
6+
* Version: 2.3.6
77
* Author: Flutterwave Developers
88
* Author URI: http://flutterwave.com/us
99
* License: MIT License
1010
* Text Domain: rave-woocommerce-payment-gateway
1111
* Domain Path: i18n/languages
12-
* WC requires at least: 6.9.1
12+
* WC requires at least: 9.6.0
1313
* WC tested up to: 8.4.0
1414
* Requires at least: 5.6
1515
* Requires PHP: 7.4

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: theflutterwave
33
Tags: fintech,flutterwave, woocommerce, payments, nigeria, mastercard, visa, target,Naira,payments,verve,donation,church,shop,store, ghana, kenya, international, mastercard, visa
44
Requires at least: 3.1
5-
Tested up to: 6.4.2
6-
Stable tag: 2.3.5
5+
Tested up to: 6.7.1
6+
Stable tag: 2.3.6
77
License: MIT
88
License URI: https://github.com/Flutterwave/Woocommerce/blob/master/LICENSE
99

@@ -96,6 +96,9 @@ By contributing to the Flutterwave WooCommerce, you agree that your contribution
9696
1. You need to open an account on [Flutterwave for Business](https://dashboard.flutterwave.com)
9797

9898
== Changelog ==
99+
= 2.3.6 =
100+
* Fixed: Dynamic Adjustment to Custom Permalink Set by Merchant.
101+
* Fixed: Redirect Payment option return a Payment Mismatch Error.
99102
= 2.3.5 =
100103
* Added: Support for HPOS.
101104
* Fixed: compatibility with WooCommerce 7.1 to 6.9.1

tests/PHPUnit/test-flw-wc-payment-gateway-request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function data_provider_for_test_get_prepared_payload(): array {
4949
$txnref = 'WOOC_'.$order->get_id().'_TEST';
5050

5151
$data_to_join = array(
52-
'amount' => $order->get_total(),
52+
'amount' => (float) $order->get_total(),
5353
'currency' => $order->get_currency(),
5454
'email' => $order->get_billing_email(),
5555
'tx_ref' => $txnref,
@@ -72,11 +72,11 @@ public function data_provider_for_test_get_prepared_payload(): array {
7272
$order,
7373
'FLWSECK-XXXXXXXXXXXXXXX-X',
7474
[
75-
'amount' => $order->get_total(),
75+
'amount' => (float) $order->get_total(),
7676
'tx_ref' => $txnref,
7777
'currency' => $order->get_currency(),
7878
'payment_options' => 'card',
79-
'redirect_url' => get_site_url().'/?wc-api=FLW_WC_Payment_Gateway?order_id=1',
79+
'redirect_url' => get_site_url().'/?wc-api=FLW_WC_Payment_Gateway&order_id=1',
8080
'payload_hash' => $hash,
8181
'customer' => [
8282
'email' => '[email protected]',

0 commit comments

Comments
 (0)