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

Purchases: Individual purchases not loading on sites with Site Redirect #536

Merged
merged 4 commits into from
Dec 3, 2015

Conversation

umurkontaci
Copy link
Contributor

This fixes the issue of individual purchases not loading on site with Site Redirect record set as primary domain. (Fixes #122)

It changes the use of domain property from purchases data to getting the site slug from SitesList. This will the URLs will behave the same as in store.

Testing

  • Assert that a site with a site redirect appears properly in /purchases.
  • Assert that two sites that redirect to the same site appear properly in /purchases.
  • QA review
  • Code review

@umurkontaci umurkontaci changed the title Purchases: Individual purchases not loading on sites with Site Redirect (Fixes #122) Purchases: Individual purchases not loading on sites with Site Redirect Nov 23, 2015
@umurkontaci umurkontaci added [Feature] Purchase Management Related to managing purchases such as subscriptions, plans, history, auto-renew, cancellation, etc. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 23, 2015
@umurkontaci umurkontaci added this to the Purchases: v1 milestone Nov 23, 2015
@umurkontaci umurkontaci self-assigned this Nov 23, 2015
@mikeshelton1503
Copy link
Contributor

👍 This fixes my issue from #122

@fabianapsimoes
Copy link
Contributor

This seems to solve the issues with Site Redirect, but is failing some tests. Moving back to Awaiting Author Response.

@fabianapsimoes fabianapsimoes added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 24, 2015
@umurkontaci umurkontaci force-pushed the fix/122-purchases-with-site-redirect branch from 1f21c28 to 7df2ac6 Compare November 24, 2015 16:21
@umurkontaci
Copy link
Contributor Author

Yes, due to some twisted dependencies. I've added react-test-env-setup to cart-synchronizer-test and the tests should be up and running now.

@umurkontaci umurkontaci added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Nov 24, 2015
@umurkontaci umurkontaci force-pushed the fix/122-purchases-with-site-redirect branch from e6227b5 to c0a113c Compare November 24, 2015 16:43
@@ -27,6 +30,7 @@ function getPurchasesBySite( purchases ) {
domain: currentValue.domain,
id: currentValue.siteId,
name: currentValue.siteName,
slug: sites.getSite( currentValue.siteId ).slug,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a guarantee that sites has been fetched at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only called in a single place under client/me/purchases/list/index.jsx, and I think that page is only loaded after we have the sites. But apart from that, there is no guarantee. I have come to think that it might be a better idea to move the function to somewhere else, because a dependency to sites-list breaks many tests since sites-list depends on DOM and we need to add react-test-env-setup to many tests to get them running.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about removing this call to SitesList and updating this function to accept an array of sites as a parameter, like getPurchasesBySite( purchases, sites )? It would keep the function pure, make this easier to test, and would be clearer that information from SitesList is necessary in modules that use getPurchasesBySite.

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 great idea, I've changed the code to implement it as such.

@umurkontaci umurkontaci added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 24, 2015
@drewblaisdell
Copy link
Contributor

@umurkontaci A potentially unresolved blocker for using the primary domain in the purchases/checkout URLs is that Jetpack sites are represented with two site objects, each with separate blog_ids:

  • The Jetpack site (e.g. foobar.com)
  • A .com site that relates to the Jetpack site (e.g. foobar.wordpress.com)

Purchases are sometimes (possibly always, I'm unsure) associated with the .com site, but if we redirect users from /purchases to the checkout through /checkout/foobar.com, the cart will be created for the Jetpack site, and the purchases will not appear as renewals, because the subscriptions exist only for foobar.wordpress.com.

@dzver or @matthusby: Do either of you know whether subscriptions for Jetpack sites are always associated with the .com site, in this case?

@dzver
Copy link
Member

dzver commented Nov 25, 2015

I'm having trouble confirming that a Jetpack site has two blog_ids. My Jetpack site seems to only have one. Do you mind giving me an example?

@drewblaisdell
Copy link
Contributor

@dzver Apparently, the example I was using was the following, non-standard case of a user with:

  • A Jetpack site with a URL property of http://foobar.com.
  • A .com site, foobar.wordpress.com, with a primary domain, http://foobar.com, that has its DNS record point to the Jetpack site.

SitesList and Site use a property (hasConflict) to resolve collisions between sites that have the same slug, by setting the slug of the .com site to the unmapped URL (foobar.wordpress.com, in the previous example).

@umurkontaci's approach of setting the slug property in the purchases assembler to that of the slug property of the site from SitesList should fix this problem correctly, so we don't need to worry about the issue with which blog_id is associated with a purchase.

@umurkontaci umurkontaci force-pushed the fix/122-purchases-with-site-redirect branch from c0a113c to 0cdd3b6 Compare November 26, 2015 13:37
@umurkontaci
Copy link
Contributor Author

This has been updated with @drewblaisdell suggestion about sending the SitesList as an argument.

@umurkontaci umurkontaci added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Nov 26, 2015
@scruffian
Copy link
Member

I tested this with .com sites and it works well.

I think we should test it with a Jetpack site before we merge.

The code looks good

@umurkontaci
Copy link
Contributor Author

@scruffian I've tested with an account on a single Jetpack site and confirm that it's using the correct URL.

@scruffian
Copy link
Member

@jeherve @v18, my concern is that this will reintroduce a problem with domain mapping for Jetpack site that we saw last week:

The problem occours when a user has a Jetpack-connected self-hosted site and a domain registered at WordPress.com, mapped to the self-hosted site. In this case the user couldn’t renew the domain through the Jetpack-connected site using Calypso – this makes some sense as the domain is registered in connection with her .com site, but it is definitely confusing.

In this case users were able to see the domain and attempt to renew it, but they got an error about requiring domain registration details. (p2MSmN-4aE-p2)

I have tried setting up my Jetpack site to test this, but I couldn't connect it. Could one of you test it?

@jeherve
Copy link
Member

jeherve commented Nov 27, 2015

I tested the branch with a domain of mine, registered on WordPress.com, and currently pointed to a Jetpack site connected to the same WordPress.com account.

I was able to go through the renewal.

this makes some sense as the domain is registered in connection with her .com site, but it is definitely confusing.

I might not be the perfect test subject for this, but I must say that it was less confusing than I expected. The domain name is displayed in a much bigger font size than the site title on /purchases, so you naturally click on it without thinking twice.

I did, however ran into another site during the renewal. The following js error appeared when clicking the "Purchase subscription" button:

screen shot 2015-11-27 at 2 37 59 pm

I didn't click on anything else before on that page, my stored credit card was automatically selected for me. When entering a new credit card, payment went through.

I couldn't reproduce when trying the same steps on WordPress.com, and could reproduce again with another subscription when in that branch.

@scruffian
Copy link
Member

I was getting an error if a site was deleted and still had purchases - since it won't be in sites. This shouldn't happen, since we shouldn't let users delete sites with upgrades, but there are probably ways round it at the moment.

@scruffian
Copy link
Member

I tried mocking @jeherve's credit card data to see if I could reproduce it, and I was unable to, so the problem must lie elsewhere. I'm not sure the best way to proceed now...


// If a site has been deleted then there will be no site with this ID in site.
if ( site ) {
slug = site.domain;
Copy link
Contributor

Choose a reason for hiding this comment

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

@scruffian I believe this should be site.slug.

@drewblaisdell drewblaisdell force-pushed the fix/122-purchases-with-site-redirect branch 2 times, most recently from 74b46d2 to ceeb93b Compare December 3, 2015 02:12
@drewblaisdell
Copy link
Contributor

@scruffian I updated your commit to use site.slug instead of site.domain and made some minor style tweaks to avoid assigning to different types of site objects to the same identifier.

I'm fairly confident that the credit card issues above are unrelated to this change and that this is safe to merge. I'm going to try and pair with @jeherve soon to make sure we figure out what is causing that error.


if ( ! this.props.purchases.isFetching && ! this.props.purchases.hasLoadedFromServer ) {
return null;
if ( ! this.props.sites.fetched ) {
Copy link
Member

Choose a reason for hiding this comment

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

What about checking against sites.initialized? It looks like it works the same way as sites.fetched, but also works for data cached in local storage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch - fixed.

@drewblaisdell drewblaisdell force-pushed the fix/122-purchases-with-site-redirect branch 2 times, most recently from 895d34b to cd7a33b Compare December 3, 2015 17:54
@jeherve
Copy link
Member

jeherve commented Dec 3, 2015

After another test, I can't reproduce these js errors anymore. Renewal went well, no issues at all.

Not sure what happened before, and what fixed it...

@drewblaisdell drewblaisdell added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 3, 2015
@drewblaisdell
Copy link
Contributor

@scruffian and @gziolo checked the code and QA box for this, and I reviewed @scruffian's last commit (making only minor style changes), so this is ready to merge.

@gziolo
Copy link
Member

gziolo commented Dec 3, 2015

👍

umurkontaci and others added 4 commits December 3, 2015 13:49
…ct (Fixes #122)

This fixes the issue of individual purchases not loading on site with Site Redirect record set as primary domain.

It changes the use of `domain` property from purchases data to getting the site slug from `SitesList`. This will the URLs will behave the same as in store.
This removes the `SitesList` dependency from this function, and makes the
behavior a bit more explicit.
@drewblaisdell drewblaisdell force-pushed the fix/122-purchases-with-site-redirect branch from cd7a33b to f76af43 Compare December 3, 2015 21:49
drewblaisdell added a commit that referenced this pull request Dec 3, 2015
…edirect

Purchases: Individual purchases not loading on sites with Site Redirect
@drewblaisdell drewblaisdell merged commit 4810232 into master Dec 3, 2015
@drewblaisdell drewblaisdell deleted the fix/122-purchases-with-site-redirect branch December 3, 2015 22:03
@scruffian
Copy link
Member

\o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Purchase Management Related to managing purchases such as subscriptions, plans, history, auto-renew, cancellation, etc. [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Purchases: Site Redirect purchase not loading
8 participants