npm-pkg-hook 1.8.0 → 1.8.2
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/package.json +1 -1
- package/src/hooks/getCardType/index.js +24 -0
- package/src/hooks/index.js +4 -1
- package/src/hooks/useGetCookies/index.js +27 -0
- package/src/hooks/useGetStoreCookie/index.js +11 -12
- package/src/hooks/{useFreeSubscriptionValidation → useSubscriptionValidation}/index.js +2 -1
- package/src/hooks/useTokenCards/index.js +41 -0
- package/src/utils/index.js +11 -0
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const getCardType = (cardNum) => {
|
|
2
|
+
let payCardType = ''
|
|
3
|
+
|
|
4
|
+
if (cardNum.startsWith('4')) {
|
|
5
|
+
payCardType = 'VISA'
|
|
6
|
+
} else if (cardNum.startsWith('5')) {
|
|
7
|
+
payCardType = 'MASTERCARD'
|
|
8
|
+
} else {
|
|
9
|
+
const regexMap = [
|
|
10
|
+
{ regEx: /^4[0-9]{5}/gi, cardType: 'VISA' },
|
|
11
|
+
{ regEx: /^5[1-5][0-9]{4}/gi, cardType: 'MASTERCARD' },
|
|
12
|
+
{ regEx: /^(5[06-8]\d{4}|6\d{5})/gi, cardType: 'MAESTRO' }
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
for (const { regEx, cardType } of regexMap) {
|
|
16
|
+
if (cardNum.match(regEx)) {
|
|
17
|
+
payCardType = cardType
|
|
18
|
+
break
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return payCardType
|
|
24
|
+
}
|
package/src/hooks/index.js
CHANGED
|
@@ -7,12 +7,15 @@ export * from './useCatWithProduct'
|
|
|
7
7
|
export * from './useManageQueryParams'
|
|
8
8
|
export * from './useDeliveryTime'
|
|
9
9
|
export * from './getTotalHours'
|
|
10
|
-
export * from './
|
|
10
|
+
export * from './useTokenCards'
|
|
11
|
+
export * from './useSubscriptionValidation'
|
|
11
12
|
export * from './convertToMilitaryTime'
|
|
12
13
|
export * from './statusOpenStores'
|
|
13
14
|
export * from './completeSchedules'
|
|
14
15
|
export * from './useLogout/helpers/BroadcastChannel'
|
|
16
|
+
export * from './getCardType'
|
|
15
17
|
export * from './newMessageSubscription'
|
|
18
|
+
export * from './useGetCookies'
|
|
16
19
|
export * from './isTokenExpired'
|
|
17
20
|
export * from './useCreateDeliveryTime'
|
|
18
21
|
export * from './addTenMinutes'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Cookies from 'js-cookie'
|
|
2
|
+
|
|
3
|
+
export const useGetCookies = () => {
|
|
4
|
+
const getCookies = (cookieNames) => {
|
|
5
|
+
try {
|
|
6
|
+
if (!Array.isArray(cookieNames)) {
|
|
7
|
+
throw new Error('Input cookie names should be an array.')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const cookiesData = []
|
|
11
|
+
|
|
12
|
+
for (const cookieName of cookieNames) {
|
|
13
|
+
const cookieValue = Cookies.get(cookieName)
|
|
14
|
+
console.log({ cookieValue })
|
|
15
|
+
if (cookieValue) {
|
|
16
|
+
cookiesData.push({ name: cookieName, value: cookieValue })
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return cookiesData
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Error al traer las cookies:', error)
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { getCookies }
|
|
27
|
+
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react'
|
|
2
|
-
import Cookies from 'js-cookie'
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import Cookies from 'js-cookie'
|
|
3
3
|
|
|
4
4
|
export const useGetStoreCookie = () => {
|
|
5
|
-
const [vpStoreCookie, setVpStoreCookie] = useState(null)
|
|
5
|
+
const [vpStoreCookie, setVpStoreCookie] = useState(null)
|
|
6
6
|
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
const getCookieValue = () => {
|
|
9
|
-
const cookieValue = Cookies.get(process.env.SESSION_NAME)
|
|
10
|
-
console.log('Cookie Value:', cookieValue)
|
|
9
|
+
const cookieValue = Cookies.get(process.env.SESSION_NAME)
|
|
10
|
+
console.log('Cookie Value:', cookieValue)
|
|
11
11
|
|
|
12
12
|
if (cookieValue) {
|
|
13
|
-
setVpStoreCookie(cookieValue)
|
|
13
|
+
setVpStoreCookie(cookieValue)
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
getCookieValue()
|
|
18
|
-
}, [])
|
|
19
|
-
|
|
20
|
-
return vpStoreCookie;
|
|
21
|
-
};
|
|
17
|
+
getCookieValue()
|
|
18
|
+
}, []) // Empty dependency array, so this effect runs once
|
|
22
19
|
|
|
20
|
+
return vpStoreCookie
|
|
21
|
+
}
|
|
@@ -13,7 +13,7 @@ const VALIDATE_SUBSCRIPTION_QUERY = gql`
|
|
|
13
13
|
}
|
|
14
14
|
`
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const useSubscriptionValidation = (idStore) => {
|
|
17
17
|
const { loading, error, data } = useQuery(VALIDATE_SUBSCRIPTION_QUERY, {
|
|
18
18
|
variables: { idStore }
|
|
19
19
|
})
|
|
@@ -21,6 +21,7 @@ export const useFreeSubscriptionValidation = (idStore) => {
|
|
|
21
21
|
const [daysElapsed, setDaysElapsed] = useState(null)
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
+
console.log(data)
|
|
24
25
|
if (data && data.validateFreeSubscription) {
|
|
25
26
|
const { currentPeriodEnd, currentPeriodStart } = data.validateFreeSubscription
|
|
26
27
|
const currentDate = new Date()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useTokenCards = () => {
|
|
4
|
+
const [loading, setLoading] = useState(false)
|
|
5
|
+
const [error, setError] = useState(null)
|
|
6
|
+
const [responseData, setResponseData] = useState(null)
|
|
7
|
+
|
|
8
|
+
const handleTokenCardsSubmit = async (postData) => {
|
|
9
|
+
setLoading(true)
|
|
10
|
+
setError(null)
|
|
11
|
+
try {
|
|
12
|
+
const headers = {
|
|
13
|
+
'Content-Type': 'application/json'
|
|
14
|
+
}
|
|
15
|
+
const url = 'http://localhost:3000/api/v1/wompi/transaction/tokens/cards'
|
|
16
|
+
|
|
17
|
+
const response = await fetch(url, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers,
|
|
20
|
+
body: JSON.stringify(postData)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const responseData = await response.json()
|
|
24
|
+
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(responseData.message || 'Something went wrong')
|
|
27
|
+
}
|
|
28
|
+
setResponseData(responseData)
|
|
29
|
+
return responseData
|
|
30
|
+
} catch (error) {
|
|
31
|
+
setError(error.message)
|
|
32
|
+
return {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
setLoading(false)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { loading, error, responseData, handleTokenCardsSubmit }
|
|
41
|
+
}
|
package/src/utils/index.js
CHANGED
|
@@ -197,3 +197,14 @@ export const SERVICES = Object.freeze({
|
|
|
197
197
|
ADMIN_STORE: 'admin-store',
|
|
198
198
|
MAIN: 'main'
|
|
199
199
|
})
|
|
200
|
+
|
|
201
|
+
export const paymentMethodCards = [
|
|
202
|
+
{
|
|
203
|
+
name: 'Visa',
|
|
204
|
+
icon: 'IconVisa'
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: 'MasterCard',
|
|
208
|
+
icon: 'IconMasterCard'
|
|
209
|
+
}
|
|
210
|
+
]
|