Automattic / newspack-blocks

Gutenberg blocks for the Newspack project.
207 stars 43 forks source link

fix(modal-checkout): empty cart when modal checkout is abandoned #1923

Closed chickenn00dle closed 1 month ago

chickenn00dle commented 1 month ago

All Submissions:

Changes proposed in this Pull Request:

Closes https://app.asana.com/0/1207817176293825/1208620127411764/f

This PR adds an ajax request to empty cart when modal checkout is abandoned.

Screenshot 2024-10-24 at 12 32 08

How to test the changes in this Pull Request:

  1. Via any checkout or donate button open modal checkout as a reader
  2. In another tab (in the same session) open the cart page test.site/cart
  3. Verify the item is present in the cart
  4. Back in the modal checkout tab, close the checkout modal without completing checkout
  5. Go back to the cart tab. On epic/ras-acc the item will still be present. On this branch, the cart should be empty.

Other information:

chickenn00dle commented 1 month ago

Thanks for the review @miguelpeixe!

Once I authenticate the nonce provided on page load will no longer be valid.

Ah whoops! I always forget about the transition in login state 🤦 . I moved the nonce to the checkout script and pulled in modal.js as you suggested: https://github.com/Automattic/newspack-blocks/pull/1923/commits/7a1c99ac92428484667f5e187da7a3f53ab58f95