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

feat(reader-revenue): make NYP and Stripe Gateway optional #1645

Merged
merged 18 commits into from
Feb 6, 2024

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Jan 19, 2024

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:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo self-assigned this Jan 19, 2024
@dkoo dkoo requested a review from a team as a code owner January 19, 2024 21:00
@dkoo dkoo changed the title Fix/optional nyp stripe gateway feat(reader-revenue): make NYP and Stripe Gateway optional Jan 19, 2024
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

The fallback is working great! I have a few comments inline.

Non-blocking, but I miss having a greyed-out style here:

image

Even with the message, I still want to click the button.

@@ -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'];
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a985f00

@chickenn00dle chickenn00dle self-requested a review January 26, 2024 22:24
Copy link
Contributor

@chickenn00dle chickenn00dle left a 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 ) }
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 👍

Copy link
Contributor Author

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 ) {
Copy link
Contributor

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

Copy link
Contributor Author

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() && ! empty( $attributes['manual'] );
Copy link
Contributor

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

Copy link
Contributor Author

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.

$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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@dkoo dkoo requested a review from chickenn00dle January 30, 2024 00:44
'%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>',
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@chickenn00dle chickenn00dle Feb 2, 2024

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:

Screenshot 2024-02-02 at 10 24 48

Copy link
Contributor Author

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?

Copy link
Contributor

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:
Screenshot 2024-02-06 at 11 37 44

And while the input is empty:
Screenshot 2024-02-06 at 11 37 51

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 } } );

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@dkoo dkoo requested a review from chickenn00dle January 31, 2024 23:59
Copy link
Contributor

@chickenn00dle chickenn00dle left a 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)

@dkoo dkoo changed the base branch from master to trunk February 5, 2024 22:07
@dkoo dkoo requested a review from chickenn00dle February 5, 2024 23:55
@dkoo dkoo requested a review from miguelpeixe February 6, 2024 18:19
Copy link
Contributor

@chickenn00dle chickenn00dle left a 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!

@dkoo dkoo merged commit 1322d7c into trunk Feb 6, 2024
6 checks passed
@dkoo dkoo deleted the fix/optional-nyp-stripe-gateway branch February 6, 2024 20:09
matticbot pushed a commit that referenced this pull request Feb 8, 2024
# [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
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-epic-ras-acc.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 20, 2024
# [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
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants