-
Notifications
You must be signed in to change notification settings - Fork 45
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
feat(reader-revenue): make NYP and Stripe Gateway optional #1645
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -33,8 +50,10 @@ public static function get_configuration( $attributes ) { | |||
|
|||
$configuration['defaultFrequency'] = $attributes['defaultFrequency']; | |||
|
|||
$is_manual = Newspack_Blocks::can_use_name_your_price() && $attributes['manual']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is throwing Warning: Undefined array key "manual"
because it's not an attribute that has a default value. It can be undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a985f00
src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php
Outdated
Show resolved
Hide resolved
…er-base.php Co-authored-by: Miguel Peixe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @dkoo!
Tested and everything works as expected. I left a few comments in the code, mostly nitpicks that can be ignored, but one question regarding translations that should be answered before moving forward with this.
> | ||
{ settings.currencySymbol + | ||
untieredAmount.toFixed( 2 ).replace( /\.?0*$/, '' ) + | ||
getFrequencyLabel( frequencySlug ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this might cause an issue for languages where the amount should not precede the per month/year text? Might be a better idea to have the getFrequencyLabel
method accept the amount and return a translated string which includes the amount in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, although I had some trouble conceptualizing how we'd translate such a string when it has to include HTML tags for styling, too. 3701068 is my best attempt—how's it look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dkoo! I left some additional review comments for this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestions here! Thank you for the guidance on this part—admittedly our work around making sure things are translatable has been lacking. 😅
* @param string $frequency_slug Frequency slug. | ||
* @param bool $hide_once_label Whether to hide the "once" label. | ||
*/ | ||
public static function get_frequency_label( $frequency_slug, $hide_once_label = false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above re including amount in the translations here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1645 (comment)
@@ -33,8 +50,10 @@ public static function get_configuration( $attributes ) { | |||
|
|||
$configuration['defaultFrequency'] = $attributes['defaultFrequency']; | |||
|
|||
$is_manual = Newspack_Blocks::can_use_name_your_price() && ! empty( $attributes['manual'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: same comment re creating variable only used in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, not necessary—updated in 42e145b.
includes/class-modal-checkout.php
Outdated
$price = ! empty( $min_price ) ? max( $price, $min_price ) : $price; | ||
|
||
$cart_item_data['nyp'] = (float) \WC_Name_Your_Price_Helpers::standardize_number( $price ); | ||
$is_product_nyp = \Newspack_Blocks::can_use_name_your_price() ? \WC_Name_Your_Price_Helpers::is_nyp( $product_id ) : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: is it necessary to create a variable here considering this is only used in one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, not necessary—updated in 42e145b.
'%1$s is the amount (with currency symbol). %2$s is the frequency of the donation. Inludes embedded HTML tags for styling.', | ||
'newspack-blocks' | ||
), | ||
'<h3 class="wpbnbd__tiers__amount__number">' . $currency_symbol . $amount . '</h3>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this pattern for translating is fine, but I think we will still run into issues with languages where currencies and amounts might need to be swapped. Can we use something like the wc_price helper function for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, I'm not sure how tied we are to the specific wording here, but WC Subscriptions has done alot of the heavy lifting for formatting price strings, which can get super tricky. Can we rely on something like wcs_price_string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5f9479a implements wcs_price_string
with a fallback to wc_price
if not available (if that's not available, the site has bigger problems).
> | ||
<div | ||
dangerouslySetInnerHTML={ { | ||
__html: getFrequencyLabel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can have this string passed from the backend via newspack_blocks_data
since the logic for creating the string already lives there? Then we can remove the duplicate logic from the frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 5f9479a. Because the block needs to be able to dynamically render values from attributes, this may look a little janky with the string replacement, but I'm open to better suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I see what you mean. It definitely does seem a bit overly complex. I'm not sure of a cleaner way to handle this with the existing design for the donate block. My suggestion would be to remove the per X
/once
from the amount strings altogether as this is implied based on the category tab selection at the top (one-time/monthly/annually). But I think changing the design of this might be outside of the scope of this PR.
I think what we have here is fine, although there is an edge case where the publisher has an empty value set, for example while editing an amount. The block shows NaN
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5b8470c forces the value to be 0
in this case. Maybe still not ideal, but better than $NaN
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I think it makes sense to set this to 0 when the input is empty. One other issue I noticed just now while retesting this is if the input is empty, we need to make sure the below $X validation still functions and prevents us from saving.
Here it is with an input value less than 5 for me:
I think instead of forcing how the null value is rendered in the preview, we can force null values to be stored as 0 somewhere around here:
setAttributes( { amounts: { ...donationSettings.amounts, ...attributes.amounts } } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also want to note while I was retesting this, I did some more thinking about the complexity of generating the translation string with dynamic pricing and HTML elements, and realized we can probably reduce the complexity by removing the span
wrappers from the currency symbol and price, and instead placing them only around the frequency string.
We can achieve the same style results via CSS this way by setting the .wpbnbd__tiers__amount__value
text to have the bolded and enlarged size and set the frequency span to have the unbolded smaller size.
This is how it is rendered right now:
<span class="wpbnbd__tiers__amount__value">
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">$</span>5
</bdi>
</span>
once
</span>
We can probably achieve the same result with this:
<span class="wpbnbd__tiers__amount__value">
$5
<span class="some-class-for-frequency-label">
once
</span>
</span>
I'm okay if we tackle this another time though since this PR has become quite involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also want to note while I was retesting this, I did some more thinking about the complexity of generating the translation string with dynamic pricing and HTML elements, and realized we can probably reduce the complexity by removing the
span
wrappers from the currency symbol and price, and instead placing them only around the frequency string.
That's a good call, but yes, let's leave for another PR.
I think instead of forcing how the null value is rendered in the preview, we can force null values to be stored as 0 somewhere around here:
At first I tried forcing empty input values to be stored as 0
, but this results in the input itself showing 0
when you delete the values in the input, which is potentially confusing to the user. Agree that we should still validate against the minimum donation value, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that we should still validate against the minimum donation value, though.
Implemented in 9f041db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on getting back to this one @dkoo. Almost there. Just one final issue commented here: #1645 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! thanks for dealing with all the back and forth on this one!
# [3.0.0-alpha.1](v2.6.2...v3.0.0-alpha.1) (2024-02-08) ### Bug Fixes * **homepage-articles:** use map_deep to construct articles_rest_url and resolve PHP 8.1 warnings ([#1655](#1655)) ([24085d8](24085d8)) * prevent error in modal-checkout check ([7e2a6c7](7e2a6c7)) ### Features * **ci:** add `epic/*` release workflow and rename `master` to `trunk` ([#1656](#1656)) ([c788e55](c788e55)) * deprecate streamlined (Stripe) Donate block version ([#1638](#1638)) ([11bd0d6](11bd0d6)) * **homepage-posts:** add custom taxonomy exclusions filter ([#1641](#1641)) ([b140a99](b140a99)) * **reader-revenue:** make NYP and Stripe Gateway optional ([#1645](#1645)) ([1322d7c](1322d7c)) ### BREAKING CHANGES * streamlined (Stripe) Donate block version is no more
🎉 This PR is included in version 3.0.0-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.0.0-epic-ras-acc.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [3.0.0](v2.6.2...v3.0.0) (2024-02-20) ### Bug Fixes * **homepage-articles:** use map_deep to construct articles_rest_url and resolve PHP 8.1 warnings ([#1655](#1655)) ([24085d8](24085d8)) * prevent error in modal-checkout check ([7e2a6c7](7e2a6c7)) ### Features * **ci:** add `epic/*` release workflow and rename `master` to `trunk` ([#1656](#1656)) ([c788e55](c788e55)) * deprecate streamlined (Stripe) Donate block version ([#1638](#1638)) ([11bd0d6](11bd0d6)) * **homepage-posts:** add custom taxonomy exclusions filter ([#1641](#1641)) ([b140a99](b140a99)) * **reader-revenue:** make NYP and Stripe Gateway optional ([#1645](#1645)) ([1322d7c](1322d7c)) ### BREAKING CHANGES * streamlined (Stripe) Donate block version is no more
🎉 This PR is included in version 3.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Makes Stripe Gateway and Name Your Price extensions optional.
How to test the changes in this Pull Request:
See Automattic/newspack-plugin#2866 for testing instructions.
Other information: