-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PPI-1040 - Revamped first-run-wizard extension
- Loading branch information
Showing
9 changed files
with
478 additions
and
220 deletions.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
src/Resources/app/administration/src/module/extension/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
.../extension/sw-first-run-wizard/sw-first-run-wizard-paypal-credentials-deprecated/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import type * as PayPal from 'src/types'; | ||
import template from './sw-first-run-wizard-paypal-credentials.html.twig'; | ||
import './sw-first-run-wizard-paypal-credentials.scss'; | ||
|
||
export default Shopware.Component.wrapComponentConfig({ | ||
template, | ||
|
||
inject: [ | ||
'systemConfigApiService', | ||
'SwagPaypalPaymentMethodService', | ||
], | ||
|
||
mixins: [ | ||
Shopware.Mixin.getByName('swag-paypal-notification'), | ||
Shopware.Mixin.getByName('swag-paypal-credentials-loader'), | ||
], | ||
|
||
data() { | ||
return { | ||
config: {} as PayPal.SystemConfig, | ||
isLoading: false, | ||
setDefault: false, | ||
}; | ||
}, | ||
|
||
computed: { | ||
sandboxMode() { | ||
return this.config['SwagPayPal.settings.sandbox'] || false; | ||
}, | ||
|
||
onboardingUrl() { | ||
return this.sandboxMode ? this.onboardingUrlSandbox : this.onboardingUrlLive; | ||
}, | ||
|
||
onboardingCallback() { | ||
return this.sandboxMode ? 'onboardingCallbackSandbox' : 'onboardingCallbackLive'; | ||
}, | ||
|
||
buttonConfig() { | ||
const prev = this.$super('buttonConfig') as { key: string; action: () => Promise<boolean> }[]; | ||
|
||
return prev.map((button) => { | ||
if (button.key === 'next') { | ||
button.action = this.onClickNext.bind(this); | ||
} | ||
|
||
return button; | ||
}); | ||
}, | ||
|
||
credentialsProvided() { | ||
return (!this.sandboxMode && this.credentialsProvidedLive) | ||
|| (this.sandboxMode && this.credentialsProvidedSandbox); | ||
}, | ||
|
||
credentialsProvidedLive() { | ||
return !!this.config['SwagPayPal.settings.clientId'] | ||
&& !!this.config['SwagPayPal.settings.clientSecret']; | ||
}, | ||
|
||
credentialsProvidedSandbox() { | ||
return !!this.config['SwagPayPal.settings.clientIdSandbox'] | ||
&& !!this.config['SwagPayPal.settings.clientSecretSandbox']; | ||
}, | ||
}, | ||
|
||
created() { | ||
this.createdComponent(); | ||
}, | ||
|
||
methods: { | ||
createdComponent() { | ||
this.$super('createdComponent'); | ||
this.fetchPayPalConfig(); | ||
}, | ||
|
||
onPayPalCredentialsLoadSuccess(clientId: string, clientSecret: string, merchantPayerId: string, sandbox: boolean) { | ||
this.setConfig(clientId, clientSecret, merchantPayerId, sandbox); | ||
}, | ||
|
||
onPayPalCredentialsLoadFailed(sandbox: boolean) { | ||
this.setConfig('', '', '', sandbox); | ||
this.createNotificationError({ | ||
message: this.$tc('swag-paypal-frw-credentials.messageFetchedError'), | ||
// @ts-expect-error - duration is not defined correctly | ||
duration: 10000, | ||
}); | ||
}, | ||
|
||
setConfig(clientId: string, clientSecret: string, merchantPayerId: string, sandbox: boolean) { | ||
const suffix = sandbox ? 'Sandbox' : ''; | ||
this.$set(this.config, `SwagPayPal.settings.clientId${suffix}`, clientId); | ||
this.$set(this.config, `SwagPayPal.settings.clientSecret${suffix}`, clientSecret); | ||
this.$set(this.config, `SwagPayPal.settings.merchantPayerId${suffix}`, merchantPayerId); | ||
}, | ||
|
||
async onClickNext(): Promise<boolean> { | ||
if (!this.credentialsProvided) { | ||
this.createNotificationError({ | ||
message: this.$tc('swag-paypal-frw-credentials.messageNoCredentials'), | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
try { | ||
// Do not test the credentials if they have been fetched from the PayPal api | ||
if (!this.isGetCredentialsSuccessful) { | ||
await this.testApiCredentials(); | ||
} | ||
|
||
await this.saveConfig(); | ||
|
||
this.$emit('frw-redirect', 'sw.first.run.wizard.index.plugins'); | ||
|
||
return false; | ||
} catch { | ||
return true; | ||
} | ||
}, | ||
|
||
fetchPayPalConfig() { | ||
this.isLoading = true; | ||
return this.systemConfigApiService.getValues('SwagPayPal.settings', null) | ||
.then((values: PayPal.SystemConfig) => { | ||
this.config = values; | ||
}) | ||
.finally(() => { | ||
this.isLoading = false; | ||
}); | ||
}, | ||
|
||
async saveConfig() { | ||
this.isLoading = true; | ||
await this.systemConfigApiService.saveValues(this.config, null); | ||
|
||
if (this.setDefault) { | ||
await this.SwagPaypalPaymentMethodService.setDefaultPaymentForSalesChannel(); | ||
} | ||
|
||
this.isLoading = false; | ||
}, | ||
|
||
async testApiCredentials() { | ||
this.isLoading = true; | ||
|
||
const sandbox = this.config['SwagPayPal.settings.sandbox'] ?? false; | ||
const sandboxSetting = sandbox ? 'Sandbox' : ''; | ||
const clientId = this.config[`SwagPayPal.settings.clientId${sandboxSetting}`]; | ||
const clientSecret = this.config[`SwagPayPal.settings.clientSecret${sandboxSetting}`]; | ||
|
||
const response = await this.SwagPayPalApiCredentialsService | ||
.validateApiCredentials(clientId, clientSecret, sandbox) | ||
.catch((errorResponse: PayPal.ServiceError) => { | ||
this.createNotificationFromError({ errorResponse, title: 'swag-paypal.settingForm.messageTestError' }); | ||
|
||
return { credentialsValid: false }; | ||
}); | ||
|
||
this.isLoading = false; | ||
|
||
return response.credentialsValid ? Promise.resolve() : Promise.reject(); | ||
}, | ||
|
||
onCredentialsChanged() { | ||
this.isGetCredentialsSuccessful = null; | ||
}, | ||
}, | ||
}); |
122 changes: 122 additions & 0 deletions
122
...run-wizard-paypal-credentials-deprecated/sw-first-run-wizard-paypal-credentials.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{% block sw_first_run_wizard_paypal_credentials %} | ||
<div class="sw-first-run-wizard-paypal-credentials"> | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_inner %} | ||
<sw-loader v-if="isLoading" /> | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_intro %} | ||
<p class="sw-first-run-wizard-paypal-credentials__headerText"> | ||
{{ $tc('swag-paypal-frw-credentials.textIntroPayPal') }} | ||
</p> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_sandbox %} | ||
<sw-switch-field | ||
v-model:value="config['SwagPayPal.settings.sandbox']" | ||
:label="$tc('swag-paypal-frw-credentials.labelSandbox')" | ||
:helpText="$tc('swag-paypal-frw-credentials.tooltipSandbox')" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_button_container %} | ||
<div class="sw-first-run-wizard-paypal-credentials__button-container"> | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_button %} | ||
<a | ||
class="sw-button sw-button--primary swag-paypal-frw__signup-button" | ||
target="_blank" | ||
:data-paypal-onboard-complete="onboardingCallback" | ||
:href="`${onboardingUrl}`" | ||
data-paypal-button="true" | ||
> | ||
{{ $tc('swag-paypal-frw-credentials.buttonGetCredentials') }} | ||
</a> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_indicator %} | ||
<div class="sw-first-run-wizard-paypal-credentials__indicator"> | ||
<template v-if="isGetCredentialsSuccessful"> | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_indicator_icon %} | ||
<sw-icon | ||
name="regular-checkmark-s" | ||
class="sw-first-run-wizard-paypal-credentials__icon-successful" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_indicator_text %} | ||
<span class="sw-first-run-wizard-paypal-credentials__text-indicator"> | ||
{{ $tc('swag-paypal-frw-credentials.textFetchedSuccessful') }} | ||
</span> | ||
{% endblock %} | ||
</template> | ||
</div> | ||
{% endblock %} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_client_id %} | ||
<sw-text-field | ||
v-show="!sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.clientId']" | ||
:label="$tc('swag-paypal-frw-credentials.labelClientId')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_client_secret %} | ||
<sw-text-field | ||
v-show="!sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.clientSecret']" | ||
:label="$tc('swag-paypal-frw-credentials.labelClientSecret')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_merchant_id %} | ||
<sw-text-field | ||
v-show="!sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.merchantPayerId']" | ||
:label="$tc('swag-paypal-frw-credentials.labelMerchantPayerId')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_client_id_sandbox %} | ||
<sw-text-field | ||
v-show="sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.clientIdSandbox']" | ||
:label="$tc('swag-paypal-frw-credentials.labelClientIdSandbox')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_client_secret_sandbox %} | ||
<sw-text-field | ||
v-show="sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.clientSecretSandbox']" | ||
:label="$tc('swag-paypal-frw-credentials.labelClientSecretSandbox')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_merchant_id_sandbox %} | ||
<sw-text-field | ||
v-show="sandboxMode" | ||
v-model:value="config['SwagPayPal.settings.merchantPayerIdSandbox']" | ||
:label="$tc('swag-paypal-frw-credentials.labelMerchantPayerIdSandbox')" | ||
@update:value="onCredentialsChanged" | ||
/> | ||
{% endblock %} | ||
|
||
{% block sw_first_run_wizard_paypal_credentials_set_default %} | ||
<sw-switch-field | ||
v-model:value="setDefault" | ||
:disabled="!credentialsProvided" | ||
:label="$tc('swag-paypal-frw-credentials.labelSetDefault')" | ||
:helpText="$tc('swag-paypal-frw-credentials.tooltipSetDefault')" | ||
/> | ||
{% endblock %} | ||
{% endblock %} | ||
</div> | ||
{% endblock %} |
31 changes: 31 additions & 0 deletions
31
...irst-run-wizard-paypal-credentials-deprecated/sw-first-run-wizard-paypal-credentials.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import "~scss/variables"; | ||
|
||
.sw-first-run-wizard-paypal-credentials { | ||
width: 100%; | ||
|
||
.sw-first-run-wizard-paypal-credentials__headerText { | ||
font-weight: bold; | ||
color: $color-darkgray-200; | ||
margin-bottom: 22px; | ||
} | ||
|
||
.sw-first-run-wizard-paypal-credentials__button-container { | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: 22px; | ||
|
||
.sw-first-run-wizard-paypal-credentials__indicator { | ||
display: inline; | ||
margin-left: 25px; | ||
|
||
.sw-first-run-wizard-paypal-credentials__icon-successful { | ||
color: $color-emerald-500; | ||
margin-top: -5px; | ||
} | ||
|
||
.sw-first-run-wizard-paypal-credentials__text-indicator { | ||
margin-left: 8px; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.