Skip to content

Commit

Permalink
Merge branch 'main' into fix/required-warning-improv
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Jun 25, 2024
2 parents 22d3ca0 + a4b653b commit caba634
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 70 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [0.70.4](https://github.com/juspay/hyperswitch-web/compare/v0.70.3...v0.70.4) (2024-06-25)


### Bug Fixes

* handle requires_customer_action and processing status for pix pa… ([#456](https://github.com/juspay/hyperswitch-web/issues/456)) ([a680e71](https://github.com/juspay/hyperswitch-web/commit/a680e71a73a31eef89d66fd1d35666da53294a51))

## [0.70.3](https://github.com/juspay/hyperswitch-web/compare/v0.70.2...v0.70.3) (2024-06-24)


### Bug Fixes

* fixed Saved Methods ApplePay and GooglePay Handler ([#455](https://github.com/juspay/hyperswitch-web/issues/455)) ([bce8bea](https://github.com/juspay/hyperswitch-web/commit/bce8bea6045acbae2df1016b93623709715a8277))

## [0.70.2](https://github.com/juspay/hyperswitch-web/compare/v0.70.1...v0.70.2) (2024-06-24)


### Bug Fixes

* package update ([0d01ff2](https://github.com/juspay/hyperswitch-web/commit/0d01ff290e0d22e17bf294d939d500c6c9a927a5))

# [0.69.0](https://github.com/juspay/hyperswitch-web/compare/v0.68.0...v0.69.0) (2024-06-20)


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.69.0",
"version": "0.70.4",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
99 changes: 44 additions & 55 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ let make = (
let dict = sessions->Utils.getDictFromJson
let sessionObj = React.useMemo(() => SessionsType.itemToObjMapper(dict, Others), [dict])

let isApplePayReady = Recoil.useRecoilValueFromAtom(RecoilAtoms.isApplePayReady)
let isGPayReady = Recoil.useRecoilValueFromAtom(RecoilAtoms.isGooglePayReady)
let gPayToken = SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Gpay)

let applePaySessionObj = SessionsType.itemToObjMapper(dict, ApplePayObject)
let applePayToken = SessionsType.getPaymentSessionObj(applePaySessionObj.sessionsToken, ApplePay)

let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Card)
let savedCardlength = savedMethods->Array.length
Expand All @@ -59,13 +61,6 @@ let make = (

let bottomElement = {
savedMethods
->Array.filter(savedMethod => {
switch savedMethod.paymentMethodType {
| Some("apple_pay") => isApplePayReady
| Some("google_pay") => isGPayReady
| _ => true
}
})
->Array.mapWithIndex((obj, i) => {
let brandIcon = switch obj.paymentMethod {
| "wallet" => getWalletBrandIcon(obj)
Expand Down Expand Up @@ -121,9 +116,9 @@ let make = (

useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)

GooglePayHelpers.useHandleGooglePayResponse(~connectors=[], ~intent)
GooglePayHelpers.useHandleGooglePayResponse(~connectors=[], ~intent, ~isSavedMethodsFlow=true)

ApplePayHelpers.useHandleApplePayResponse(~connectors=[], ~intent)
ApplePayHelpers.useHandleApplePayResponse(~connectors=[], ~intent, ~isSavedMethodsFlow=true)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
Expand Down Expand Up @@ -162,52 +157,44 @@ let make = (
confirm.confirmTimestamp >= confirm.readyTimestamp
) {
switch customerMethod.paymentMethodType {
| Some("google_pay") => {
let gPayToken = SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Gpay)
switch gPayToken {
| OtherTokenOptional(optToken) =>
GooglePayHelpers.handleGooglePayClicked(
~sessionObj=optToken,
~componentName,
~iframeId,
~readOnly,
)
| _ =>
// TODO - To be replaced with proper error message
intent(
~bodyArr=savedPaymentMethodBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)
}
| Some("google_pay") =>
switch gPayToken {
| OtherTokenOptional(optToken) =>
GooglePayHelpers.handleGooglePayClicked(
~sessionObj=optToken,
~componentName,
~iframeId,
~readOnly,
)
| _ =>
// TODO - To be replaced with proper error message
intent(
~bodyArr=savedPaymentMethodBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)
}
| Some("apple_pay") => {
let applePaySessionObj = SessionsType.itemToObjMapper(dict, ApplePayObject)
let applePayToken = SessionsType.getPaymentSessionObj(
applePaySessionObj.sessionsToken,
ApplePay,
| Some("apple_pay") =>
switch applePayToken {
| ApplePayTokenOptional(optToken) =>
ApplePayHelpers.handleApplePayButtonClicked(~sessionObj=optToken, ~componentName)
| _ =>
// TODO - To be replaced with proper error message
intent(
~bodyArr=savedPaymentMethodBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)
switch applePayToken {
| ApplePayTokenOptional(optToken) =>
ApplePayHelpers.handleApplePayButtonClicked(~sessionObj=optToken, ~componentName)
| _ =>
// TODO - To be replaced with proper error message
intent(
~bodyArr=savedPaymentMethodBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)
}
}
| _ =>
intent(
Expand Down Expand Up @@ -244,6 +231,8 @@ let make = (
complete,
customerMethod,
isCustomerAcceptanceRequired,
applePayToken,
gPayToken,
))
useSubmitPaymentData(submitCallback)

Expand Down
26 changes: 23 additions & 3 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
let (walletOptions, setWalletOptions) = React.useState(_ => [])
let {sdkHandleConfirmPayment} = Recoil.useRecoilValueFromAtom(optionAtom)

let isApplePayReady = Recoil.useRecoilValueFromAtom(RecoilAtoms.isApplePayReady)
let isGPayReady = Recoil.useRecoilValueFromAtom(RecoilAtoms.isGooglePayReady)

let (paymentMethodListValue, setPaymentMethodListValue) = Recoil.useRecoilState(
PaymentUtils.paymentMethodListValue,
)
Expand Down Expand Up @@ -72,7 +75,16 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
}
}

let finalSavedPaymentMethods = savedPaymentMethods->Array.copy
let finalSavedPaymentMethods =
savedPaymentMethods
->Array.copy
->Array.filter(savedMethod => {
switch savedMethod.paymentMethodType {
| Some("apple_pay") => isApplePayReady
| Some("google_pay") => isGPayReady
| _ => true
}
})
finalSavedPaymentMethods->Array.sort(sortSavedPaymentMethods)

let paymentOrder = paymentMethodOrder->getOptionalArr->removeDuplicate
Expand All @@ -98,7 +110,13 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
}

None
}, (customerPaymentMethods, displaySavedPaymentMethods, optionAtomValue))
}, (
customerPaymentMethods,
displaySavedPaymentMethods,
optionAtomValue,
isApplePayReady,
isGPayReady,
))

React.useEffect(() => {
let defaultSelectedPaymentMethod = optionAtomValue.displayDefaultSavedPaymentIcon
Expand Down Expand Up @@ -344,7 +362,9 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
</div>
</RenderIf>
<RenderIf condition={!showFields && displaySavedPaymentMethods}>
<SavedMethods paymentToken setPaymentToken savedMethods loadSavedCards cvcProps paymentType sessions />
<SavedMethods
paymentToken setPaymentToken savedMethods loadSavedCards cvcProps paymentType sessions
/>
</RenderIf>
<RenderIf
condition={(paymentOptions->Array.length > 0 || walletOptions->Array.length > 0) &&
Expand Down
2 changes: 0 additions & 2 deletions src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti

let areOneClickWalletsRendered = Recoil.useSetRecoilState(RecoilAtoms.areOneClickWalletsRendered)

let isGuestCustomer = UtilityHooks.useIsGuestCustomer()

let googlePayPaymentMethodType = switch PaymentMethodsRecord.getPaymentMethodTypeFromList(
~paymentMethodListValue,
~paymentMethod="wallet",
Expand Down
4 changes: 3 additions & 1 deletion src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ let make = () => {
let dict = json->JSON.Decode.object->Option.getOr(Dict.make())
let status = dict->getString("status", "")

if status === "succeeded" {
if (
status === "succeeded" || status === "requires_customer_action" || status === "processing"
) {
postSubmitResponse(~jsonData=json, ~url=return_url)
} else if status === "failed" {
postFailedSubmitResponse(
Expand Down
4 changes: 4 additions & 0 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ let useHandleApplePayResponse = (
~setApplePayClicked=_ => (),
~syncPayment=() => (),
~isInvokeSDKFlow=true,
~isSavedMethodsFlow=false,
) => {
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
Expand Down Expand Up @@ -191,6 +192,9 @@ let useHandleApplePayResponse = (
)
} else if dict->Dict.get("showApplePayButton")->Option.isSome {
setApplePayClicked(_ => false)
if isSavedMethodsFlow {
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong")
}
} else if dict->Dict.get("applePaySyncPayment")->Option.isSome {
syncPayment()
}
Expand Down
5 changes: 4 additions & 1 deletion src/Utilities/GooglePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let processPayment = (
)
}

let useHandleGooglePayResponse = (~connectors, ~intent) => {
let useHandleGooglePayResponse = (~connectors, ~intent, ~isSavedMethodsFlow=false) => {
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let {publishableKey} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)

Expand Down Expand Up @@ -123,6 +123,9 @@ let useHandleGooglePayResponse = (~connectors, ~intent) => {
}
if dict->Dict.get("gpayError")->Option.isSome {
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
if isSavedMethodsFlow {
postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong")
}
}
}
Window.addEventListener("message", handle)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ let rec intentCall = (
| (Applepay, false)
| (Paypal, false) =>
if !isPaymentSession {
closePaymentLoaderIfAny()
postSubmitResponse(~jsonData=data, ~url=url.href)
} else if confirmParam.redirect === Some("always") {
handleOpenUrl(url.href)
Expand Down Expand Up @@ -1560,4 +1561,3 @@ let paymentIntentForPaymentSession = (
(),
)
}

4 changes: 3 additions & 1 deletion src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ let getHeaders = (~uri=?, ~token=?, ~headers=Dict.make(), ()) => {
("Content-Type", "application/json"),
("X-Client-Version", Window.version),
("X-Payment-Confirm-Source", "sdk"),
("X-Browser-Name", OrcaLogger.arrayOfNameAndVersion->Array.get(0)->Option.getOr("Others")),
("X-Browser-Version", OrcaLogger.arrayOfNameAndVersion->Array.get(1)->Option.getOr("0")),
("X-Client-Platform", "web"),
]->Dict.fromArray

switch (token, uri) {
Expand Down Expand Up @@ -1327,4 +1330,3 @@ let handleFailureResponse = (~message, ~errorType) =>
]->getJsonFromArrayOfJson,
),
]->getJsonFromArrayOfJson

16 changes: 13 additions & 3 deletions src/orca-loader/PaymentSessionMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ let getCustomerSavedPaymentMethods = (

PaymentUtils.getStateJson()
->then(stateJson => {
logger.setLogInfo(~value="States Loaded", ~eventName=APPLE_PAY_FLOW, ~paymentMethod="APPLE_PAY", ())
logger.setLogInfo(
~value="States Loaded",
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
(),
)
stateJson->completeApplePayPayment
})
->catch(err => {
Expand Down Expand Up @@ -226,7 +231,12 @@ let getCustomerSavedPaymentMethods = (
PaymentUtils.getStateJson()
->then(
stateJson => {
logger.setLogInfo(~value="States Loaded", ~eventName=GOOGLE_PAY_FLOW, ~paymentMethod="GOOGLE_PAY", ())
logger.setLogInfo(
~value="States Loaded",
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
(),
)
stateJson->completeGooglePayPayment
},
)
Expand Down Expand Up @@ -423,7 +433,7 @@ let getCustomerSavedPaymentMethods = (
->Identity.anyTypeToJson
->resolve
})
->catch(err => {
->catch(_ => {
updateCustomerPaymentMethodsRef(~isFilterApplePay=true, ~isFilterGooglePay=true)

{
Expand Down

0 comments on commit caba634

Please sign in to comment.