@akinon/pz-flow-payment 1.92.0-rc.7
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/CHANGELOG.md +7 -0
- package/README.md +59 -0
- package/package.json +9 -0
- package/src/index.tsx +3 -0
- package/src/views/index.tsx +125 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# pz-flow-payment
|
|
2
|
+
|
|
3
|
+
Checkout.com Flow Payment integration for Project Zero Next.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can use the following command to install the `pz-flow-payment` plugin in your Project Zero Next application:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @akinon/projectzero@latest --plugins
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## PaymentOptionViews Integration
|
|
14
|
+
|
|
15
|
+
The Flow Payment plugin is designed to work seamlessly with the `PaymentOptionViews` array in your checkout step implementation. By default, you do not need to call the `FlowPayment` component directly. Flow Payment will be rendered automatically when the user selects the corresponding payment option in the checkout flow.
|
|
16
|
+
|
|
17
|
+
To enable Flow Payment as a selectable payment option, add an entry to the `PaymentOptionViews` array, typically in your `src/views/checkout/steps/payment/index.tsx` file:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import FlowPayment from '@akinon/pz-flow-payment/src/views';
|
|
21
|
+
|
|
22
|
+
export const PaymentOptionViews = [
|
|
23
|
+
// ...other payment options
|
|
24
|
+
{
|
|
25
|
+
slug: 'flow',
|
|
26
|
+
view: FlowPayment
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This allows the checkout step to dynamically render the Flow Payment component when the user selects the corresponding payment option. Make sure the `slug` matches the payment option's identifier used in your backend or payment configuration.
|
|
32
|
+
|
|
33
|
+
## Customizations
|
|
34
|
+
|
|
35
|
+
If you want to customize the Flow Payment integration (for example, to change the environment, locale, translations, appearance, or component options), you will need to call the `FlowPayment` component yourself and provide the desired options as props.
|
|
36
|
+
|
|
37
|
+
Example usage:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import FlowPayment from '@akinon/pz-flow-payment/src/views';
|
|
41
|
+
|
|
42
|
+
<FlowPayment
|
|
43
|
+
options={{
|
|
44
|
+
environment: 'sandbox', // or 'production'
|
|
45
|
+
locale: 'en',
|
|
46
|
+
translations: {
|
|
47
|
+
// Custom translations here
|
|
48
|
+
},
|
|
49
|
+
appearance: {
|
|
50
|
+
// Design tokens for appearance customization
|
|
51
|
+
},
|
|
52
|
+
componentOptions: {
|
|
53
|
+
// Component-specific options
|
|
54
|
+
}
|
|
55
|
+
}}
|
|
56
|
+
/>;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See the source code and [Checkout.com documentation](https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website/customize-your-flow-integration) for all available configuration options.
|
package/package.json
ADDED
package/src/index.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { checkoutApi } from '@akinon/next/data/client/checkout';
|
|
2
|
+
import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
|
|
3
|
+
import {
|
|
4
|
+
ComponentOptions,
|
|
5
|
+
CustomTranslations,
|
|
6
|
+
loadCheckoutWebComponents,
|
|
7
|
+
PartialDesignTokens,
|
|
8
|
+
PaymentSessionResponse
|
|
9
|
+
} from '@checkout.com/checkout-web-components';
|
|
10
|
+
import { RootState } from '@theme/redux/store';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
|
|
13
|
+
export default function FlowPayment({
|
|
14
|
+
options
|
|
15
|
+
}: {
|
|
16
|
+
options?: {
|
|
17
|
+
/**
|
|
18
|
+
* Environment to use for the payment components.
|
|
19
|
+
* Defaults to 'production'.
|
|
20
|
+
* If you want to test the payment components, you can set this to 'sandbox'.
|
|
21
|
+
*/
|
|
22
|
+
environment?: 'sandbox' | 'production';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The locale to use for the payment components.
|
|
26
|
+
* Defaults to 'en'.
|
|
27
|
+
*
|
|
28
|
+
* See the list of supported locales here:
|
|
29
|
+
* https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website/add-localization-to-your-flow-integration#Supported_languages
|
|
30
|
+
*/
|
|
31
|
+
locale?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The translations to use for the payment components.
|
|
35
|
+
* See the documentation for more details:
|
|
36
|
+
* https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website/add-localization-to-your-flow-integration#Translations
|
|
37
|
+
*/
|
|
38
|
+
translations?: CustomTranslations;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The appearance options for the payment components.
|
|
42
|
+
* See the documentation for more details:
|
|
43
|
+
* https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website/customize-your-flow-integration
|
|
44
|
+
*/
|
|
45
|
+
appearance?: PartialDesignTokens;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The component options for the payment components.
|
|
49
|
+
* See the documentation for more details:
|
|
50
|
+
* https://www.checkout.com/docs/payments/accept-payments/accept-a-payment-on-your-website/customize-your-flow-integration#Component_options
|
|
51
|
+
*/
|
|
52
|
+
componentOptions?: ComponentOptions;
|
|
53
|
+
};
|
|
54
|
+
}) {
|
|
55
|
+
const { preOrder, walletPaymentData } = useAppSelector(
|
|
56
|
+
(state: RootState) => state.checkout
|
|
57
|
+
);
|
|
58
|
+
const dispatch = useAppDispatch();
|
|
59
|
+
|
|
60
|
+
const initWalletSelection = async () => {
|
|
61
|
+
const walletSelectionPageResponse = await dispatch(
|
|
62
|
+
checkoutApi.endpoints.setWalletSelectionPage.initiate({
|
|
63
|
+
payment_option: preOrder.payment_option?.pk
|
|
64
|
+
})
|
|
65
|
+
).unwrap();
|
|
66
|
+
|
|
67
|
+
const walletPaymentPageContext =
|
|
68
|
+
walletSelectionPageResponse.context_list.find(
|
|
69
|
+
(c) => c.page_name === 'WalletPaymentPage'
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!walletPaymentPageContext) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
dispatch(checkoutApi.endpoints.setWalletPaymentPage.initiate({}));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const initFlowPaymentWebComponents = async ({
|
|
80
|
+
publicKey
|
|
81
|
+
}: {
|
|
82
|
+
publicKey: string;
|
|
83
|
+
}) => {
|
|
84
|
+
const checkout = await loadCheckoutWebComponents({
|
|
85
|
+
publicKey,
|
|
86
|
+
environment: options?.environment || 'production',
|
|
87
|
+
locale: options?.locale || 'en',
|
|
88
|
+
translations: options?.translations,
|
|
89
|
+
paymentSession: preOrder.context_extras as PaymentSessionResponse,
|
|
90
|
+
appearance: options?.appearance,
|
|
91
|
+
componentOptions: options?.componentOptions
|
|
92
|
+
? { flow: options.componentOptions }
|
|
93
|
+
: undefined
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const flowComponent = checkout.create('flow');
|
|
97
|
+
|
|
98
|
+
flowComponent.mount(document.getElementById('flow-container')!);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
initWalletSelection();
|
|
103
|
+
}, []);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (
|
|
107
|
+
!preOrder.wallet_method ||
|
|
108
|
+
!preOrder.token ||
|
|
109
|
+
!walletPaymentData?.data?.public_key ||
|
|
110
|
+
preOrder.wallet_method !== 'checkout_flow'
|
|
111
|
+
) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
initFlowPaymentWebComponents({
|
|
116
|
+
publicKey: walletPaymentData.data.public_key
|
|
117
|
+
});
|
|
118
|
+
}, [
|
|
119
|
+
preOrder.wallet_method,
|
|
120
|
+
preOrder.token,
|
|
121
|
+
walletPaymentData?.data?.public_key
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
return <div id="flow-container" className="flow-payment-container"></div>;
|
|
125
|
+
}
|