Skip to content

Commit

Permalink
Merge branch 'main' into 204-divide-the-disablesavecards-props-into-t…
Browse files Browse the repository at this point in the history
…wo-props-for-api-and-checkbox-different
  • Loading branch information
Pritish Budhiraja authored Mar 8, 2024
2 parents c330f18 + ff22896 commit c76bdfe
Show file tree
Hide file tree
Showing 12 changed files with 532 additions and 579 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [0.27.5](https://github.com/juspay/hyperswitch-web/compare/v0.27.4...v0.27.5) (2024-03-08)

## [0.27.4](https://github.com/juspay/hyperswitch-web/compare/v0.27.3...v0.27.4) (2024-03-08)


Expand Down
5 changes: 3 additions & 2 deletions bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": 4,
"mode": "classic"
},
"bsc-flags": ["-bs-super-errors"],
"bsc-flags": ["-bs-super-errors", "-open RescriptCore"],
"sources": {
"dir": "src",
"subdirs": true
Expand All @@ -21,6 +21,7 @@
"@rescript/react",
"bs-fetch",
"@ryyppy/rescript-promise",
"rescript-webapi"
"rescript-webapi",
"@rescript/core"
]
}
965 changes: 462 additions & 503 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "orca-payment-page",
"version": "0.27.4",
"version": "0.27.5",
"main": "index.js",
"private": true,
"dependencies": {
"@aws-sdk/client-cloudfront": "^3.414.0",
"@aws-sdk/client-s3": "^3.417.0",
"@kount/kount-web-client-sdk": "^1.1.6",
"@rescript/core": "^0.7.0",
"@rescript/react": "^0.11.0",
"@ryyppy/rescript-promise": "^2.1.0",
"@sentry/react": "^7.64.0",
Expand Down
59 changes: 28 additions & 31 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let getCurrentMonthAndYear = (dateTimeIsoString: string) => {
let tempTimeDateString = dateTimeIsoString->Js.String2.replace("Z", "")
let tempTimeDate = tempTimeDateString->Js.String2.split("T")

let date = tempTimeDate[0]
let date = tempTimeDate[0]->Option.getOr("")
let dateComponents = date->Js.String2.split("-")

let currentMonth = dateComponents->Belt.Array.get(1)->Belt.Option.getWithDefault("")
Expand Down Expand Up @@ -225,24 +225,24 @@ let getCardBrand = cardNumber => {
try {
let card = cardNumber->Js.String2.replaceByRe(%re("/[^\d]/g"), "")
let rupayRanges = [
[508227, 508227],
[508500, 508999],
[603741, 603741],
[606985, 607384],
[607385, 607484],
[607485, 607984],
[608001, 608100],
[608101, 608200],
[608201, 608300],
[608301, 608350],
[608351, 608500],
[652150, 652849],
[652850, 653049],
[653050, 653149],
[817290, 817290],
(508227, 508227),
(508500, 508999),
(603741, 603741),
(606985, 607384),
(607385, 607484),
(607485, 607984),
(608001, 608100),
(608101, 608200),
(608201, 608300),
(608301, 608350),
(608351, 608500),
(652150, 652849),
(652850, 653049),
(653050, 653149),
(817290, 817290),
]

let masterCardRanges = [[222100, 272099], [510000, 559999]]
let masterCardRanges = [(222100, 272099), (510000, 559999)]

let doesFallInRange = (cardRanges, isin) => {
let intIsin =
Expand All @@ -252,14 +252,10 @@ let getCardBrand = cardNumber => {
->Belt.Int.fromString
->Belt.Option.getWithDefault(0)

let range = cardRanges->Js.Array2.mapi((_, i) => {
let min = cardRanges[i][0]
let max = cardRanges[i][1]
if intIsin >= min && intIsin <= max {
true
} else {
false
}
let range = cardRanges->Js.Array2.map(cardRange => {
let (min, max) = cardRange

intIsin >= min && intIsin <= max
})
range->Js.Array2.includes(true)
}
Expand Down Expand Up @@ -301,12 +297,13 @@ let calculateLuhn = value => {
->Js.Array2.map(item => {
let val = item->toInt
let double = val * 2
if double > 9 {
let str = double->Belt.Int.toString
let arr = str->Js.String2.split("")
(arr[0]->toInt + arr[1]->toInt)->Belt.Int.toString
} else {
double->Belt.Int.toString
let str = double->Belt.Int.toString
let arr = str->Js.String2.split("")

switch (arr[0], arr[1]) {
| (Some(first), Some(second)) if double > 9 =>
(first->toInt + second->toInt)->Belt.Int.toString
| _ => str
}
})

Expand Down
7 changes: 4 additions & 3 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ let make = (
}, [list])

let paymentExperience = React.useMemo1(() => {
applePayPaymentMethodType.payment_experience->Js.Array2.length == 0
? PaymentMethodsRecord.RedirectToURL
: applePayPaymentMethodType.payment_experience[0].payment_experience_type
switch applePayPaymentMethodType.payment_experience[0] {
| Some(paymentExperience) => paymentExperience.payment_experience_type
| None => PaymentMethodsRecord.RedirectToURL
}
}, [applePayPaymentMethodType])

let isInvokeSDKFlow = React.useMemo1(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ let make = (
}

let isWallet = walletOptions->Js.Array2.includes("google_pay")
let paymentExperience =
googlePayPaymentMethodType.payment_experience->Js.Array2.length == 0
? PaymentMethodsRecord.RedirectToURL
: googlePayPaymentMethodType.payment_experience[0].payment_experience_type
let paymentExperience = switch googlePayPaymentMethodType.payment_experience[0] {
| Some(paymentExperience) => paymentExperience.payment_experience_type
| None => PaymentMethodsRecord.RedirectToURL
}

let isInvokeSDKFlow = React.useMemo1(() => {
(isGooglePaySDKFlow || isGooglePayThirdPartyFlow) &&
Expand Down
3 changes: 1 addition & 2 deletions src/Types/ThemeImporter.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ type themeDataModule = {
default: CardThemeType.themeClass,
defaultRules: CardThemeType.themeClass => Js.Json.t,
}
open Promise

@val
external importTheme: string => t<themeDataModule> = "import"
external importTheme: string => Promise.t<themeDataModule> = "import"
13 changes: 3 additions & 10 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ let closePaymentLoaderIfAny = () =>

let retrievePaymentIntent = (clientSecret, headers, ~optLogger, ~switchToCustomPod) => {
open Promise
let paymentIntentID =
Js.String2.split(clientSecret, "_secret_")->Belt.Array.get(0)->Belt.Option.getWithDefault("")
let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0]->Option.getOr("")
let endpoint = ApiEndpoint.getApiEndPoint()
let uri = `${endpoint}/payments/${paymentIntentID}?client_secret=${clientSecret}`

Expand Down Expand Up @@ -507,10 +506,7 @@ let usePaymentSync = (optLogger: option<OrcaLogger.loggerMake>, paymentType: pay
(~handleUserError=false, ~confirmParam: ConfirmType.confirmParams, ~iframeId="", ()) => {
switch keys.clientSecret {
| Some(clientSecret) =>
let paymentIntentID =
Js.String2.split(clientSecret, "_secret_")
->Belt.Array.get(0)
->Belt.Option.getWithDefault("")
let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0]->Option.getOr("")
let headers = [("Content-Type", "application/json"), ("api-key", confirmParam.publishableKey)]
let endpoint = ApiEndpoint.getApiEndPoint(~publishableKey=confirmParam.publishableKey, ())
let uri = `${endpoint}/payments/${paymentIntentID}?force_sync=true&client_secret=${clientSecret}`
Expand Down Expand Up @@ -596,10 +592,7 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
) => {
switch keys.clientSecret {
| Some(clientSecret) =>
let paymentIntentID =
Js.String2.split(clientSecret, "_secret_")
->Belt.Array.get(0)
->Belt.Option.getWithDefault("")
let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0]->Option.getOr("")
let headers = [("Content-Type", "application/json"), ("api-key", confirmParam.publishableKey)]
let returnUrlArr = [("return_url", confirmParam.return_url->Js.Json.string)]
let manual_retry = isManualRetryEnabled
Expand Down
12 changes: 6 additions & 6 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,15 @@ let validatePhoneNumber = (countryCode, number) => {
->Belt.Option.flatMap(Js.Json.decodeString)
->Belt.Option.getWithDefault("") == countryCode
})
if filteredArr->Js.Array2.length > 0 {
let obj = filteredArr[0]
switch filteredArr[0] {
| Some(obj) =>
let regex =
obj
->Js.Dict.get("validation_regex")
->Belt.Option.flatMap(Js.Json.decodeString)
->Belt.Option.getWithDefault("")
Js.Re.test_(regex->Js.Re.fromString, number)
} else {
false
| None => false
}
}

Expand Down Expand Up @@ -623,11 +622,12 @@ let validateRountingNumber = str => {
if str->Js.String2.length != 9 {
false
} else {
let weights = [3, 7, 1, 3, 7, 1, 3, 7, 1]
let firstWeight = 3
let weights = [firstWeight, 7, 1, 3, 7, 1, 3, 7, 1]
let sum =
str
->Js.String2.split("")
->Js.Array2.mapi((item, i) => item->toInt * weights[i])
->Js.Array2.mapi((item, i) => item->toInt * weights[i]->Option.getOr(firstWeight))
->Js.Array2.reduce((acc, val) => {
acc + val
}, 0)
Expand Down
2 changes: 1 addition & 1 deletion src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ let make = (publishableKey, options: option<Js.Json.t>, analyticsInfo: option<Js
"api-key": publishableKey,
}
let endpoint = ApiEndpoint.getApiEndPoint(~publishableKey, ())
let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0]
let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0]->Option.getOr("")
let retrievePaymentUrl = `${endpoint}/payments/${paymentIntentID}?client_secret=${clientSecret}`
open Promise
logApi(
Expand Down
32 changes: 16 additions & 16 deletions src/orca-loader/OrcaUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,26 @@ let rec flatten = (obj, addIndicatorForObject) => {
}

let rec setNested = (dict, keys, value) => {
if keys->Js.Array.length === 0 {
()
} else if keys->Js.Array.length === 1 {
Js.Dict.set(dict, keys[0], value)
} else {
let key = keys[0]
let subDict = switch Js.Dict.get(dict, key) {
| Some(json) =>
switch json->Js.Json.decodeObject {
| Some(obj) => obj
| None => dict
}
| None => {
switch keys[0] {
| Some(firstKey) =>
if keys->Js.Array.length === 1 {
Js.Dict.set(dict, firstKey, value)
} else {
let subDict = switch Js.Dict.get(dict, firstKey) {
| Some(json) =>
switch json->Js.Json.decodeObject {
| Some(obj) => obj
| None => dict
}
| None =>
let subDict = Js.Dict.empty()
Js.Dict.set(dict, key, subDict->Js.Json.object_)
dict->Dict.set(firstKey, subDict->Js.Json.object_)
subDict
}
let remainingKeys = keys->Js.Array2.sliceFrom(1)
setNested(subDict, remainingKeys, value)
}
let remainingKeys = keys->Js.Array2.sliceFrom(1)
setNested(subDict, remainingKeys, value)
| None => ()
}
}

Expand Down

0 comments on commit c76bdfe

Please sign in to comment.