@danielseres9/adobe-commerce-checkout 0.1.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/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/package.json +62 -0
- package/src/app-builder-client.js +115 -0
- package/src/checkout.js +80 -0
- package/src/constants.js +7 -0
- package/src/gql.js +33 -0
- package/src/index.js +24 -0
- package/src/order.js +1 -0
- package/src/transformers.js +38 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Worldpay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Worldpay Adobe Commerce Checkout
|
|
2
|
+
|
|
3
|
+
Worldpay integration package for Adobe Commerce Checkout Drop-ins and OOPE payment methods.
|
|
4
|
+
|
|
5
|
+
This package contains the storefront-side logic required to connect an Adobe Commerce Storefront checkout to a Worldpay App Builder payment endpoint. It is intended for AEM Edge Delivery Services storefronts that use Adobe Commerce Drop-ins.
|
|
6
|
+
|
|
7
|
+
## What It Does
|
|
8
|
+
|
|
9
|
+
- Adds Checkout Drop-in GraphQL fragments for OOPE payment configuration.
|
|
10
|
+
- Preserves `oope_payment_method_config` in the checkout cart model.
|
|
11
|
+
- Detects `Worldpay` and `WorldpayLocal*` payment methods.
|
|
12
|
+
- Places the Adobe Commerce order before starting payment.
|
|
13
|
+
- Calls the OOPE `backend_integration_url`, usually the Worldpay App Builder `create-payment` action.
|
|
14
|
+
- Sends `orderEntityId`, `merchantConfigId`, `returnUrl`, and `paymentMethod`.
|
|
15
|
+
- Redirects the shopper to the Worldpay middleware redirect/HPP page.
|
|
16
|
+
- Displays pending Worldpay orders as `Pending Payment`.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @danielseres9/adobe-commerce-checkout
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For local package development from a sibling checkout:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@danielseres9/adobe-commerce-checkout": "file:../worldpay-adobe-commerce-checkout"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Storefront Wiring
|
|
35
|
+
|
|
36
|
+
### 1. Extend Checkout GraphQL
|
|
37
|
+
|
|
38
|
+
In `build.mjs`:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { overrideGQLOperations } from '@dropins/build-tools/gql-extend.js';
|
|
42
|
+
import { worldpayCheckoutGqlOperations } from '@danielseres9/adobe-commerce-checkout';
|
|
43
|
+
|
|
44
|
+
overrideGQLOperations([
|
|
45
|
+
{
|
|
46
|
+
npm: '@dropins/storefront-checkout',
|
|
47
|
+
operations: worldpayCheckoutGqlOperations,
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Preserve OOPE Config In Checkout Data
|
|
53
|
+
|
|
54
|
+
In the checkout initializer:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { worldpayCheckoutModelTransformer } from '@danielseres9/adobe-commerce-checkout';
|
|
58
|
+
|
|
59
|
+
initialize(checkoutApi, {
|
|
60
|
+
models: {
|
|
61
|
+
CartModel: {
|
|
62
|
+
transformer: worldpayCheckoutModelTransformer,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Handle Worldpay Place Order
|
|
69
|
+
|
|
70
|
+
Inside the checkout block's `handlePlaceOrder` callback:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import * as orderApi from '@dropins/storefront-order/api.js';
|
|
74
|
+
import { events } from '@dropins/tools/event-bus.js';
|
|
75
|
+
import {
|
|
76
|
+
handleWorldpayPlaceOrder,
|
|
77
|
+
isWorldpayPaymentMethod,
|
|
78
|
+
} from '@danielseres9/adobe-commerce-checkout';
|
|
79
|
+
|
|
80
|
+
if (isWorldpayPaymentMethod(code)) {
|
|
81
|
+
await handleWorldpayPlaceOrder({
|
|
82
|
+
cartId,
|
|
83
|
+
code,
|
|
84
|
+
cartData: events.lastPayload('checkout/updated')
|
|
85
|
+
?? events.lastPayload('checkout/initialized'),
|
|
86
|
+
buildOrderUrl: buildOrderDetailsUrl,
|
|
87
|
+
placeOrder: orderApi.placeOrder,
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 4. Transform Worldpay Pending Orders
|
|
94
|
+
|
|
95
|
+
In the order initializer:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { worldpayOrderDataModelTransformer } from '@danielseres9/adobe-commerce-checkout';
|
|
99
|
+
|
|
100
|
+
initialize(orderApi, {
|
|
101
|
+
models: {
|
|
102
|
+
OrderDataModel: {
|
|
103
|
+
transformer: worldpayOrderDataModelTransformer,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## OOPE Requirements
|
|
110
|
+
|
|
111
|
+
The Adobe Commerce OOPE method must expose `oope_payment_method_config.backend_integration_url`. That URL should point to the Worldpay App Builder `create-payment` action and include or otherwise allow resolving a `merchantConfigId`.
|
|
112
|
+
|
|
113
|
+
Example:
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
https://<namespace>.adobeioruntime.net/api/v1/web/adobe_worldpay_access/create-payment?merchantConfigId=<merchant-id>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Runtime Payload
|
|
120
|
+
|
|
121
|
+
The package posts this JSON body to App Builder:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"orderEntityId": 123,
|
|
126
|
+
"merchantConfigId": "merchant-config-id",
|
|
127
|
+
"returnUrl": "https://merchant.example/order-details?orderRef=...",
|
|
128
|
+
"paymentMethod": "Worldpay"
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
App Builder should return:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"redirectUrl": "https://middleware.example/redirect-page/..."
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The browser is then redirected to `redirectUrl`.
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielseres9/adobe-commerce-checkout",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Worldpay integration package for Adobe Commerce Checkout Drop-ins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js",
|
|
9
|
+
"./app-builder-client.js": "./src/app-builder-client.js",
|
|
10
|
+
"./checkout.js": "./src/checkout.js",
|
|
11
|
+
"./constants.js": "./src/constants.js",
|
|
12
|
+
"./gql.js": "./src/gql.js",
|
|
13
|
+
"./order.js": "./src/order.js",
|
|
14
|
+
"./transformers.js": "./src/transformers.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"worldpay",
|
|
30
|
+
"adobe-commerce",
|
|
31
|
+
"aem",
|
|
32
|
+
"edge-delivery-services",
|
|
33
|
+
"checkout",
|
|
34
|
+
"drop-ins",
|
|
35
|
+
"oope"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@dropins/storefront-checkout": ">=3.2.0 <4",
|
|
39
|
+
"@dropins/storefront-order": ">=3.3.0 <4",
|
|
40
|
+
"@dropins/tools": ">=1.8.0 <2"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@dropins/storefront-checkout": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@dropins/storefront-order": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@dropins/tools": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+ssh://git@github.com/danielseres9/worldpay-adobe-commerce-checkout.git"
|
|
57
|
+
},
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/danielseres9/worldpay-adobe-commerce-checkout/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/danielseres9/worldpay-adobe-commerce-checkout#readme"
|
|
62
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { WORLDPAY_PAYMENT_METHOD } from './constants.js';
|
|
2
|
+
|
|
3
|
+
export function getWorldpayMethodConfig(method) {
|
|
4
|
+
return method?.additionalData?.oope_payment_method_config
|
|
5
|
+
?? method?.oope_payment_method_config;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getWorldpayBackendUrl(cartData, paymentMethodCode) {
|
|
9
|
+
const selectedMethod = cartData?.selectedPaymentMethod;
|
|
10
|
+
const availableMethod = cartData?.availablePaymentMethods?.find(
|
|
11
|
+
(method) => method.code === paymentMethodCode,
|
|
12
|
+
);
|
|
13
|
+
const config = getWorldpayMethodConfig(
|
|
14
|
+
selectedMethod?.code === paymentMethodCode
|
|
15
|
+
? selectedMethod
|
|
16
|
+
: availableMethod,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return config?.backend_integration_url;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getMerchantConfigId(appBuilderUrl) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(appBuilderUrl).searchParams.get('merchantConfigId');
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getOrderEntityId(orderData) {
|
|
31
|
+
return orderData?.id
|
|
32
|
+
?? orderData?.entity_id
|
|
33
|
+
?? orderData?.entityId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getDefaultOrigin() {
|
|
37
|
+
return typeof window !== 'undefined' ? window.location?.origin : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getDefaultFetch() {
|
|
41
|
+
return typeof window !== 'undefined' ? window.fetch?.bind(window) : undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getAbsoluteUrl(path, origin = getDefaultOrigin()) {
|
|
45
|
+
if (!origin) return path;
|
|
46
|
+
return new URL(path, origin).toString();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function buildWorldpayPaymentPayload({
|
|
50
|
+
orderData,
|
|
51
|
+
returnUrl,
|
|
52
|
+
appBuilderUrl,
|
|
53
|
+
merchantConfigId = getMerchantConfigId(appBuilderUrl),
|
|
54
|
+
paymentMethod = WORLDPAY_PAYMENT_METHOD,
|
|
55
|
+
}) {
|
|
56
|
+
const orderEntityId = getOrderEntityId(orderData);
|
|
57
|
+
|
|
58
|
+
if (!orderEntityId) {
|
|
59
|
+
throw new Error('Worldpay order entity id missing.');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
orderEntityId,
|
|
64
|
+
...(merchantConfigId ? { merchantConfigId } : {}),
|
|
65
|
+
returnUrl,
|
|
66
|
+
paymentMethod,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function createWorldpayPayment({
|
|
71
|
+
appBuilderUrl,
|
|
72
|
+
orderData,
|
|
73
|
+
returnUrl,
|
|
74
|
+
merchantConfigId,
|
|
75
|
+
paymentMethod = WORLDPAY_PAYMENT_METHOD,
|
|
76
|
+
fetchImpl = getDefaultFetch(),
|
|
77
|
+
}) {
|
|
78
|
+
if (!appBuilderUrl) {
|
|
79
|
+
throw new Error('Worldpay backend integration URL missing.');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof fetchImpl !== 'function') {
|
|
83
|
+
throw new Error('Worldpay fetch implementation missing.');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const response = await fetchImpl(appBuilderUrl, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: {
|
|
89
|
+
'Content-Type': 'application/json',
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify(buildWorldpayPaymentPayload({
|
|
92
|
+
orderData,
|
|
93
|
+
returnUrl,
|
|
94
|
+
appBuilderUrl,
|
|
95
|
+
merchantConfigId,
|
|
96
|
+
paymentMethod,
|
|
97
|
+
})),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error('Worldpay payment creation failed.');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const data = await response.json();
|
|
105
|
+
const redirectUrl = data.redirectUrl ?? data.redirect_url;
|
|
106
|
+
|
|
107
|
+
if (!redirectUrl) {
|
|
108
|
+
throw new Error('Worldpay redirect URL missing.');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
redirectUrl,
|
|
113
|
+
data,
|
|
114
|
+
};
|
|
115
|
+
}
|
package/src/checkout.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { WORLDPAY_PAYMENT_METHOD, isWorldpayPaymentMethod } from './constants.js';
|
|
2
|
+
import {
|
|
3
|
+
createWorldpayPayment,
|
|
4
|
+
getAbsoluteUrl,
|
|
5
|
+
getWorldpayBackendUrl,
|
|
6
|
+
} from './app-builder-client.js';
|
|
7
|
+
|
|
8
|
+
function getDefaultLocation() {
|
|
9
|
+
return typeof window !== 'undefined' ? window.location : undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getDefaultOrigin() {
|
|
13
|
+
return typeof window !== 'undefined' ? window.location?.origin : undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function startWorldpayPayment({
|
|
17
|
+
cartData,
|
|
18
|
+
orderData,
|
|
19
|
+
returnUrl,
|
|
20
|
+
paymentMethodCode = WORLDPAY_PAYMENT_METHOD,
|
|
21
|
+
merchantConfigId,
|
|
22
|
+
fetchImpl,
|
|
23
|
+
locationRef = getDefaultLocation(),
|
|
24
|
+
}) {
|
|
25
|
+
const appBuilderUrl = getWorldpayBackendUrl(cartData, paymentMethodCode);
|
|
26
|
+
const { redirectUrl, data } = await createWorldpayPayment({
|
|
27
|
+
appBuilderUrl,
|
|
28
|
+
orderData,
|
|
29
|
+
returnUrl,
|
|
30
|
+
merchantConfigId,
|
|
31
|
+
paymentMethod: WORLDPAY_PAYMENT_METHOD,
|
|
32
|
+
fetchImpl,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (locationRef) {
|
|
36
|
+
locationRef.href = redirectUrl;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
redirectUrl,
|
|
41
|
+
data,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function handleWorldpayPlaceOrder({
|
|
46
|
+
cartId,
|
|
47
|
+
code,
|
|
48
|
+
cartData,
|
|
49
|
+
buildOrderUrl,
|
|
50
|
+
placeOrder,
|
|
51
|
+
merchantConfigId,
|
|
52
|
+
fetchImpl,
|
|
53
|
+
locationRef = getDefaultLocation(),
|
|
54
|
+
origin = getDefaultOrigin(),
|
|
55
|
+
}) {
|
|
56
|
+
if (!isWorldpayPaymentMethod(code)) return false;
|
|
57
|
+
|
|
58
|
+
if (typeof buildOrderUrl !== 'function') {
|
|
59
|
+
throw new Error('Worldpay order URL builder missing.');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof placeOrder !== 'function') {
|
|
63
|
+
throw new Error('Worldpay place order function missing.');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const orderData = await placeOrder(cartId);
|
|
67
|
+
const returnUrl = getAbsoluteUrl(buildOrderUrl(orderData), origin);
|
|
68
|
+
|
|
69
|
+
await startWorldpayPayment({
|
|
70
|
+
cartData,
|
|
71
|
+
orderData,
|
|
72
|
+
returnUrl,
|
|
73
|
+
paymentMethodCode: code,
|
|
74
|
+
merchantConfigId,
|
|
75
|
+
fetchImpl,
|
|
76
|
+
locationRef,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return true;
|
|
80
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const WORLDPAY_PAYMENT_METHOD = 'Worldpay';
|
|
2
|
+
export const WORLDPAY_LOCAL_PAYMENT_METHOD_PREFIX = 'WorldpayLocal';
|
|
3
|
+
|
|
4
|
+
export function isWorldpayPaymentMethod(code) {
|
|
5
|
+
return code === WORLDPAY_PAYMENT_METHOD
|
|
6
|
+
|| String(code ?? '').startsWith(WORLDPAY_LOCAL_PAYMENT_METHOD_PREFIX);
|
|
7
|
+
}
|
package/src/gql.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const worldpayCheckoutGqlOperations = [
|
|
2
|
+
`
|
|
3
|
+
fragment AVAILABLE_PAYMENT_METHOD_FRAGMENT on AvailablePaymentMethod {
|
|
4
|
+
code
|
|
5
|
+
title
|
|
6
|
+
oope_payment_method_config {
|
|
7
|
+
backend_integration_url
|
|
8
|
+
custom_config {
|
|
9
|
+
... on CustomConfigKeyValue {
|
|
10
|
+
key
|
|
11
|
+
value
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
`
|
|
18
|
+
fragment SELECTED_PAYMENT_METHOD_FRAGMENT on SelectedPaymentMethod {
|
|
19
|
+
code
|
|
20
|
+
title
|
|
21
|
+
purchase_order_number
|
|
22
|
+
oope_payment_method_config {
|
|
23
|
+
backend_integration_url
|
|
24
|
+
custom_config {
|
|
25
|
+
... on CustomConfigKeyValue {
|
|
26
|
+
key
|
|
27
|
+
value
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
];
|
package/src/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export {
|
|
2
|
+
WORLDPAY_LOCAL_PAYMENT_METHOD_PREFIX,
|
|
3
|
+
WORLDPAY_PAYMENT_METHOD,
|
|
4
|
+
isWorldpayPaymentMethod,
|
|
5
|
+
} from './constants.js';
|
|
6
|
+
export { worldpayCheckoutGqlOperations } from './gql.js';
|
|
7
|
+
export {
|
|
8
|
+
transformPaymentMethod,
|
|
9
|
+
worldpayCheckoutModelTransformer,
|
|
10
|
+
worldpayOrderDataModelTransformer,
|
|
11
|
+
} from './transformers.js';
|
|
12
|
+
export {
|
|
13
|
+
buildWorldpayPaymentPayload,
|
|
14
|
+
createWorldpayPayment,
|
|
15
|
+
getAbsoluteUrl,
|
|
16
|
+
getMerchantConfigId,
|
|
17
|
+
getOrderEntityId,
|
|
18
|
+
getWorldpayBackendUrl,
|
|
19
|
+
getWorldpayMethodConfig,
|
|
20
|
+
} from './app-builder-client.js';
|
|
21
|
+
export {
|
|
22
|
+
handleWorldpayPlaceOrder,
|
|
23
|
+
startWorldpayPayment,
|
|
24
|
+
} from './checkout.js';
|
package/src/order.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { worldpayOrderDataModelTransformer } from './transformers.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isWorldpayPaymentMethod } from './constants.js';
|
|
2
|
+
|
|
3
|
+
export function transformPaymentMethod(method) {
|
|
4
|
+
if (!method) return method;
|
|
5
|
+
|
|
6
|
+
const { code, title, ...additionalData } = method;
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
code,
|
|
10
|
+
title,
|
|
11
|
+
additionalData,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function worldpayCheckoutModelTransformer(data) {
|
|
16
|
+
return {
|
|
17
|
+
availablePaymentMethods: data?.available_payment_methods
|
|
18
|
+
?.map(transformPaymentMethod),
|
|
19
|
+
selectedPaymentMethod: transformPaymentMethod(
|
|
20
|
+
data?.selected_payment_method,
|
|
21
|
+
),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function worldpayOrderDataModelTransformer(data) {
|
|
26
|
+
const isWorldpay = data?.payment_methods?.some(
|
|
27
|
+
(method) => isWorldpayPaymentMethod(method?.type),
|
|
28
|
+
);
|
|
29
|
+
const status = String(data?.status ?? '').trim().toLowerCase();
|
|
30
|
+
|
|
31
|
+
if (isWorldpay && status === 'pending') {
|
|
32
|
+
return {
|
|
33
|
+
status: 'Pending Payment',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {};
|
|
38
|
+
}
|