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

Sandbox live switch, Change onboarding flow #40

Merged
merged 42 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
25fa11b
extract sandbox host into its own container key.
websupporter Sep 24, 2020
7fd2712
do not send the email when creating referreldata for link
websupporter Sep 24, 2020
920b428
show buttons on start screen
websupporter Sep 24, 2020
b708198
load onboarding script on start screen
websupporter Sep 24, 2020
6f870ec
render sandbox and live connect button and toggle between those depen…
websupporter Sep 24, 2020
09a5f0e
enable loginseller endpoint to switch between sandbox and live
websupporter Sep 24, 2020
9f45ca6
remove some setting fields from start screen
websupporter Sep 24, 2020
1b3061f
save merchant email when merchant comes back from onboarding
websupporter Sep 24, 2020
2679afd
keep email input always editable without the need of reset
websupporter Sep 24, 2020
5907d03
move merchant email into toggle
websupporter Sep 24, 2020
16ad8c9
resolve merge conflict
websupporter Sep 24, 2020
3281043
do not show enable button on start screen
websupporter Sep 24, 2020
6d8b6bf
prevent 'do you want to leave'-alert when redirect occurs through pay…
websupporter Sep 24, 2020
b41e760
fix button toggle, which was prevented from the general checkbox chan…
websupporter Sep 24, 2020
8a3ae89
codestyle fix
websupporter Sep 24, 2020
8d682af
add new setting fields to differentiate between live/sandbox credentials
websupporter Sep 25, 2020
9327b19
add new fields for production and sandbox credentials.
websupporter Sep 25, 2020
de4dc87
store credentials also in the sandbox-prod-credential buckets when re…
websupporter Sep 25, 2020
28863a2
make sure client_id and client_secret are properly stored.
websupporter Sep 25, 2020
d7cd055
connect the referral endpoints always to the connect.woocommerce inst…
websupporter Sep 25, 2020
2cb1656
redirect when merchant_email has been stored from GET parameters.
websupporter Sep 25, 2020
3733576
fully onboarded needs all credentials being present
websupporter Sep 25, 2020
e5a569e
seperate state detection by production/sandbox
websupporter Sep 25, 2020
074a6ea
remove the toggle for a credentials set once those are set.
websupporter Sep 25, 2020
e8a3b3d
remove reset functionality from Settings container
websupporter Sep 25, 2020
091077d
codestyle
websupporter Sep 25, 2020
07f08a2
make sure sandbox and production data is present before setting clien…
websupporter Sep 28, 2020
15580be
resolve merge conflict
websupporter Sep 29, 2020
2f474cc
add disconnect button
websupporter Sep 29, 2020
81bedf3
move api urls to constants
websupporter Oct 1, 2020
2a099b0
simplify should_render logic
websupporter Oct 1, 2020
7521e63
add semicolons
websupporter Oct 1, 2020
0a3acae
Merge branch 'master' into issue-22-sandbox-live-switch
websupporter Oct 1, 2020
fa1c2e4
take client_id and secret into account when deciding whether DCC is e…
websupporter Oct 1, 2020
321a324
print warning when client_id is not present while trying to store mer…
websupporter Oct 1, 2020
6683617
even without client_id we want to store the merchant_id
websupporter Oct 2, 2020
2a88248
use the plugins notice module to render the notice
websupporter Oct 2, 2020
9510925
remove the alert box in javascript when onboarding fails
websupporter Oct 2, 2020
d9b2818
redirect when POST request with the error-get-parameter, so no error …
websupporter Oct 2, 2020
2608f19
resolve merge conflict
websupporter Oct 5, 2020
722b67a
make sure to store sandbox_on even when method throws error
websupporter Oct 6, 2020
abb2346
codestyle
websupporter Oct 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/ppcp-api-client/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@

