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

Update/normalize donation events #2299

Merged
merged 3 commits into from
Feb 27, 2023
Merged

Conversation

leogermani
Copy link
Contributor

@leogermani leogermani commented Feb 21, 2023

All Submissions:

Changes proposed in this Pull Request:

Normalizes the donation_new event so it works the same way in both platforms.

Before the change in this PR, donations processed through Woocommerce would trigger a donation_new event before they were confirmed, while in Stripe it would only be triggered after confirmation.

Now the event is only triggered after confirmation in both platforms.

We keep the current WooCommerce listener as a new event called donation_order_processed as suggested in p1676562193774819-slack-1676536201.225739 (even though I'm not sure we need it)

How to test the changes in this Pull Request:

  1. Add the following snippet to your site:
Data_Events::register_handler( 'debug_donation_new_events', 'donation_new' );

function debug_donation_new_events( $timestamp, $data, $user_id ) {
	error_log( print_r( $data, true ) );
}

Data_Events::register_handler( 'debug_donation_subscription_new_events', 'donation_subscription_new' );

function debug_donation_subscription_new_events( $timestamp, $data, $user_id ) {
	error_log( print_r( $data, true ) );
}
  1. Set up Stripe as the Reader Revenue platform
  2. Make donations
  3. Watch the logs and make sure you see the correct events being triggered at the correct times, with the correct data
  4. Do the same for the Newspack platform and confirm they are consistent
  5. Make sure to test with cards that will return failed payments to make sure events are not triggered in those situations

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?

@leogermani leogermani self-assigned this Feb 22, 2023
@leogermani leogermani added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 22, 2023
@leogermani leogermani marked this pull request as ready for review February 22, 2023 14:00
@leogermani leogermani requested a review from a team as a code owner February 22, 2023 14:00
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Approving because it works, but I noticed something that may be outside the scope of this PR—when using the Stripe RR platform, the user_id value always seems to be 0. Tested on both an existing and a new browser session.

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 22, 2023
@leogermani
Copy link
Contributor Author

Approving because it works, but I noticed something that may be outside the scope of this PR—when using the Stripe RR platform, the user_id value always seems to be 0. Tested on both an existing and a new browser session.

I could not reproduce this. Did you have RAS enabled when you tested? This will happen if RAS is not enabled because a user won't be created.

I really want @miguelpeixe to have a look at this, but I'll merge it if I get to the next task that depends on it so I'm not blocked. We can always revisit/revert it if Miguel finds a problem.

@dkoo
Copy link
Contributor

dkoo commented Feb 23, 2023

I could not reproduce this. Did you have RAS enabled when you tested?

RAS is enabled on my site, and the user ID is populated when Newspack is the Reader Revenue platform. It's only 0 for Stripe.

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.

Working as described

when using the Stripe RR platform, the user_id value always seems to be 0. Tested on both an existing and a new browser session.

@dkoo Perhaps you are unauthenticated and donating with an already registered email? The donation will not be tied to the user ID if that's the case.

@leogermani leogermani merged commit 2624d53 into master Feb 27, 2023
@leogermani
Copy link
Contributor Author

The donation will not be tied to the user ID if that's the case.

Why not? Shouldn't it?

@dkoo
Copy link
Contributor

dkoo commented Feb 27, 2023

Why not? Shouldn't it?

That was my assumption as well—I was assuming if using an email address that is known to be associated with a user ID, that user ID should be sent with the data.

@miguelpeixe miguelpeixe deleted the update/normalize-donation-events branch February 27, 2023 20:51
@miguelpeixe
Copy link
Member

We can double-check with @adekbadek, but that's not how it's designed:

$user_id = Reader_Activation::register_reader( $email_address, $full_name, true, $reader_metadata );
if ( ! \is_wp_error( $user_id ) && false !== $user_id ) {
$client_metadata['userId'] = $user_id;
}
}

$user_id will be false if the user is already registered:

/**
* Register a reader given its email.
*
* Due to authentication or auth intention, this method should be used
* preferably on POST or API requests to avoid issues with caching.
*
* @param string $email Email address.
* @param string $display_name Reader display name to be used on account creation.
* @param bool $authenticate Whether to authenticate after registering. Default to true.
* @param array $metadata Any metadata to pass along to the action hook.
*
* @return int|false|\WP_Error The created user ID in case of registration, false if the user already exists, or a WP_Error object.
*/
public static function register_reader( $email, $display_name = '', $authenticate = true, $metadata = [] ) {
if ( ! self::is_enabled() ) {

I'm not sure we can/should relate a donation to a user account without authorization.

@dkoo
Copy link
Contributor

dkoo commented Feb 27, 2023

Thanks for the additional info—let's leave as-is for now

matticbot pushed a commit that referenced this pull request Mar 3, 2023
# [1.106.0-alpha.1](v1.105.0...v1.106.0-alpha.1) (2023-03-03)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Mar 14, 2023
# [1.106.0](v1.105.1...v1.106.0) (2023-03-14)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))
* show handoff to finish Newspack setup only if setup is incomplete ([#2343](#2343)) ([1173b5b](1173b5b))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants