PayPal Payment Buttons: move the product form into the block inspector - #52022
PayPal Payment Buttons: move the product form into the block inspector#52022tx2pnw wants to merge 23 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Paypal Payment buttons plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
45abef7 to
5e3e314
Compare
f965d87 to
d8d93b6
Compare
…ost tax without it
Fixes WOOPTP-488
Proposed changes
Moves the product form fields off the editor canvas into the block inspector, fixes how the same controls look at the sidebar's 280px width, and fixes bugs in the form itself — including one that silently destroyed merchant configuration.
The move
One field or group per commit; the canvas form keeps working and shrinks as fields move. The last field out is what forces a preview onto the canvas, so until then the block keeps a shrinking form there — that's expected, not half-done work. Location only.
PanelBody. The canvas takes the button preview, the status row and the noticesAppearance
Same controls, same attributes, same PayPal payload — only how they look in the column changes.
DESCRIPTIONgets the 16px gap the others haveUSD — US.... Now the code and its symbol,USD $, like Simple Payments and Donations. Widest is 61px in 66px of room, so all 24 fitCreate New, orSaveonce a button existsUse PayPal profile settingstruncated in the narrow sidebar. Now full width and flush with the togglesBehavior
Everything above is a move or a pixel. These change what the merchant gets.
PayPal_API_Client::update_resource()expected HTTP 200. PayPal answers 204 No Content on a successful PUT, andmake_request()takes only the matching status as success — everything else goes down the error path. So PayPal saved the edit and the merchant gotpaypal_api_unknown_errorand "please try again".The client now takes 204 and returns the request data plus the resource id, since a 204 has no body to parse. A re-GET would also work, but it adds a call that can fail on its own, and a GET that fails after a saved PUT recreates this same bug.
extract_payment_link()andvalidate_paypal_url()come out of that method with it: no body means nolinksto read.That return value is what was sent, not what PayPal stored — a PUT is a full replacement and PayPal resets whatever the request left out. Use
get_resource()for real state.200 is accepted alongside 204 as insurance. Every measured PUT is 204 with an empty body, including under
Prefer: return=representation, a replayedPayPal-Request-Id, and everyAcceptwe tried. The response is discarded either way, so accepting 200 costs nothing, and guessing this too narrowly is what caused the bug in the first place. The 200 came from PayPal's own guide, which said "Returns200 OKwith the updated payment link details" until PayPal corrected it to204 No Content.Fixing the form now that it lives in the inspector
Ten fixes to the controls themselves, one per commit. Unlike everything above, each changes what a control does, and two remove one.
Update destroyed configuration the form has no controls for
A PUT replaces the whole resource, and
buildRequestDataonly sends the fields the form has controls for. PayPal deleted the rest. Same link, one edit:product_idSKU-1shippinghandlingdiscountscollect_shipping_addressfalsetrueIt happened silently, the block said it worked, and there was nothing to undo. This hit any link the block did not create — one made in PayPal's dashboard, or by the admin page.
handleUpdateButtonnow reads the payment first, merges those five fields into the request, then PUTs. Costs one GET per save, and it picks up an edit made in PayPal's dashboard since the block loaded. PayPal's value wins over the form's for all five: the form has no control for any of them, so what it would send is a default, not a decision.Two supporting changes, both needed or the JS achieves nothing:
sanitize_line_items()rebuilds each line item from an allowlist, so the REST route dropped these five before they got to PayPal.collect_shipping_addressgoes out on every request — omit it and PayPal sets it back totrue, so sending it once does not stick. The block attribute now defaults totrue, which is what PayPal already does, so a new button is unchanged.api_response_to_attributes()maps it both ways: it only mapped thetruecase, so a payment collecting no address read as one that did.Tax name field out
PayPal renders its own label to the buyer. Two live checkout pages, one with
ZZ Custom VAT Labelset and one with no name, both showTax— the field changed nothing a customer saw, and blanking it turned tax collection off.Three checks required that name. All three go, or the tax is lost between the form and PayPal:
use-paypal-resource.js—taxEnabled && taxNametaxesin the requestsanitize_line_items()—! empty( $tax['name'] )PayPal_Attribute_Mapper::attributes_to_api_request()nameis optional on both tax types: 201 with none, echoed back without one. Thenameproperty comes off the route schema to match, and the admin detail card builds its label from what the tax actually has.taxNamestays as a block attribute and leavesRESOURCE_ATTRIBUTES— syncing it rewrote a merchant's stored name back to "Sales Tax" on every open.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
packages/paypal-paymentsand load the branch on a test site.TAX TYPEandTAX NAMErun the full width of the panel, flush with the toggles above and with no left border. PickUse PayPal profile settings— it fits.PRODUCT IMAGE (OPTIONAL), andDESCRIPTION (OPTIONAL)has the same gap above it as the others. Type in the description: the counter updates on its own line. Paste over 256 characters and click away — the help swaps to the length error and the box turns red.USD $. Open it: 24 entries, each a code and its symbol, withCHFon its own. PickJPY— Price switches to whole numbers (step 1, placeholder 1500) and the canvas preview shows¥.Update keeps what the form has no controls for
The block has no shipping, handling, discount or SKU controls yet, so make the payment through the REST route. On a post edit screen, in the browser console:
await wp.apiFetch( { path: '/wpcom/v2/paypal/buttons/<id>' } ). The new name is there, and so areproduct_id,shipping,handling,discountsandcollect_shipping_address: false. Without this branch the five are gone and the address flag readstrue.collect_shipping_addressistrue, same as before this branch.await wp.apiFetch( { path: '/wpcom/v2/paypal/buttons/<id>', method: 'DELETE' } ).Tax with no name
8.25and Save. Read it back withawait wp.apiFetch( { path: '/wpcom/v2/paypal/buttons/<id>' } ):line_items[0].taxesis[ { type: 'PERCENTAGE', value: '8.25' } ]. Without this branchtaxesis absent.[ { type: 'PREFERENCE', value: 'PROFILE' } ].taxesis absent, and the product name, price and quantity are unchanged.Screenshots