@akinon/next 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +40 -0
- package/CHANGELOG.md +7 -0
- package/hooks/index.ts +1 -0
- package/hooks/use-payment-options.ts +53 -0
- package/package.json +7 -2
- package/plugins.js +2 -1
- package/types/commerce/checkout.ts +1 -0
- package/types/index.ts +1 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
node: true,
|
|
5
|
+
es2021: true
|
|
6
|
+
},
|
|
7
|
+
extends: [
|
|
8
|
+
'eslint:recommended',
|
|
9
|
+
'next/core-web-vitals',
|
|
10
|
+
'eslint:recommended',
|
|
11
|
+
'plugin:@typescript-eslint/recommended',
|
|
12
|
+
'prettier',
|
|
13
|
+
'plugin:@akinon/projectzero/core', // DO NOT remove this config for stability
|
|
14
|
+
'plugin:@akinon/projectzero/recommended'
|
|
15
|
+
],
|
|
16
|
+
overrides: [
|
|
17
|
+
{
|
|
18
|
+
env: {
|
|
19
|
+
node: true
|
|
20
|
+
},
|
|
21
|
+
files: ['.eslintrc.{js,cjs}', 'middlewares/default.ts'],
|
|
22
|
+
rules: {
|
|
23
|
+
'@akinon/projectzero/check-middleware-order': 'error'
|
|
24
|
+
},
|
|
25
|
+
parserOptions: {
|
|
26
|
+
sourceType: 'script'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
parser: '@typescript-eslint/parser',
|
|
31
|
+
parserOptions: {
|
|
32
|
+
ecmaVersion: '2021',
|
|
33
|
+
sourceType: 'module'
|
|
34
|
+
},
|
|
35
|
+
plugins: ['@typescript-eslint', '@akinon/projectzero'],
|
|
36
|
+
rules: {
|
|
37
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
38
|
+
'@typescript-eslint/no-explicit-any': 'warn'
|
|
39
|
+
}
|
|
40
|
+
};
|
package/CHANGELOG.md
CHANGED
package/hooks/index.ts
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import plugins from '@theme/plugins';
|
|
2
|
+
import settings from '@theme/settings';
|
|
3
|
+
import { useAppSelector } from '@akinon/next/redux/hooks';
|
|
4
|
+
import { RootState } from '@theme/redux/store';
|
|
5
|
+
|
|
6
|
+
export const usePaymentOptions = () => {
|
|
7
|
+
const { paymentOptions } = useAppSelector(
|
|
8
|
+
(state: RootState) => state.checkout
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const initialTypes = new Set([
|
|
12
|
+
'credit_card',
|
|
13
|
+
'funds_transfer',
|
|
14
|
+
'redirection'
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const paymentTypeToPluginMap = {
|
|
18
|
+
pay_on_delivery: 'pz-pay-on-delivery',
|
|
19
|
+
bkm_express: 'pz-bkm'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
|
|
23
|
+
|
|
24
|
+
const isPluginMapIncluded = (type: string) => {
|
|
25
|
+
if (paymentTypeToPluginMap.hasOwnProperty(type)) {
|
|
26
|
+
const pluginName = paymentTypeToPluginMap[type];
|
|
27
|
+
return plugins.includes(pluginName);
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const isExtraTypeIncluded = (type: string) => {
|
|
33
|
+
const extraPaymentTypes = settings?.checkout?.extraPaymentTypes || [];
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
extraPaymentTypes.includes(type) &&
|
|
37
|
+
!initialTypes.has(type) &&
|
|
38
|
+
!paymentTypeToPluginMap.hasOwnProperty(type)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const filteredPaymentOptions = paymentOptions.filter((option) => {
|
|
43
|
+
const { payment_type } = option;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
isInitialTypeIncluded(payment_type) ||
|
|
47
|
+
isPluginMapIncluded(payment_type) ||
|
|
48
|
+
isExtraTypeIncluded(payment_type)
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return { filteredPaymentOptions };
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"semver": "7.5.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react-redux": "7.1.30"
|
|
25
|
+
"@types/react-redux": "7.1.30",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
27
|
+
"@typescript-eslint/parser": "6.7.4",
|
|
28
|
+
"eslint": "^8.14.0",
|
|
29
|
+
"@akinon/eslint-plugin-projectzero": "1.13.0",
|
|
30
|
+
"eslint-config-prettier": "8.5.0"
|
|
26
31
|
}
|
|
27
32
|
}
|
package/plugins.js
CHANGED
package/types/index.ts
CHANGED
|
@@ -173,6 +173,7 @@ export interface Settings {
|
|
|
173
173
|
* If there is a need to exclude certain payment options from the iframe, for instance, due to CORS issues, this option can be utilized by passing the slugs associated with the desired payment options.
|
|
174
174
|
*/
|
|
175
175
|
iframeExcludedPaymentOptions?: string[];
|
|
176
|
+
extraPaymentTypes?: string[];
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
|