@akinon/pz-tamara-extension 1.126.21 → 1.126.22-v1-rc.19
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/package.json +1 -1
- package/src/pages/TamaraPaymentGateway.tsx +35 -7
- package/src/utils/index.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @akinon/pz-tamara-extension
|
|
2
2
|
|
|
3
|
+
## 1.126.22-v1-rc.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 560e209d: ZERO-4523: send is_premium_customer as null in Tamara risk_assessment
|
|
8
|
+
- 560e209d: ZERO-4523: add risk_assessment to Tamara session payload
|
|
9
|
+
|
|
3
10
|
## 1.126.21
|
|
4
11
|
|
|
5
12
|
## 1.126.20
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import settings from 'settings';
|
|
3
|
+
import { URLS } from '@akinon/next/data/urls';
|
|
3
4
|
import { cookies } from 'next/headers';
|
|
4
5
|
import FormComponent from '../components/FormComponent';
|
|
5
6
|
import {
|
|
@@ -7,7 +8,8 @@ import {
|
|
|
7
8
|
generateHash,
|
|
8
9
|
getRandomString,
|
|
9
10
|
formatDecimal,
|
|
10
|
-
getQuantizeFormat
|
|
11
|
+
getQuantizeFormat,
|
|
12
|
+
formatDateDDMMYYYY
|
|
11
13
|
} from '../utils';
|
|
12
14
|
import { TamaraPaymentGatewayProps } from '../types';
|
|
13
15
|
|
|
@@ -37,10 +39,14 @@ export const TamaraPaymentGateway = async ({
|
|
|
37
39
|
'Accept-Language': language
|
|
38
40
|
};
|
|
39
41
|
|
|
40
|
-
const preOrder = await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const [preOrder, userProfile, orders] = await Promise.all([
|
|
43
|
+
fetchData(
|
|
44
|
+
`${settings.commerceUrl}/orders/checkout/?page=OrderNotePage`,
|
|
45
|
+
requestHeaders
|
|
46
|
+
),
|
|
47
|
+
fetchData(URLS.user.currentUser, requestHeaders),
|
|
48
|
+
fetchData(`${URLS.account.order}?status=550&limit=9999`, requestHeaders)
|
|
49
|
+
]);
|
|
44
50
|
|
|
45
51
|
const salt = getRandomString(10);
|
|
46
52
|
const hash = generateHash(salt, sessionId, hashKey);
|
|
@@ -106,6 +112,15 @@ export const TamaraPaymentGateway = async ({
|
|
|
106
112
|
};
|
|
107
113
|
});
|
|
108
114
|
|
|
115
|
+
const tamaraSlug = preOrder?.pre_order?.payment_option?.slug;
|
|
116
|
+
const tamaraOrders = (orders?.results ?? []).filter(
|
|
117
|
+
(order: any) => order?.payment_option_slug === tamaraSlug
|
|
118
|
+
);
|
|
119
|
+
const tamaraPaidDates = tamaraOrders
|
|
120
|
+
.map((order: any) => order?.created_date)
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.sort();
|
|
123
|
+
|
|
109
124
|
const context = {
|
|
110
125
|
hash,
|
|
111
126
|
salt,
|
|
@@ -133,11 +148,24 @@ export const TamaraPaymentGateway = async ({
|
|
|
133
148
|
line1: preOrder.pre_order.shipping_address.line,
|
|
134
149
|
phone_number: preOrder.pre_order.shipping_address.phone_number,
|
|
135
150
|
region: preOrder.pre_order.shipping_address.township.name
|
|
151
|
+
},
|
|
152
|
+
risk_assessment: {
|
|
153
|
+
is_premium_customer: null,
|
|
154
|
+
account_creation_date: formatDateDDMMYYYY(userProfile?.date_joined),
|
|
155
|
+
total_order_count: tamaraOrders.length,
|
|
156
|
+
date_first_paid: formatDateDDMMYYYY(tamaraPaidDates[0]),
|
|
157
|
+
date_last_paid: formatDateDDMMYYYY(
|
|
158
|
+
tamaraPaidDates[tamaraPaidDates.length - 1]
|
|
159
|
+
)
|
|
136
160
|
}
|
|
137
161
|
};
|
|
138
162
|
|
|
139
|
-
const DefaultContainer = ({ children }) =>
|
|
140
|
-
|
|
163
|
+
const DefaultContainer = ({ children }: { children?: React.ReactNode }) => (
|
|
164
|
+
<>{children}</>
|
|
165
|
+
);
|
|
166
|
+
const RenderContainer: (props: {
|
|
167
|
+
children?: React.ReactNode;
|
|
168
|
+
}) => React.ReactNode =
|
|
141
169
|
renderer?.paymentGateway?.renderContainer || DefaultContainer;
|
|
142
170
|
|
|
143
171
|
return (
|
package/src/utils/index.ts
CHANGED
|
@@ -60,3 +60,14 @@ export const getQuantizeFormat = (priceAsString: string): number => {
|
|
|
60
60
|
|
|
61
61
|
return Math.pow(10, -decimalPlaces);
|
|
62
62
|
};
|
|
63
|
+
|
|
64
|
+
export const formatDateDDMMYYYY = (
|
|
65
|
+
value?: string | null
|
|
66
|
+
): string | null => {
|
|
67
|
+
if (!value) return null;
|
|
68
|
+
const date = new Date(value);
|
|
69
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
70
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
71
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
72
|
+
return `${day}-${month}-${date.getFullYear()}`;
|
|
73
|
+
};
|