Skip to content

Commit

Permalink
Merge branch 'main' into cb-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Dec 9, 2024
2 parents 71d4ee1 + 7c9a858 commit bb4346a
Show file tree
Hide file tree
Showing 45 changed files with 899 additions and 212 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
## [0.105.2](https://github.com/juspay/hyperswitch-web/compare/v0.105.1...v0.105.2) (2024-12-05)


### Bug Fixes

* re render issue of card nickname ([#823](https://github.com/juspay/hyperswitch-web/issues/823)) ([a4691b0](https://github.com/juspay/hyperswitch-web/commit/a4691b09f8dba1fa3ebaa8a56b910206296b899d))

## [0.105.1](https://github.com/juspay/hyperswitch-web/compare/v0.105.0...v0.105.1) (2024-12-05)

# [0.105.0](https://github.com/juspay/hyperswitch-web/compare/v0.104.6...v0.105.0) (2024-12-04)


### Features

* add traditional chinese locale ([#822](https://github.com/juspay/hyperswitch-web/issues/822)) ([2707923](https://github.com/juspay/hyperswitch-web/commit/27079236edef9bdd776753b67a70c474a794dd72))

## [0.104.6](https://github.com/juspay/hyperswitch-web/compare/v0.104.5...v0.104.6) (2024-12-04)

## [0.104.5](https://github.com/juspay/hyperswitch-web/compare/v0.104.4...v0.104.5) (2024-12-03)

## [0.104.4](https://github.com/juspay/hyperswitch-web/compare/v0.104.3...v0.104.4) (2024-12-03)


### Bug Fixes

* show card form by default rendering issue ([#817](https://github.com/juspay/hyperswitch-web/issues/817)) ([00e8562](https://github.com/juspay/hyperswitch-web/commit/00e8562b97c20ed02dc86eaf139ffafb822be075))

## [0.104.3](https://github.com/juspay/hyperswitch-web/compare/v0.104.2...v0.104.3) (2024-12-02)

## [0.104.2](https://github.com/juspay/hyperswitch-web/compare/v0.104.1...v0.104.2) (2024-12-02)

## [0.104.1](https://github.com/juspay/hyperswitch-web/compare/v0.104.0...v0.104.1) (2024-12-02)

# [0.104.0](https://github.com/juspay/hyperswitch-web/compare/v0.103.2...v0.104.0) (2024-11-26)


### Features

* samsung pay added ([#806](https://github.com/juspay/hyperswitch-web/issues/806)) ([01db104](https://github.com/juspay/hyperswitch-web/commit/01db104a2512e99eb38305751a9e9395e0812940))

## [0.103.2](https://github.com/juspay/hyperswitch-web/compare/v0.103.1...v0.103.2) (2024-11-26)

## [0.103.1](https://github.com/juspay/hyperswitch-web/compare/v0.103.0...v0.103.1) (2024-11-25)


Expand Down
1 change: 0 additions & 1 deletion Hyperswitch-React-Demo-App/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"private": true,
"dependencies": {
"@juspay-tech/hyper-js": "^1.6.0",
"@juspay-tech/hyperswitch-node": "^1.0.1",
"@juspay-tech/react-hyper-js": "^1.0.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
Expand Down
43 changes: 18 additions & 25 deletions Hyperswitch-React-Demo-App/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ const fetch = require("node-fetch");
const express = require("express");
const { resolve } = require("path");
const dotenv = require("dotenv");
const hyper = require("@juspay-tech/hyperswitch-node");
dotenv.config({ path: "./.env" });

const app = express();
const PORT = 5252;

const hyperswitch = hyper(process.env.HYPERSWITCH_SECRET_KEY);

function getUrl(envVar, selfHostedValue) {
return process.env[envVar] === selfHostedValue ? "" : process.env[envVar];
}
Expand Down Expand Up @@ -95,7 +92,7 @@ const paymentData = {
country_code: "+91",
},
},
}
};

const profileId = process.env.PROFILE_ID;
if (profileId) {
Expand All @@ -122,29 +119,25 @@ app.get("/create-payment-intent", async (_, res) => {
});

async function createPaymentIntent(request) {
if (SERVER_URL) {
const url =
process.env.HYPERSWITCH_SERVER_URL_FOR_DEMO_APP ||
process.env.HYPERSWITCH_SERVER_URL;
const apiResponse = await fetch(`${url}/payments`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": process.env.HYPERSWITCH_SECRET_KEY,
},
body: JSON.stringify(request),
});
const paymentIntent = await apiResponse.json();
const url =
process.env.HYPERSWITCH_SERVER_URL_FOR_DEMO_APP ||
process.env.HYPERSWITCH_SERVER_URL;
const apiResponse = await fetch(`${url}/payments`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": process.env.HYPERSWITCH_SECRET_KEY,
},
body: JSON.stringify(request),
});
const paymentIntent = await apiResponse.json();

if (paymentIntent.error) {
console.error("Error - ", paymentIntent.error);
throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
}
return paymentIntent;
} else {
return await hyperswitch?.paymentIntents?.create(request);
if (paymentIntent.error) {
console.error("Error - ", paymentIntent.error);
throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
}
return paymentIntent;
}

app.listen(PORT, () => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orca-payment-page",
"version": "0.103.1",
"version": "0.105.2",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let make = () => {
switch fullscreenMode {
| "paymentloader" => <PaymentLoader />
| "plaidSDK" => <PlaidSDKIframe />
| "pazeWallet" => <PazeWallet />
| "pazeWallet" => <PazeWallet logger />
| "fullscreen" =>
<div id="fullscreen">
<FullScreenDivDriver />
Expand Down
12 changes: 6 additions & 6 deletions src/CardPattern.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let cardPatterns = [
{
issuer: "Maestro",
pattern: %re(
"/^(5018|5081|5044|504681|504993|5020|502260|5038|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775|600206|627741)/"
"/^(5018|5081|5044|504681|504993|5020|502260|5038|5893|603845|603123|6304|6759|676[1-3]|6220|504834|504817|504645|504775|600206|627741)/"
),
cvcLength: [3, 4],
length: [12, 13, 14, 15, 16, 17, 18, 19],
Expand All @@ -29,7 +29,7 @@ let cardPatterns = [
{
issuer: "RuPay",
pattern: %re(
"/^(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4]|817290|817368|817378|353800)/"
"/^(508227|508[5-9]|603741|60698[5-9]|60699|607[0-8]|6079[0-7]|60798[0-4]|60800[1-9]|6080[1-9]|608[1-4]|608500|6521[5-9]|652[2-9]|6530|6531[0-4]|817290|817368|817378|353800|82)/"
),
cvcLength: [3],
length: [16],
Expand All @@ -38,23 +38,23 @@ let cardPatterns = [
},
{
issuer: "DinersClub",
pattern: %re("/^(36|38|30[0-5])/"),
pattern: %re("/^(36|38|39|30[0-5])/"),
cvcLength: [3],
maxCVCLength: 3,
length: [14, 15, 16, 17, 18, 19],
pincodeRequired: false,
},
{
issuer: "Discover",
pattern: %re("/^(6011|65|64[4-9]|622)/"),
pattern: %re("/^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)/"),
cvcLength: [3],
length: [16],
maxCVCLength: 3,
pincodeRequired: true,
},
{
issuer: "Mastercard",
pattern: %re("/^5[1-5]/"),
pattern: %re("/^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])/"),
cvcLength: [3],
maxCVCLength: 3,
length: [16],
Expand Down Expand Up @@ -104,7 +104,7 @@ let cardPatterns = [
},
{
issuer: "JCB",
pattern: %re("/^35/"),
pattern: %re("/^35(2[89]|[3-8][0-9])/"),
cvcLength: [3],
maxCVCLength: 3,
length: [16],
Expand Down
1 change: 1 addition & 0 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ let getLocaleObject = async string => {
| NL => Js.import(DutchLocale.localeStrings)
| SV => Js.import(SwedishLocale.localeStrings)
| RU => Js.import(RussianLocale.localeStrings)
| ZH_HANT => Js.import(TraditionalChineseLocale.localeStrings)
}

let awaitedLocaleValue = await promiseLocale
Expand Down
34 changes: 25 additions & 9 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ let formatCardNumber = (val, cardType) => {
let clearValue = val->clearSpaces
let formatedCard = switch cardType {
| AMEX => `${clearValue->slice(0, 4)} ${clearValue->slice(4, 10)} ${clearValue->slice(10, 15)}`
| DINERSCLUB =>
`${clearValue->slice(0, 4)} ${clearValue->slice(4, 10)} ${clearValue->slice(10, 14)}`
| DINERSCLUB
| MASTERCARD
| DISCOVER
| SODEXO
Expand Down Expand Up @@ -362,6 +361,7 @@ let getCardBrandIcon = (cardType, paymentType) => {
| GooglePayElement
| PayPalElement
| ApplePayElement
| SamsungPayElement
| KlarnaElement
| ExpressCheckoutElement
| PaymentMethodsManagement
Expand All @@ -379,7 +379,10 @@ let getExpiryValidity = cardExpiry => {
let valid = if currentYear == year->toInt && month->toInt >= currentMonth && month->toInt <= 12 {
true
} else if (
year->toInt > currentYear && year->toInt < 2075 && month->toInt >= 1 && month->toInt <= 12
year->toInt > currentYear &&
year->toInt < Date.getFullYear(Js.Date.fromFloat(Date.now())) + 100 &&
month->toInt >= 1 &&
month->toInt <= 12
) {
true
} else {
Expand Down Expand Up @@ -453,12 +456,27 @@ let generateFontsLink = (fonts: array<CardThemeType.fonts>) => {
->ignore
}
}

let maxCardLength = cardBrand => {
let obj = getobjFromCardPattern(cardBrand)
Array.reduce(obj.length, 0, (acc, val) => max(acc, val))
}

let isCardLengthValid = (cardBrand, cardNumberLength) => {
let obj = getobjFromCardPattern(cardBrand)
Array.includes(obj.length, cardNumberLength)
}

let cardValid = (cardNumber, cardBrand) => {
let clearValueLength = cardNumber->clearSpaces->String.length
if cardBrand == "" && (GlobalVars.isInteg || GlobalVars.isSandbox) {
Utils.checkIsTestCardWildcard(cardNumber)
} else {
isCardLengthValid(cardBrand, clearValueLength) && calculateLuhn(cardNumber)
}
}

let focusCardValid = (cardNumber, cardBrand) => {
let clearValueLength = cardNumber->clearSpaces->String.length
if cardBrand == "" && (GlobalVars.isInteg || GlobalVars.isSandbox) {
Utils.checkIsTestCardWildcard(cardNumber)
Expand All @@ -467,6 +485,7 @@ let cardValid = (cardNumber, cardBrand) => {
(cardBrand === "Visa" && clearValueLength == 16)) && calculateLuhn(cardNumber)
}
}

let blurRef = (ref: React.ref<Nullable.t<Dom.element>>) => {
ref.current->Nullable.toOption->Option.forEach(input => input->blur)->ignore
}
Expand Down Expand Up @@ -565,10 +584,10 @@ let setCardValid = (cardnumber, setIsCardValid) => {
if cardValid(cardnumber, cardBrand) {
setIsCardValid(_ => Some(true))
} else if (
!cardValid(cardnumber, cardBrand) && cardnumber->String.length == maxCardLength(cardBrand)
!cardValid(cardnumber, cardBrand) && isCardLengthValid(cardBrand, cardnumber->String.length)
) {
setIsCardValid(_ => Some(false))
} else if !(cardnumber->String.length == maxCardLength(cardBrand)) {
} else if !isCardLengthValid(cardBrand, cardnumber->String.length) {
setIsCardValid(_ => None)
}
}
Expand Down Expand Up @@ -677,10 +696,7 @@ let getCardBrandFromStates = (cardBrand, cardScheme, showFields) => {
!showFields ? cardScheme : cardBrand
}

let getCardBrandInvalidError = (
~cardNumber,
~localeString: OrcaPaymentPage.LocaleStringTypes.localeStrings,
) => {
let getCardBrandInvalidError = (~cardNumber, ~localeString: LocaleStringTypes.localeStrings) => {
switch cardNumber->getCardBrand {
| "" => localeString.enterValidCardNumberErrorText
| cardBrandValue => localeString.cardBrandConfiguredErrorText(cardBrandValue)
Expand Down
2 changes: 2 additions & 0 deletions src/Components/SurchargeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type oneClickWallets = {
}
let oneClickWallets = [
{paymentMethodType: "apple_pay", displayName: "ApplePay"},
{paymentMethodType: "samsung_pay", displayName: "SamsungPay"},
{paymentMethodType: "paypal", displayName: "Paypal"},
{paymentMethodType: "google_pay", displayName: "GooglePay"},
{paymentMethodType: "klarna", displayName: "Klarna"},
Expand All @@ -23,6 +24,7 @@ let useSurchargeDetailsForOneClickWallets = (~paymentMethodListValue) => {
oneClickWallets->Array.reduce([], (acc, wallet) => {
let (isWalletBtnRendered, paymentMethod) = switch wallet.paymentMethodType {
| "apple_pay" => (areOneClickWalletsRendered.isApplePay, "wallet")
| "samsung_pay" => (areOneClickWalletsRendered.isSamsungPay, "wallet")
| "paypal" => (areOneClickWalletsRendered.isPaypal, "wallet")
| "google_pay" => (areOneClickWalletsRendered.isGooglePay, "wallet")
| "klarna" => (areOneClickWalletsRendered.isKlarna, "pay_later")
Expand Down
5 changes: 5 additions & 0 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let setCustomPodUri = Recoil.useSetRecoilState(customPodUri)
let setIsGooglePayReady = Recoil.useSetRecoilState(isGooglePayReady)
let setIsApplePayReady = Recoil.useSetRecoilState(isApplePayReady)
let setIsSamsungPayReady = Recoil.useSetRecoilState(isSamsungPayReady)
let (divH, setDivH) = React.useState(_ => 0.0)
let (launchTime, setLaunchTime) = React.useState(_ => 0.0)
let {showCardFormByDefault, paymentMethodOrder} = optionsPayment
Expand Down Expand Up @@ -96,6 +97,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
| GooglePayElement
| PayPalElement
| ApplePayElement
| SamsungPayElement
| KlarnaElement
| PazeElement
| ExpressCheckoutElement
Expand Down Expand Up @@ -385,6 +387,9 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
dict->getJsonObjectFromDict("isReadyToPay")->JSON.Decode.bool->Option.getOr(false)
)
}
if dict->getDictIsSome("isSamsungPayReady") {
setIsSamsungPayReady(_ => dict->getBool("isSamsungPayReady", false))
}
if (
dict->getDictIsSome("customBackendUrl") &&
dict
Expand Down
2 changes: 1 addition & 1 deletion src/LocaleStrings/ChineseLocale.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let localeStrings: LocaleStringTypes.localeStrings = {
locale: `zh`,
localeDirection: `ltr`,
cardNumberLabel: `卡号`,
cardNumberLabel: `卡號`,
inValidCardErrorText: `卡号无效。`,
inCompleteCVCErrorText: `您的卡片安全码不完整。`,
inCompleteExpiryErrorText: `您的卡片到期日期不完整。`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/LocaleStringHelper.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let mapLocalStringToTypeLocale = val => {
| "sv" => SV
| "ru" => RU
| "zh" => ZH
| "zh-Hant" => ZH_HANT
| "en"
| _ =>
EN
Expand Down
2 changes: 1 addition & 1 deletion src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type locale =
EN | HE | FR | EN_GB | AR | JA | DE | FR_BE | ES | CA | PT | IT | PL | NL | SV | RU | ZH
EN | HE | FR | EN_GB | AR | JA | DE | FR_BE | ES | CA | PT | IT | PL | NL | SV | RU | ZH | ZH_HANT

type localeStrings = {
locale: string,
Expand Down
Loading

0 comments on commit bb4346a

Please sign in to comment.