-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding fixes for getting items from the api * paycek * paycek * paycek * Apply suggestions from code review Co-authored-by: Ivan Ramljak <22823970+piqusy@users.noreply.github.com> Co-authored-by: Davorin Prislin <81157133+dadadavorin@users.noreply.github.com> * fixing pr issues --------- Co-authored-by: Ivan Ramljak <22823970+piqusy@users.noreply.github.com> Co-authored-by: Davorin Prislin <81157133+dadadavorin@users.noreply.github.com>
- Loading branch information
1 parent
3b3c355
commit 82a16b6
Showing
29 changed files
with
1,095 additions
and
61 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* PaymentGateways class. | ||
*/ | ||
export class PaymentGateways { | ||
constructor({ | ||
utils, | ||
state, | ||
response, | ||
}) { | ||
/** @type {import('./utils').Utils} */ | ||
this.utils = utils; | ||
/** @type {import('./state').State} */ | ||
this.state = state; | ||
|
||
this.response = response; | ||
} | ||
|
||
/** | ||
* Initialize the payment gateway. | ||
* @returns {void} | ||
*/ | ||
init() { | ||
const { | ||
type, | ||
url, | ||
params, | ||
} = this.response; | ||
|
||
if (type === 'SUBMIT') { | ||
this.initFormActionSubmit(url, params); | ||
} | ||
|
||
if (type === 'POST') { | ||
this.initFormSubmitBuilder(url, params); | ||
} | ||
|
||
if (type === 'GET') { | ||
this.initUrlRedirect(url); | ||
} | ||
} | ||
|
||
/** | ||
* Submit the form action. | ||
* | ||
* @returns {void} | ||
*/ | ||
initFormActionSubmit() { | ||
this.state.getStateFormElement().submit(); | ||
} | ||
|
||
/** | ||
* Redirect to the given URL. | ||
* @param {string} url | ||
* @returns {void} | ||
*/ | ||
initUrlRedirect(url) { | ||
window.location.href = url; | ||
} | ||
|
||
/** | ||
* Submit a form with the given URL and parameters. | ||
* @param {string} url | ||
* @param {Record<string, string>} params | ||
* @returns {void} | ||
*/ | ||
initFormSubmitBuilder(url, params) { | ||
// Create a form element. | ||
const form = document.createElement('form'); | ||
form.method = 'POST'; | ||
form.action = url; | ||
|
||
// Populate hidden fields with parameters | ||
Object.entries(params).forEach(([key, value]) => { | ||
const hiddenField = document.createElement('input'); | ||
hiddenField.type = 'hidden'; | ||
hiddenField.name = key; | ||
hiddenField.value = String(value); | ||
form.appendChild(hiddenField); | ||
}); | ||
|
||
// Append form to body, submit it, then remove it | ||
document.body.appendChild(form); | ||
form.submit(); | ||
document.body.removeChild(form); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { select } from '@wordpress/data'; | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
import { props, checkAttr, BlockInserter, STORE_NAME } from '@eightshift/frontend-libs/scripts'; | ||
import { FormEditor } from '../../../components/form/components/form-editor'; | ||
|
||
export const PaycekEditor = ({ attributes, setAttributes, clientId }) => { | ||
const manifest = select(STORE_NAME).getBlock('paycek'); | ||
|
||
const { | ||
blockClass, | ||
} = attributes; | ||
|
||
const paycekAllowedBlocks = checkAttr('paycekAllowedBlocks', attributes, manifest); | ||
|
||
return ( | ||
<div className={blockClass}> | ||
<FormEditor | ||
{...props('form', attributes, { | ||
setAttributes, | ||
formContent: <InnerBlocks | ||
allowedBlocks={(typeof paycekAllowedBlocks === 'undefined') || paycekAllowedBlocks} | ||
templateLock={false} | ||
renderAppender={() => <BlockInserter clientId={clientId} />} | ||
/> | ||
})} | ||
/> | ||
</div> | ||
); | ||
}; |
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,25 @@ | ||
import React from 'react'; | ||
import { select } from '@wordpress/data'; | ||
import { IntegrationsInternalOptions } from '../../../components/integrations/components/integrations-internal-options'; | ||
import { STORE_NAME } from '@eightshift/frontend-libs/scripts'; | ||
|
||
export const PaycekOptions = ({ | ||
attributes, | ||
setAttributes, | ||
clientId, | ||
}) => { | ||
const manifest = select(STORE_NAME).getBlock('paycek'); | ||
|
||
const { | ||
title, | ||
} = manifest; | ||
|
||
return ( | ||
<IntegrationsInternalOptions | ||
title={title} | ||
clientId={clientId} | ||
attributes={attributes} | ||
setAttributes={setAttributes} | ||
/> | ||
); | ||
}; |
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,38 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/infinum/eightshift-frontend-libs/develop/schemas/block.json", | ||
"blockName": "paycek", | ||
"title": "PayCek form", | ||
"description" : "PayCek payment form", | ||
"category": "eightshift-forms", | ||
"icon": { | ||
"src": "esf-form-paycek" | ||
}, | ||
"keywords": [ | ||
"paycek" | ||
], | ||
"example": { | ||
}, | ||
"components": { | ||
"form": "form", | ||
"step": "step" | ||
}, | ||
"hasInnerBlocks": true, | ||
"attributes": { | ||
"paycekAllowedBlocks": { | ||
"type": "array", | ||
"default": [] | ||
}, | ||
"paycekIntegrationId": { | ||
"type": "string" | ||
}, | ||
"paycekFormPostId": { | ||
"type": "string" | ||
}, | ||
"paycekFormDataTypeSelector": { | ||
"type": "string" | ||
} | ||
}, | ||
"parent": [ | ||
"eightshift-forms/form-selector" | ||
] | ||
} |
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,15 @@ | ||
import React from 'react'; | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
import { PaycekEditor } from './components/paycek-editor'; | ||
import { PaycekOptions } from './components/paycek-options'; | ||
|
||
export const Paycek = (props) => { | ||
return ( | ||
<> | ||
<InspectorControls> | ||
<PaycekOptions {...props} /> | ||
</InspectorControls> | ||
<PaycekEditor {...props} /> | ||
</> | ||
); | ||
}; |
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,33 @@ | ||
/* global esFormsLocalization */ | ||
|
||
import { addFilter } from '@wordpress/hooks'; | ||
import { select } from '@wordpress/data'; | ||
import { STORE_NAME } from '@eightshift/frontend-libs/scripts/editor'; | ||
import { isArray } from 'lodash'; | ||
|
||
// Provide additional blocks to the forms. | ||
export const hooks = () => { | ||
const { blockName } = select(STORE_NAME).getBlock('paycek'); | ||
const namespace = select(STORE_NAME).getSettingsNamespace(); | ||
|
||
// All adding additional blocks to the custom form builder. | ||
addFilter('blocks.registerBlockType', `${namespace}/${blockName}`, (settings, name) => { | ||
if (name === `${namespace}/${blockName}`) { | ||
if (typeof esFormsLocalization !== 'undefined' && isArray(esFormsLocalization?.additionalBlocks)) { | ||
esFormsLocalization.additionalBlocks.forEach((element) => { | ||
if (!settings.attributes.paycekAllowedBlocks.default.includes(element)) { | ||
settings.attributes.paycekAllowedBlocks.default.push(element); | ||
} | ||
}); | ||
} | ||
|
||
select(STORE_NAME).getSettings().allowedBlocksBuilderIntegrationAdditionalBlocksList.forEach((element) => { | ||
if (!settings.attributes.paycekAllowedBlocks.default.includes(element)) { | ||
settings.attributes.paycekAllowedBlocks.default.push(element); | ||
} | ||
}); | ||
} | ||
|
||
return settings; | ||
}); | ||
}; |
Oops, something went wrong.