Skip to content

Simple payments: allow read+write access to meta fields via REST API - #10402

Merged
simison merged 10 commits into
masterfrom
update/simple-payments-rest-api-meta
Nov 8, 2018
Merged

simison merged 10 commits into
masterfrom
update/simple-payments-rest-api-meta

Conversation

@simison

@simison simison commented Oct 25, 2018 •

Copy link
Copy Markdown
Member

Enable Simple payments custom meta values for access through the REST API. Field’s value will be exposed on a .meta key in the endpoint response, and WordPress will handle setting up the callbacks for reading and writing to that meta key.

This is needed for Simple Payments block to be able to read+create+update Simple payment buttons through the REST API.

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
https://developer.wordpress.org/reference/functions/register_meta/

Changes proposed in this Pull Request:

Enable Simple payments custom meta values for access through the REST API.

Testing instructions:

  • Have a site with simple payments enabled (premium or business plan)
  • Create a post in Calypso editor and create a simple payments button (from "+ add" menu)
  • Note down button's ID by looking at the posts HTML source (from shortcode e.g. [simple-payment id="42"])
  • Call API endpoint:
    • Locally hosted Jetpack
      http://localhost/index.php?rest_route=/wp/v2/jp_pay_product/BUTTON_ID
      
    • WPCOM (apply D19907-code to test):
      https://public-api.wordpress.com/wp/v2/sites/YOUR_SITE_URL/jp_pay_product/BUTTON_ID
      
  • Without this change, meta field is missing Simple payments meta fields, with the change you should see:
  "meta": {
    "spay_price": 3,
    "spay_currency": "HUF",
    "spay_cta": "",
    "spay_multiple": 1,
    "spay_email": "email@example.com",
    "spay_formatted_price": "Ft3",
    "spay_status": ""
  },

You should be able to write to this object as well. The easiest way to test reading+creating+writing would be following instructions from Automattic/wp-calypso#28065

Proposed changelog entry for your changes:

Enable Simple payments custom meta values for access through the REST API.

@simison simison added [Status] In Progress Simple Payments [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Oct 25, 2018
@simison simison self-assigned this Oct 25, 2018
@simison
simison requested a review from a team October 25, 2018 15:29
@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D19907-code. (newly created revision)

@simison
simison requested review from a team and rodrigoi October 25, 2018 15:32
@jetpackbot

jetpackbot commented Oct 25, 2018 •

Copy link
Copy Markdown
Collaborator

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: December 4, 2018.
Scheduled code freeze: November 27, 2018

Generated by 🚫 dangerJS

@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D19907-code. (updated diff)

@simison
simison requested a review from a team October 26, 2018 22:51
@simison simison added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Oct 26, 2018
@simison simison added this to the 6.7 milestone Oct 26, 2018
jeherve
jeherve previously approved these changes Oct 29, 2018

@jeherve jeherve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems to work well for me. 🚢

tyxla
tyxla previously approved these changes Oct 29, 2018

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm testing with #28065 and this seems to work great! Nice work!

Left some minor comments, I'm mostly concerned about our lack of support for non-integer values for prices.

* @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
*/
public function register_meta_fields_in_rest_api() {
register_meta( 'post', 'spay_price', array(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Noting that there seem to be double indentation here (two tabs nesting instead of 1)

@simison
simison dismissed stale reviews from tyxla and jeherve via 93352d8 October 29, 2018 12:15
jeherve
jeherve previously approved these changes Oct 29, 2018

@jeherve jeherve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding my 🚢 👍 back. Merge when ready.

@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Please review this diff before merging: D19907-code. (updated diff)

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Oct 29, 2018
@simison

simison commented Oct 29, 2018 •

Copy link
Copy Markdown
Member Author

While this does test well, I'm a bit cautious to merge without fully understanding implications of just casting spay_price as an Integer or a Float (convo p1540815622091600-slack-jetpack-gutenberg) — I'm going to have a better look with more time tomorrow.

Seems like this value should hold either floats or integers depending on another field.

@sirreal
sirreal force-pushed the update/simple-payments-rest-api-meta branch from 9eb3ab7 to e203f95 Compare November 8, 2018 10:33
@sirreal

sirreal commented Nov 8, 2018

Copy link
Copy Markdown
Member

I've rebased this without the changes in #10555, which have changed some and are significant enough to warrant an independent PR.

@sirreal sirreal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was working well. I'm re-approving after removing some formatting commits that are now part of #10555

@jeherve jeherve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Works for me. Merge when ready.

@jeherve jeherve modified the milestones: 6.8, 6.7.1 Nov 8, 2018
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Nov 8, 2018
@simison
simison merged commit 08201df into master Nov 8, 2018
@ghost ghost removed the [Status] Ready to Merge Go ahead, you can push that green button! label Nov 8, 2018
@simison
simison deleted the update/simple-payments-rest-api-meta branch November 8, 2018 11:29
jeherve pushed a commit that referenced this pull request Nov 8, 2018
…10402)

Enable Simple payments custom meta values for access through the REST API. Field’s value will be exposed on a `.meta` key in the endpoint response and WordPress will handle setting up the callbacks for reading and writing to that meta key.

This is needed for Simple Payments block to be able to read+create+update Simple payment buttons through the REST API.

https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
https://developer.wordpress.org/reference/functions/register_meta/
@jeherve

jeherve commented Nov 8, 2018

Copy link
Copy Markdown
Member

Cherry-picked to branch-6.7 in 1c7176e

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

Labels

[Feature] Pay with PayPal aka Simple Payments [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants