-
Notifications
You must be signed in to change notification settings - Fork 50
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
Rework onboarding code and add REST controller for integration with the OBW #121
Conversation
…e/return_url_description` filterable
…he onboarding flow - Adds action `woocommerce_paypal_payments_onboarding_before_redirect` - Adds filter `woocommerce_paypal_payments_onboarding_redirect_url`
- Add `ppcp_onboarding` object and separate sandbox/production callbacks. - Prevent errors when loading `onboarding.js` outside of the settings screen. - Workaround PayPal’s partner.js shortcomings.
78a61eb
to
57fdd97
Compare
Adds various routes under `/wc-paypal/v1/onboarding` including `/status` (onboarding status), `/set-credentials` (manually set merchant ID/email and keys) and `/get-params` (information useful for presenting the user with an onboarding button).
57fdd97
to
11aa5da
Compare
Nice work @jorgeatorres! I tested the onboarding flow for sandbox and production and there were no issues. I also tested each endpoint individually and everything checks out. Since @mattallan mentioned he'd also review this, I won't merge so he can also have a look. |
Nice one @jorgeatorres! I've tested all those API endpoints as well as the normal onboarding flow and it's all working perfectly from my end. This is good to merge ! 💯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
'woocommerce-paypal-payments' | ||
'return_url_description' => apply_filters( | ||
'woocommerce_paypal_payments_partner_config_override_return_url_description', | ||
__( 'Return to your shop.', 'woocommerce-paypal-payments' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, it makes sense to use esc_html__
instead of just __
.
Thank you all for the reviews! Merging now. |
Issue: woocommerce/woocommerce-admin#5788
Description
This PR refactors some of the code in the on-boarding module in order to expose certain internal details that are needed by WooCommerce's onboarding wizard. Also, in order to workaround several limitations in PayPal's
partner.js
(such as the inability to trigger the popup for dynamically loaded buttons, certain issues with Firefox, etc.),onboarding.js
was heavily modified too.To permit integration with WooCommerce's onboarding wizard, a REST controller was also added. In particular, this controller exposes the following routes:
/wc-paypal/v1/onboarding/get-params
[POST]Returns information useful for presenting the user with a sign-up link/button.
environment
: either 'sandbox' or 'production'. Optional. Defaults to 'sandbox'.environment
: Environment for which the parameters apply.scriptURL
: URL to theonboarding.js
script.scriptData
: Data required by theonboarding.js
script. Should be added to thePayPalCommerceGatewayOnboarding
variable in the global context.onboardCompleteCallback
: Value to be used for thedata-paypal-onboard-complete
attribute in the sign-up link or button.signupLink
: Generated sign-up link. Final redirect URL defaults to the settings page./wc-paypal/v1/onboarding/get-status
[GET]Returns information about the current onboarding status.
environment
: Current environment.onboarded
:true
if onboarded was completed for the current environment.state
: Textual representation of the current onboarding status ("start", "progressive", "onboarded").sandbox.onboarded
: Same asonboarded
but for the "sandbox" environment in particular.sandbox.state
: Same asstate
but for the "sandbox" environment in particular.production.onboarded
: Same asonboarded
but for the "production" environment in particular.production.state
: Same asstate
but for the "production" environment in particular./wc-paypal/v1/onboarding/set-credentials
[POST]Allows setting credentials for a given environment and also enables the gateway.
environment
: Environment the credentials apply to. Required.merchant_id
: Merchant ID. Required.merchant_email
: Merchant e-mail. Required.client_id
: API Client ID. Required.client_secret
: API Client Secret. Required.Steps to test:
Make sure the usual onboarding flow works correctly
Test the REST endpoints
Go to WC > Settings > Advanced > REST API and create an API key for testing. It should be for a user with sufficient access (i.e. "install_plugins" capability).
Keep key and secret handy.
Make sure the endpoints work correctly. Test with different inputs. Some example requests:
curl -X GET https://SITE/wp-json/wc-paypal/v1/onboarding/get-status -u API_KEY:API_SECRET
curl -X POST https://SITE/wp-json/wc-paypal/v1/onboarding/get-params -u API_KEY:API_SECRET
curl -X POST https://SITE/wp-json/wc-paypal/v1/onboarding/set-credentials -u API_KEY:API_SECRET -H 'content-type: application/json' -d '{"environment":"whatever"}'
curl -X POST https://SITE/wp-json/wc-paypal/v1/onboarding/set-credentials -u API_KEY:API_SECRET -H 'content-type: application/json' -d '{"environment":"sandbox","merchant_id":"MERCHANTID","client_id":"CLIENTID"}'
curl -X POST https://SITE/wp-json/wc-paypal/v1/onboarding/set-credentials -u API_KEY:API_SECRET -H 'content-type: application/json' -d '{"environment":"sandbox","merchant_id":"MERCHANTID","merchant_email":"MERCHANTEMAIL","client_id":"CLIENTID","client_secret":"CLIENTSECRET"}'