From a74438ce03bcdeed73f4c3c795c8535cbf3e6f0f Mon Sep 17 00:00:00 2001 From: Sagnik Mitra Date: Wed, 30 Oct 2024 16:57:24 +0530 Subject: [PATCH] fix: gpay unified checkout fix --- src/orca-loader/Elements.res | 62 ++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index d6aa0b59..a44ecdd3 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -952,31 +952,30 @@ let make = ( )->then(resp => { switch resp->TaxCalculation.taxResponseToObjMapper { | Some(taxCalculationResponse) => { - let updatePaymentRequest = - [ - ( - "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, - ), - ]->getJsonFromArrayOfJson + let updatePaymentRequest = [ + ( + "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, + ), + ]->getJsonFromArrayOfJson updatePaymentRequest->resolve } | None => JSON.Encode.null->resolve @@ -986,7 +985,7 @@ let make = ( JSON.Encode.null->resolve } } - let gPayClient = GooglePayType.google( + let gpayClientRequest = if componentType->getIsExpressCheckoutComponent { { "environment": publishableKey->String.startsWith("pk_prd_") ? "PRODUCTION" @@ -994,8 +993,15 @@ let make = ( "paymentDataCallbacks": { "onPaymentDataChanged": onPaymentDataChanged, }, - }->Identity.anyTypeToJson, - ) + }->Identity.anyTypeToJson + } else { + { + "environment": publishableKey->String.startsWith("pk_prd_") + ? "PRODUCTION" + : "TEST", + }->Identity.anyTypeToJson + } + let gPayClient = GooglePayType.google(gpayClientRequest) gPayClient.isReadyToPay(payRequest) ->then(res => {