-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): finish the config initial
- Loading branch information
1 parent
653cdab
commit feb7a09
Showing
9 changed files
with
91 additions
and
67 deletions.
There are no files selected for viewing
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,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"Malga" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,41 +1,29 @@ | ||
import { Malga } from 'src/common/malga' | ||
import { MalgaFormElements } from 'src/common/interfaces' | ||
import { | ||
getFormElements, | ||
removeFormElements, | ||
createFormElement, | ||
getFormValues, | ||
} from '../common/utils' | ||
|
||
export class AsyncTokenize { | ||
constructor( | ||
private readonly malga: Malga, | ||
private readonly elements: MalgaFormElements, | ||
// private readonly elements: MalgaFormElements, | ||
) {} | ||
|
||
public handle() { | ||
const { form } = getFormElements(this.elements) | ||
|
||
form?.addEventListener('submit', async (event) => { | ||
event.preventDefault() | ||
|
||
const { holderName, number, expirationDate, cvv } = getFormValues( | ||
this.elements, | ||
) | ||
|
||
const { tokenId } = await this.malga.tokenization({ | ||
holderName, | ||
number, | ||
expirationDate, | ||
cvv, | ||
}) | ||
|
||
removeFormElements(this.elements) | ||
const tokenIdElement = createFormElement('tokenId', tokenId) | ||
|
||
form?.appendChild(tokenIdElement) | ||
|
||
form?.submit() | ||
}) | ||
return console.log('async') | ||
// const { form } = getFormElements(this.elements) | ||
// form?.addEventListener('submit', async (event) => { | ||
// event.preventDefault() | ||
// // const { holderName, number, expirationDate, cvv } = getFormValues( | ||
// // this.elements, | ||
// // ) | ||
// const { tokenId } = await this.malga.tokenization({ | ||
// holderName, | ||
// number, | ||
// expirationDate, | ||
// cvv, | ||
// }) | ||
// removeFormElements(this.elements) | ||
// const tokenIdElement = createFormElement('tokenId', tokenId) | ||
// form?.appendChild(tokenIdElement) | ||
// form?.submit() | ||
// }) | ||
} | ||
} |
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,10 @@ | ||
export enum Event { | ||
Submit = 'submit', | ||
Focus = 'focus', | ||
Blur = 'blur', | ||
OnChange = 'change', | ||
Input = 'input', | ||
Tokenize = 'tokenize', | ||
UpdateField = 'updateField', | ||
SetTypeField = 'setTypeField', | ||
} |
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,6 @@ | ||
export enum Field { | ||
CardNumber = 'card-number', | ||
CardHolderName = 'card-holder-name', | ||
CardExpirationDate = 'card-expiration-date', | ||
CardCvv = 'card-cvv', | ||
} |
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,2 @@ | ||
export * from './Events' | ||
export * from './Fields' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import type { MalgaInputFieldConfigurations } from 'src/common/interfaces' | ||
import { EventPostMessage } from '../form-events' | ||
import { create } from './create' | ||
import { camelToKebabCase } from './parsedString' | ||
import { Event } from 'src/common/enums' | ||
|
||
export function loaded(configFields: any) { | ||
const fields = Object.keys(configFields) | ||
export function loaded(config: MalgaInputFieldConfigurations) { | ||
const fields = Object.keys(config.fields) | ||
|
||
for (const field of fields) { | ||
const fieldConfig = config.fields[field] | ||
|
||
const iframe = create(field) | ||
const iframeName = camelToKebabCase(field) | ||
if (!iframe || !iframe.contentWindow) return | ||
|
||
if (!iframe || !iframe.contentWindow) { | ||
console.error(`Error to access the iframe of ${field}`) | ||
return | ||
} | ||
|
||
const parentNode = document.querySelector(fieldConfig.container) | ||
|
||
if (!parentNode) { | ||
console.error(`Container not found ${field}: ${fieldConfig.container}`) | ||
return | ||
} | ||
|
||
parentNode?.appendChild(iframe) | ||
|
||
const iframePostmessage = new EventPostMessage(iframe.contentWindow, '*') | ||
|
||
iframe.onload = () => { | ||
iframePostmessage.send('setTypeField', { | ||
iframePostmessage.send(Event.SetTypeField, { | ||
fieldType: iframeName, | ||
}) | ||
|
||
iframe.onload = null | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import { Malga } from 'src/common/malga' | ||
import { MalgaFormElements } from 'src/common/interfaces' | ||
import { getFormValues } from '../common/utils' | ||
|
||
export class Tokenize { | ||
constructor( | ||
private readonly malga: Malga, | ||
private readonly elements: MalgaFormElements, | ||
) {} | ||
constructor(private readonly malga: Malga) {} | ||
|
||
public async handle() { | ||
const { holderName, number, expirationDate, cvv } = getFormValues( | ||
this.elements, | ||
) | ||
// const { holderName, number, expirationDate, cvv } = getFormValues( | ||
// this.elements, | ||
// ) | ||
|
||
return this.malga.tokenization({ | ||
holderName, | ||
number, | ||
expirationDate, | ||
cvv, | ||
}) | ||
return console.log('entrou nessa funcao do tokeniza') | ||
// return this.malga.tokenization({ | ||
// holderName, | ||
// number, | ||
// expirationDate, | ||
// cvv, | ||
// }) | ||
} | ||
} |