Skip to content

Commit

Permalink
Merge branch 'format-exception' of github.com:juspay/hyperswitch-web …
Browse files Browse the repository at this point in the history
…into format-exception
  • Loading branch information
PritishBudhiraja committed Nov 4, 2024
2 parents be39c17 + b6aae62 commit 12c0bd8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 112 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [0.98.4](https://github.com/juspay/hyperswitch-web/compare/v0.98.3...v0.98.4) (2024-10-30)


### Bug Fixes

* Google pay log issue fix ([#762](https://github.com/juspay/hyperswitch-web/issues/762)) ([df629e9](https://github.com/juspay/hyperswitch-web/commit/df629e9d053f6e2fd443c833a9e343b3cf841f90))

## [0.98.3](https://github.com/juspay/hyperswitch-web/compare/v0.98.2...v0.98.3) (2024-10-30)


### Bug Fixes

* Gpay unified checkout fix ([#761](https://github.com/juspay/hyperswitch-web/issues/761)) ([45ee508](https://github.com/juspay/hyperswitch-web/commit/45ee50849c1d048e3dba0b35c5252bd4e2ffac89))

## [0.98.2](https://github.com/juspay/hyperswitch-web/compare/v0.98.1...v0.98.2) (2024-10-30)


### Reverts

* remove changes of pr [#746](https://github.com/juspay/hyperswitch-web/issues/746) ([#758](https://github.com/juspay/hyperswitch-web/issues/758)) ([cdae75e](https://github.com/juspay/hyperswitch-web/commit/cdae75ec21525e21aa2049f7bbfd513adebfef89))

## [0.98.1](https://github.com/juspay/hyperswitch-web/compare/v0.98.0...v0.98.1) (2024-10-29)


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.98.1",
"version": "0.98.4",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ let make = (
GooglePayHelpers.handleGooglePayClicked(
~sessionObj=optToken,
~componentName,
~paymentMethodListValue,
~iframeId,
~readOnly,
)
Expand Down
1 change: 0 additions & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ let make = (
GooglePayHelpers.handleGooglePayClicked(
~sessionObj,
~componentName,
~paymentMethodListValue,
~iframeId,
~readOnly=options.readOnly,
)
Expand Down
7 changes: 0 additions & 7 deletions src/Utilities/GooglePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ let handleGooglePayClicked = (
~componentName,
~iframeId,
~readOnly,
~paymentMethodListValue: PaymentMethodsRecord.paymentMethodList,
) => {
let paymentDataRequest = GooglePayType.getPaymentDataFromSession(~sessionObj, ~componentName)
messageParentWindow([
Expand All @@ -168,18 +167,13 @@ let handleGooglePayClicked = (
messageParentWindow([
("GpayClicked", true->JSON.Encode.bool),
("GpayPaymentDataRequest", paymentDataRequest->Identity.anyTypeToJson),
(
"IsTaxCalculationEnabled",
paymentMethodListValue.is_tax_calculation_enabled->JSON.Encode.bool,
),
])
}
}

let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => {
let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)
let areRequiredFieldsEmpty = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsEmpty)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let {iframeId} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
Expand All @@ -192,7 +186,6 @@ let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => {
handleGooglePayClicked(
~sessionObj,
~componentName,
~paymentMethodListValue,
~iframeId,
~readOnly=options.readOnly,
)
Expand Down
10 changes: 0 additions & 10 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/* Remove focus outline in Firefox */
@-moz-document url-prefix() {
*:focus,
*:focus-visible,
*:focus-within,
*:active {
outline: transparent !important;
}
}

/* Remove contact and password icon in safari */
input::-webkit-credentials-auto-fill-button,
input::-webkit-contacts-auto-fill-button {
Expand Down
212 changes: 122 additions & 90 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ let make = (
let clientSecretReMatch = Re.test(`.+_secret_[A-Za-z0-9]+`->Re.fromString, clientSecret)

let preMountLoaderIframeDiv = mountPreMountLoaderIframe()
let isTaxCalculationEnabled = ref(false)

let unMountPreMountLoaderIframe = () => {
switch preMountLoaderIframeDiv->Nullable.toOption {
Expand Down Expand Up @@ -133,6 +134,8 @@ let make = (
let dict = json->getDictFromJson
let isPaymentMethodsData = dict->getString("data", "") === "payment_methods"
if isPaymentMethodsData {
isTaxCalculationEnabled.contents =
dict->getDictFromDict("response")->getBool("is_tax_calculation_enabled", false)
addSmartEventListener("message", onPlaidCallback(mountedIframeRef), "onPlaidCallback")

let json = dict->getJsonFromDict("response", JSON.Encode.null)
Expand Down Expand Up @@ -917,104 +920,133 @@ let make = (
try {
let transactionInfo = gpayobj.transaction_info->getDictFromJson

let handleGooglePayMessages = (event: Types.event) => {
let evJson = event.data->anyTypeToJson
let isTaxCalculationEnabled =
evJson
->getOptionalJsonFromJson("IsTaxCalculationEnabled")
->Option.flatMap(JSON.Decode.bool)
->Option.getOr(false)

let onPaymentDataChanged = intermediatePaymentData => {
let shippingAddress =
intermediatePaymentData
->getDictFromJson
->getDictFromDict("shippingAddress")
->billingContactItemToObjMapper
let newShippingAddress =
let onPaymentDataChanged = intermediatePaymentData => {
let shippingAddress =
intermediatePaymentData
->getDictFromJson
->getDictFromDict("shippingAddress")
->billingContactItemToObjMapper
let newShippingAddress =
[
("state", shippingAddress.administrativeArea->JSON.Encode.string),
("country", shippingAddress.countryCode->JSON.Encode.string),
("zip", shippingAddress.postalCode->JSON.Encode.string),
]->getJsonFromArrayOfJson

let paymentMethodType = "google_pay"->JSON.Encode.string

let currentPaymentRequest = [
(
"newTransactionInfo",
[
("state", shippingAddress.administrativeArea->JSON.Encode.string),
("country", shippingAddress.countryCode->JSON.Encode.string),
("zip", shippingAddress.postalCode->JSON.Encode.string),
]->getJsonFromArrayOfJson

let paymentMethodType = "google_pay"->JSON.Encode.string

if isTaxCalculationEnabled {
TaxCalculation.calculateTax(
~shippingAddress=[
("address", newShippingAddress),
]->getJsonFromArrayOfJson,
~logger,
~publishableKey,
~clientSecret,
~paymentMethodType,
)->then(resp => {
switch resp->TaxCalculation.taxResponseToObjMapper {
| Some(taxCalculationResponse) => {
let updatePaymentRequest =
(
"countryCode",
transactionInfo
->getString("country_code", "")
->JSON.Encode.string,
),
(
"currencyCode",
transactionInfo
->getString("currency_code", "")
->JSON.Encode.string,
),
("totalPriceStatus", "FINAL"->JSON.Encode.string),
(
"totalPrice",
transactionInfo
->getString("total_price", "")
->JSON.Encode.string,
),
]->getJsonFromArrayOfJson,
),
]->getJsonFromArrayOfJson

if isTaxCalculationEnabled.contents {
TaxCalculation.calculateTax(
~shippingAddress=[
("address", newShippingAddress),
]->getJsonFromArrayOfJson,
~logger,
~publishableKey,
~clientSecret,
~paymentMethodType,
)->then(resp => {
switch resp->TaxCalculation.taxResponseToObjMapper {
| Some(taxCalculationResponse) => {
let updatePaymentRequest = [
(
"newTransactionInfo",
[
(
"newTransactionInfo",
[
(
"countryCode",
shippingAddress.countryCode->JSON.Encode.string,
),
(
"currencyCode",
transactionInfo
->getString("currency_code", "")
->JSON.Encode.string,
),
("totalPriceStatus", "FINAL"->JSON.Encode.string),
(
"totalPrice",
taxCalculationResponse.net_amount
->minorUnitToString
->JSON.Encode.string,
),
]->getJsonFromArrayOfJson,
"countryCode",
shippingAddress.countryCode->JSON.Encode.string,
),
(
"currencyCode",
transactionInfo
->getString("currency_code", "")
->JSON.Encode.string,
),
("totalPriceStatus", "FINAL"->JSON.Encode.string),
(
"totalPrice",
taxCalculationResponse.net_amount
->minorUnitToString
->JSON.Encode.string,
),
]->getJsonFromArrayOfJson
updatePaymentRequest->resolve
}
| None => JSON.Encode.null->resolve
]->getJsonFromArrayOfJson,
),
]->getJsonFromArrayOfJson
updatePaymentRequest->resolve
}
})
} else {
JSON.Encode.null->resolve
}
| None => currentPaymentRequest->resolve
}
})
} else {
currentPaymentRequest->resolve
}
let gPayClient = GooglePayType.google(
{
"environment": publishableKey->String.startsWith("pk_prd_")
? "PRODUCTION"
: "TEST",
"paymentDataCallbacks": {
"onPaymentDataChanged": onPaymentDataChanged,
},
}->Identity.anyTypeToJson,
}
let gpayClientRequest = if componentType->getIsExpressCheckoutComponent {
{
"environment": publishableKey->String.startsWith("pk_prd_")
? "PRODUCTION"
: "TEST",
"paymentDataCallbacks": {
"onPaymentDataChanged": onPaymentDataChanged,
},
}->Identity.anyTypeToJson
} else {
{
"environment": publishableKey->String.startsWith("pk_prd_")
? "PRODUCTION"
: "TEST",
}->Identity.anyTypeToJson
}
let gPayClient = GooglePayType.google(gpayClientRequest)

gPayClient.isReadyToPay(payRequest)
->then(res => {
let dict = res->getDictFromJson
let isReadyToPay = getBool(dict, "result", false)
let msg = [("isReadyToPay", isReadyToPay->JSON.Encode.bool)]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
})
->catch(err => {
logger.setLogInfo(
~value=err->Identity.anyTypeToJson->JSON.stringify,
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
~logType=DEBUG,
)
resolve()
})
->ignore

let handleGooglePayMessages = (event: Types.event) => {
let evJson = event.data->anyTypeToJson

gPayClient.isReadyToPay(payRequest)
->then(res => {
let dict = res->getDictFromJson
let isReadyToPay = getBool(dict, "result", false)
let msg = [("isReadyToPay", isReadyToPay->JSON.Encode.bool)]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
resolve()
})
->catch(err => {
logger.setLogInfo(
~value=err->Identity.anyTypeToJson->JSON.stringify,
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
~logType=DEBUG,
)
resolve()
})
->ignore
let gpayClicked =
evJson
->getOptionalJsonFromJson("GpayClicked")
Expand Down

0 comments on commit 12c0bd8

Please sign in to comment.