Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/167: Add WooPayments compatibility #201

Merged
merged 6 commits into from
Mar 25, 2024
Merged

fix/167: Add WooPayments compatibility #201

merged 6 commits into from
Mar 25, 2024

Conversation

Sidsector9
Copy link
Member

@Sidsector9 Sidsector9 commented Feb 23, 2024

All Submissions:

  • Does your code follow the WooCommerce Sniffs variant of WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Will this change require new documentation or changes to existing documentation?

Changes proposed in this Pull Request:

Closes #167 .

Steps to test the changes in this Pull Request:

  1. Set USD as the store currency.
  2. Add ZAR to WooPayments multi-currency.
  3. Ensure WooPayments and Payfast are both enabled.
  4. Visit the shop page and set the currency to ZAR, add a product to cart and visit checkout page.
  5. Observe Payfast gateway is not in the list.
  6. Switch to fix branch and repeat (4).
  7. Observe Payfast is in the list.

Changelog entry

Fix - Payfast gateway not visible on Checkout when ZAR currency is set via WooPayments multi-currency feature.

@Sidsector9 Sidsector9 self-assigned this Feb 23, 2024
Comment on lines 1821 to 1833
if ( isset( $_GET['currency'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$currency_code = array(
sanitize_text_field(
wp_unslash( $_GET['currency'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
),
);
// Check if the currency is set in the session (for logged-out users).
} elseif ( 0 === $user_id && WC()->session ) {
$currency_code = WC()->session->get( \WCPay\MultiCurrency\MultiCurrency::CURRENCY_SESSION_KEY );
// Check if the currency is set in the user meta (for logged-in users).
} elseif ( $user_id ) {
$currency_code = get_user_meta( $user_id, \WCPay\MultiCurrency\MultiCurrency::CURRENCY_META_KEY );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with how multi-currency works so this feedback may not make sense. But wondering if there's a scenario where the user session or user meta hasn't been set and thus the currency code ends up being empty here?

I guess wondering if we should separate this code into two if statements. So we check for the currency value from the URL first and store that in the $currency_code variable. And then we overwrite that value from session or user meta, if that value exists in either. Something like:

$currency_code = '';
if ( isset( $_GET['currency'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	$currency_code = array(
		sanitize_text_field(
			wp_unslash( $_GET['currency'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		),
	);
}

// Check if the currency is set in the session (for logged-out users).
if ( 0 === $user_id && WC()->session ) {
	$stored_code = WC()->session->get( \WCPay\MultiCurrency\MultiCurrency::CURRENCY_SESSION_KEY );

	// Not sure the best check on this value? Should it always be an array and we can check for that? Can it sometimes be a string?
	if ( $stored_code ) {
		$currency_code = $stored_code;
	}
// Check if the currency is set in the user meta (for logged-in users).
} elseif ( $user_id ) {
	$stored_code = get_user_meta( $user_id, \WCPay\MultiCurrency\MultiCurrency::CURRENCY_META_KEY );

	// Not sure the best check on this value? Should it always be an array and we can check for that? Can it sometimes be a string?
	if ( $stored_code ) {
		$currency_code = $stored_code;
	}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkotter I've fixed the confusion between the return value types array vs string. There was a small bug, thanks for pointing that out.

Regarding separating if statements into 2, the problem is that in Block Checkout, the user meta is saved after the block is rendered. So the block checkout page requires an additional reload for Payfast to appear in the list of gateways. We give precedence to the GET parameter, if that is set, then we use it, because ultimately that gets saved to the session and user meta.

@ankitguptaindia
Copy link
Member

QA/Test Report-

Testing Environment -

  • WordPress: 6.4.3
  • Theme: Storefront Version: 4.5.4
  • WooCommerce - Version 8.6.1
  • PHP: 8.0.22
  • Web Server: Nginx
  • Browser: Chrome - Version 121
  • OS: macOS Sonoma 14.3
  • Git Branch: fix/167

Test Results -

Functional Demo / Screencast -

PayFast payment gateway is available on checkout when customers use 'Rand' as a currency from WooPayment currency selection option.
Cross tested scenario when Store also has 'Rand' as a store currency and WooPayment installed.

Recording.577.mp4

Next Step- Ready to UAT

Testing Documentation Status-

Cases related to this PR/Issue, are added to Critical Flow Wiki Pages:

  • Yes
  • Not Required/ Applicable for this PR

@ankitguptaindia ankitguptaindia marked this pull request as draft March 19, 2024 08:57
@ankitguptaindia
Copy link
Member

Regression+Smoke Test Report-

Testing Environment -

  • WordPress: 6.5-RC1
  • Theme: Storefront Version: 4.5.4
  • WooCommerce - Version 8.7.0
  • PHP: 8.3.0
  • Web Server: Nginx
  • Browser: Chrome - Version 122
  • OS: macOS Monterey

Tested with Archive File created via

php woorelease.phar build smoke-testing branch _URL_

  • Composer version - v2.3.5
  • npm version - v8.19.2
  • node version - v16.18.1

Please note that this plugin has been tested with the build created by the specified versions ☝🏼 of Composer, Node, and NPM.

Status- Working as expected. Ready to merge 🚀

@vikrampm1 vikrampm1 added this to the 1.6.2 milestone Mar 25, 2024
@vikrampm1 vikrampm1 marked this pull request as ready for review March 25, 2024 09:32
@vikrampm1 vikrampm1 merged commit 7b0be44 into trunk Mar 25, 2024
6 checks passed
@vikrampm1 vikrampm1 deleted the fix/167 branch March 25, 2024 09:33
@vikrampm1 vikrampm1 mentioned this pull request Mar 25, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with WooPayments multi currency
4 participants