-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from hyva-themes/custom-payment-renderers-imp…
…rovement Custom payment renderers integration improvement
- Loading branch information
Showing
6 changed files
with
91 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs'); | ||
const util = require('util'); | ||
const exec = util.promisify(require('child_process').exec); | ||
|
||
module.exports = { | ||
async installRepo(path, directory, repoUri, repoType) { | ||
console.log(`Installing ${directory}: ${repoUri}`); | ||
await exec(`git clone ${repoUri} ${path}${directory}`); | ||
console.log(`${directory} ${repoType} added successfully.`); | ||
}, | ||
|
||
collectConfiguredReposFromEnv(configKey) { | ||
const { env } = process; | ||
const configPrefix = `npm_package_config_${configKey}_`; | ||
const repos = {}; | ||
|
||
Object.keys(env).forEach((envProp) => { | ||
if (envProp.startsWith(configPrefix)) { | ||
const paymentCode = envProp.replace(configPrefix, ''); | ||
if (paymentCode) { | ||
repos[paymentCode] = env[envProp]; | ||
} | ||
} | ||
}); | ||
|
||
return repos; | ||
}, | ||
|
||
async cloneAndConfigureRepos(repoList, installationPath, repoType) { | ||
const paymentMethodList = Object.keys(repoList); | ||
|
||
await Promise.all( | ||
paymentMethodList.map(async (repo) => { | ||
if (!fs.existsSync(`${installationPath}${repo}`)) { | ||
await this.installRepo( | ||
installationPath, | ||
repo, | ||
repoList[repo], | ||
repoType | ||
); | ||
} | ||
return 'success'; | ||
}) | ||
); | ||
}, | ||
}; |
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,12 @@ | ||
import { paymentFetcher } from './utility'; | ||
|
||
/** | ||
* Preparing custom renderers from the available payment methods configured | ||
* into this directory. | ||
* 📢 📢 📢 This file is autogenerated and may be overwritten. Handle with care. 🙅🏽 🙅🏽 🙅🏽 | ||
* | ||
* Available payment methods are available in `paymentConfig.json`. | ||
* When you have custom payment repo integration, then the content of this file | ||
* will be overwritten during performing "npm install". So, in most of the cases, | ||
* you don't need to alter the content of this file. | ||
* | ||
* Each payment methods will posses `renderers.js` file which will defines the | ||
* custom payment method renderers. This will collect all the renderers provide | ||
* it into the PaymentMethods component. | ||
* But, if you have your own custom payment methods locally, then you need to | ||
* include them here as well. That is the only time you need to touch this file. | ||
*/ | ||
export default async function getCustomRenderers() { | ||
const paymentMethodRenderers = | ||
await paymentFetcher.fetchDataFromPaymentMethods('renderers.js', []); | ||
|
||
return paymentMethodRenderers.reduce( | ||
(renderers, item) => ({ ...renderers, ...item }), | ||
{} | ||
); | ||
} | ||
export default {}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.