return array(
'api.host' => function( $container ) : string {
return 'https://api.paypal.com';
return PAYPAL_API_URL;
},
'api.paypal-host' => function( $container ) : string {
return 'https://api.paypal.com';
return PAYPAL_API_URL;
},
'api.partner_merchant_id' => static function () : string {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function data(): array {
private function default_data(): array {

return array(
'email' => $this->merchant_email,
'partner_config_override' => array(
'partner_logo_url' => 'https://connect.woocommerce.com/images/woocommerce_logo.png',
'return_url' => admin_url(
Expand Down
15 changes: 10 additions & 5 deletions modules/ppcp-button/src/Assets/class-smartbutton.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,18 +860,23 @@ private function context(): string {
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting has not been found.
*/
private function dcc_is_enabled(): bool {
if ( ! is_checkout() ) {
return false;
}
if ( ! $this->dcc_applies->for_country_currency() ) {
return false;
}
$keys = array(
'dcc_enabled' => 'is_checkout',
'client_id',
'client_secret',
'dcc_enabled',
);
foreach ( $keys as $key => $callback ) {
if ( $this->settings->has( $key ) && $this->settings->get( $key ) && $callback() ) {
return true;
foreach ( $keys as $key ) {
if ( ! $this->settings->has( $key ) || ! $this->settings->get( $key ) ) {
return false;
}
}
return false;
return true;
}

/**
Expand Down
60 changes: 53 additions & 7 deletions modules/ppcp-onboarding/assets/css/onboarding.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
display: none;
}

#field-client_secret,
#field-client_id,
#field-merchant_id{
#field-merchant_email_production,
#field-ppcp_disconnect_sandbox,
#field-ppcp_disconnect_production,
#field-merchant_id_production,
#field-client_id_production,
#field-client_secret_production,
#field-merchant_email_sandbox,
#field-merchant_id_sandbox,
#field-client_id_sandbox,
#field-client_secret_sandbox{
display: none;
}
#field-client_secret.show,
#field-client_id.show,
#field-merchant_id.show {
#field-merchant_email_production.show,
#field-ppcp_disconnect_sandbox.show,
#field-ppcp_disconnect_production.show,
#field-merchant_id_production.show,
#field-client_id_production.show,
#field-client_secret_production.show,
#field-merchant_email_sandbox.show,
#field-merchant_id_sandbox.show,
#field-client_id_sandbox.show,
#field-client_secret_sandbox.show {
display: table-row;
}

Expand All @@ -21,7 +35,8 @@
display: unset;
}

#field-toggle_manual_input button {
#field-production_toggle_manual_input button,
#field-sandbox_toggle_manual_input button {
color: #0073aa;
transition-property: border, background, color;
transition-duration: .05s;
Expand All @@ -33,3 +48,34 @@
margin: 0;
padding: 0;
}

#field-sandbox_toggle_manual_input.onboarded,
#field-production_toggle_manual_input.onboarded {
display: none;
}


#field-ppcp_disconnect_sandbox.onboarded,
#field-ppcp_disconnect_production.onboarded,
#field-merchant_email_sandbox.onboarded,
#field-merchant_id_sandbox.onboarded,
#field-client_id_sandbox.onboarded,
#field-client_secret_sandbox.onboarded,
#field-merchant_email_production.onboarded,
#field-merchant_id_production.onboarded,
#field-client_id_production.onboarded,
#field-client_secret_production.onboarded {
display:table-row;
}
#field-ppcp_disconnect_sandbox.onboarded.hide,
#field-ppcp_disconnect_production.onboarded.hide,
#field-merchant_email_sandbox.onboarded.hide,
#field-merchant_id_sandbox.onboarded.hide,
#field-client_id_sandbox.onboarded.hide,
#field-client_secret_sandbox.onboarded.hide,
#field-merchant_email_production.onboarded.hide,
#field-merchant_id_production.onboarded.hide,
#field-client_id_production.onboarded.hide,
#field-client_secret_production.onboarded.hide {
display:none;
}
187 changes: 178 additions & 9 deletions modules/ppcp-onboarding/assets/js/onboarding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function onboardingCallback(authCode, sharedId) {
const sandboxSwitchElement = document.querySelector('#ppcp-sandbox_on');
fetch(
PayPalCommerceGatewayOnboarding.endpoint,
{
Expand All @@ -10,18 +11,186 @@ function onboardingCallback(authCode, sharedId) {
{
authCode: authCode,
sharedId: sharedId,
nonce: PayPalCommerceGatewayOnboarding.nonce
nonce: PayPalCommerceGatewayOnboarding.nonce,
env: sandboxSwitchElement && sandboxSwitchElement.checked ? 'sandbox' : 'production'
}
)
}
);
}

/**
* Since the PayPal modal will redirect the user a dirty form
* provokes an alert if the user wants to leave the page. Since the user
* needs to toggle the sandbox switch, we disable this dirty state with the
* following workaround for checkboxes.
*
* @param event
*/
const checkBoxOnClick = (event) => {
const value = event.target.checked;
if (event.target.getAttribute('id') === 'ppcp-sandbox_on') {
toggleSandboxProduction(! value);
}
event.preventDefault();
event.stopPropagation();
setTimeout( () => {
event.target.checked = value;
},1
);
};

/**
* Toggles the credential input fields.
*
* @param forProduction
*/
const credentialToggle = (forProduction) => {

const sandboxClassSelectors = [
'#field-ppcp_disconnect_sandbox',
'#field-merchant_email_sandbox',
'#field-merchant_id_sandbox',
'#field-client_id_sandbox',
'#field-client_secret_sandbox',
];
const productionClassSelectors = [
'#field-ppcp_disconnect_production',
'#field-merchant_email_production',
'#field-merchant_id_production',
'#field-client_id_production',
'#field-client_secret_production',
];

const selectors = forProduction ? productionClassSelectors : sandboxClassSelectors;
document.querySelectorAll(selectors.join()).forEach(
(element) => {element.classList.toggle('show')}
)
.then( response => response.json() )
.then(
(data) => {
if (data.success) {
return;
}
alert( PayPalCommerceGatewayOnboarding.error )
};

/**
* Toggles the visibility of the sandbox/production input fields.
*
* @param showProduction
*/
const toggleSandboxProduction = (showProduction) => {
const productionDisplaySelectors = [
'#field-credentials_production_heading',
'#field-production_toggle_manual_input',
'#field-ppcp_onboarding_production',
];
const productionClassSelectors = [

'#field-ppcp_disconnect_production',
'#field-merchant_email_production',
'#field-merchant_id_production',
'#field-client_id_production',
'#field-client_secret_production',
];
const sandboxDisplaySelectors = [
'#field-credentials_sandbox_heading',
'#field-sandbox_toggle_manual_input',
'#field-ppcp_onboarding_sandbox',
];
const sandboxClassSelectors = [
'#field-ppcp_disconnect_sandbox',
'#field-merchant_email_sandbox',
'#field-merchant_id_sandbox',
'#field-client_id_sandbox',
'#field-client_secret_sandbox',
];

if (showProduction) {
document.querySelectorAll(productionDisplaySelectors.join()).forEach(
(element) => {element.style.display = ''}
);
document.querySelectorAll(sandboxDisplaySelectors.join()).forEach(
(element) => {element.style.display = 'none'}
);
document.querySelectorAll(productionClassSelectors.join()).forEach(
(element) => {element.classList.remove('hide')}
);
document.querySelectorAll(sandboxClassSelectors.join()).forEach(
(element) => {
element.classList.remove('show');
element.classList.add('hide');
}
);
}
return;
}
document.querySelectorAll(productionDisplaySelectors.join()).forEach(
(element) => {element.style.display = 'none'}
);
document.querySelectorAll(sandboxDisplaySelectors.join()).forEach(
(element) => {element.style.display = ''}
);

document.querySelectorAll(sandboxClassSelectors.join()).forEach(
(element) => {element.classList.remove('hide')}
);
document.querySelectorAll(productionClassSelectors.join()).forEach(
(element) => {
element.classList.remove('show');
element.classList.add('hide');
}
)
};

const disconnect = (event) => {
event.preventDefault();
const fields = event.target.classList.contains('production') ? [
'#field-merchant_email_production input',
'#field-merchant_id_production input',
'#field-client_id_production input',
'#field-client_secret_production input',
] : [
'#field-merchant_email_sandbox input',
'#field-merchant_id_sandbox input',
'#field-client_id_sandbox input',
'#field-client_secret_sandbox input',
];

document.querySelectorAll(fields.join()).forEach(
(element) => {
element.value = '';
}
);

document.querySelector('.woocommerce-save-button').click();
};

(() => {
const sandboxSwitchElement = document.querySelector('#ppcp-sandbox_on');
if (sandboxSwitchElement) {
toggleSandboxProduction(! sandboxSwitchElement.checked);
}

document.querySelectorAll('.ppcp-disconnect').forEach(
(button) => {
button.addEventListener(
'click',
disconnect
);
}
);

document.querySelectorAll('#mainform input[type="checkbox"]').forEach(
(checkbox) => {
checkbox.addEventListener('click', checkBoxOnClick);
}
);

document.querySelectorAll('#field-sandbox_toggle_manual_input button, #field-production_toggle_manual_input button').forEach(
(button) => {
button.addEventListener(
'click',
(event) => {
event.preventDefault();
const isProduction = event.target.classList.contains('production-toggle');
credentialToggle(isProduction);
}
)
}
)

})();
Loading