Skip to content

Commit

Permalink
BRAIN-41: fraud protection fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lernhart committed Nov 15, 2024
1 parent cd527a4 commit e73f68e
Show file tree
Hide file tree
Showing 20 changed files with 768 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
:title='$t("settings.general.title")'
:is-loading='loading'
>
<div class='sw-braintree-app-settings-general__container'>
<div class='sw-braintree-app-settings-general__threeDSecuredEnforced'>
<mt-switch
class='sw-braintree-app-settings-general__threeDSecureEnforced'
class='sw-braintree-app-settings-general__threeDSecureEnforced__input'
:label='$t("settings.general.threeDSecureEnforced.label")'
:checked='activeConfig?.threeDSecureEnforced ?? undefined'
:is-inherited='isThreeDSecureEnforcedInherited'
:is-inherited='isFieldInherited("threeDSecureEnforced")'
:is-inheritance-field='!!salesChannelId'
@change='onChanceThreeDSecureEnforcedInherited'
@inheritance-remove='onRemoveInheritance'
@inheritance-restore='onRestoreInheritance'
@change='activeConfig.threeDSecureEnforced = !activeConfig.threeDSecureEnforced'
@inheritance-remove='onRemoveInheritance("threeDSecureEnforced")'
@inheritance-restore='onRestoreInheritance("threeDSecureEnforced")'
/>

<mt-icon
Expand All @@ -23,21 +23,35 @@
name='solid-question-circle-s'
/>
</div>
<div class='sw-braintree-app-settings-general__shipsFromPostalCode'>
<mt-text-field
class='sw-braintree-app-settings-general__shipsFromPostalCode__input'
:label='$t("settings.general.shipsFromPostalCode.label")'
:placeholder='$t("settings.general.shipsFromPostalCode.placeholder")'
:value='activeConfig?.shipsFromPostalCode ?? undefined'
:is-inherited='isFieldInherited("shipsFromPostalCode")'
:is-inheritance-field='!!salesChannelId'
:model-value='activeConfig.shipsFromPostalCode ?? undefined'
@update:model-value='activeConfig.shipsFromPostalCode = $event ?? null'
@inheritance-remove='onRemoveInheritance("shipsFromPostalCode")'
@inheritance-restore='onRestoreInheritance("shipsFromPostalCode")'
/>
</div>
</mt-card>
</template>

<script lang='ts'>
import type { PropType } from 'vue';
import { defineComponent } from 'vue';
import { MtCard, MtSwitch, MtIcon } from '@shopware-ag/meteor-component-library';
import { MtCard, MtSwitch, MtIcon, MtTextField } from '@shopware-ag/meteor-component-library';
import { registerSaveHandler } from '@/resources/inject-keys';
import { DefaultConfigEntity } from '@/resources/entities';
import { inject } from 'vue';
export default defineComponent({
name: 'sw-braintree-app-settings-general',
components: { MtCard, MtSwitch, MtIcon },
components: { MtTextField, MtCard, MtSwitch, MtIcon },
props: {
salesChannelId: {
Expand Down Expand Up @@ -71,13 +85,6 @@ export default defineComponent({
activeConfig(): ConfigEntity {
return this.config[this.stringifySalesChannelId] ?? DefaultConfigEntity(this.salesChannelId);
},
isThreeDSecureEnforcedInherited(){
if(this.salesChannelId === null)
return false;
return this.activeConfig.threeDSecureEnforced === null;
},
},
watch: {
Expand Down Expand Up @@ -116,31 +123,43 @@ export default defineComponent({
.catch((e) => this.$notify.error('save_settings', e));
},
onChanceThreeDSecureEnforcedInherited(){
this.activeConfig.threeDSecureEnforced = !this.activeConfig.threeDSecureEnforced;
isFieldInherited(key: keyof ConfigEntity): boolean {
if (this.salesChannelId === null)
return false;
return this.activeConfig[key] === null;
},
onRemoveInheritance(){
this.activeConfig.threeDSecureEnforced = this.config['null']?.threeDSecureEnforced ?? false;
onRemoveInheritance(key: keyof ConfigEntity): void {
// @ts-expect-error - TS does not know that the value of key is a valid assignment
this.activeConfig[key] = this.config['null']?.[key]?? DefaultConfigEntity(this.salesChannelId)[key];
},
onRestoreInheritance(){
this.activeConfig.threeDSecureEnforced = null;
onRestoreInheritance(key: keyof ConfigEntity): void {
// @ts-expect-error - TS does not know that the value of key is a valid assignment
this.activeConfig[key] = null;
},
},
});
</script>

<style lang='scss'>
.sw-braintree-app-settings-general {
&__container {
display: flex;
flex-direction: column;
&__threeDSecuredEnforced {
display: flex;
align-items: center;
gap: 8px;
.mt-field--switch__container .mt-field--switch {
margin: 0;
}
}
.mt-field--switch__container .mt-field--switch {
margin: 0;
&__shipsFromPostalCode {
margin-top: 24px;
}
}
</style>
6 changes: 5 additions & 1 deletion assets/src/i18n/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
"threeDSecureEnforced": {
"label": "Only accept transactions with 3D Secure"
},
"threeDSecureToolTip": "Transaction will not be accepted, if 3D Secure is not available"
"threeDSecureToolTip": "Transaction will not be accepted, if 3D Secure is not available",
"shipsFromPostalCode": {
"label": "Sender shipping address postal code",
"placeholder": "e.g. 48268"
}
},
"currency": {
"missingAccountTitle": "Missing information",
Expand Down
1 change: 1 addition & 0 deletions assets/src/resources/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const DefaultConfigEntity = (salesChannelId?: string | null): ConfigEntit
id: null,
shop: '',
threeDSecureEnforced: false,
shipsFromPostalCode: null,
salesChannelId: salesChannelId ?? null,
createdAt: (new Date()).toISOString(),
updatedAt: null,
Expand Down
3 changes: 3 additions & 0 deletions assets/src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ declare global {
id: string | null,
shop: string,
threeDSecureEnforced: boolean | null,
shipsFromPostalCode: string | null,
salesChannelId: string | null,
createdAt: string,
updatedAt: string | null,
}

type ConfigEntityProperties = keyof Omit<ConfigEntity, 'shop' | 'createdAt' | 'updatedAt' | 'id' | 'salesChannelId'>;

interface CurrencyMappingEntity {
id: string | null,
shop: string,
Expand Down
Loading

0 comments on commit e73f68e

Please sign in to comment.