Skip to content

Commit

Permalink
Merge branch 'payment-management-headless' of github.com:juspay/hyper…
Browse files Browse the repository at this point in the history
…switch-web into payment-management
  • Loading branch information
PritishBudhiraja committed Jun 28, 2024
2 parents d73fdbb + 37230d3 commit 54bcf49
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Hyperswitch-React-Demo-App/src/something.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const loadSDK = (clientSecret, pubkey) => {
const appearance = {
theme: "charcoal",
};
const ephimeralKey = "epk_199235de39aa4ca08c596a98635e6bbb";
const widgets = hyper.widgets({ appearance, clientSecret, ephimeralKey });
const ephemeralKey = "epk_8dd34bfa79b1483b9f9a56ba9ad23009";
const widgets = hyper.widgets({ appearance, clientSecret, ephemeralKey });
const unifiedCheckoutOptions = {
layout: "tabs",
wallets: {
Expand Down
1 change: 1 addition & 0 deletions src/RenderPaymentMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ let make = (
</RenderIf>}>
<PaymentManagementLazy />
</React.Suspense>
| PaymentRequestButtonsElement
| NONE => React.null
}}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ let make = (publishableKey, options: option<JSON.t>, analyticsInfo: option<JSON.
~clientSecret={clientSecretId},
~publishableKey,
~logger=Some(logger),
~ephemeralKey=ephemeralKey.contents,
)
}

Expand Down
15 changes: 14 additions & 1 deletion src/orca-loader/PaymentSession.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
open Types

let make = (options, ~clientSecret, ~publishableKey, ~logger: option<OrcaLogger.loggerMake>) => {
let make = (
options,
~clientSecret,
~publishableKey,
~logger: option<OrcaLogger.loggerMake>,
~ephemeralKey,
) => {
let logger = logger->Option.getOr(OrcaLogger.defaultLoggerConfig)
let switchToCustomPod =
GlobalVars.isInteg &&
Expand All @@ -20,6 +26,13 @@ let make = (options, ~clientSecret, ~publishableKey, ~logger: option<OrcaLogger.
~logger,
~switchToCustomPod,
),
getPaymentManagementMethods: _ =>
PaymentSessionMethods.getPaymentManagementMethods(
~ephemeralKey,
~logger,
~switchToCustomPod,
~endpoint,
),
}

defaultInitPaymentSession
Expand Down
69 changes: 66 additions & 3 deletions src/orca-loader/PaymentSessionMethods.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
open Promise
open Types
open Utils

let getCustomerSavedPaymentMethods = (
~clientSecret,
~publishableKey,
~endpoint,
~logger,
~switchToCustomPod,
) => {
open Promise
open Types
open Utils
PaymentHelpers.fetchCustomerPaymentMethodList(
~clientSecret,
~publishableKey,
Expand Down Expand Up @@ -196,3 +197,65 @@ let getCustomerSavedPaymentMethods = (
updatedCustomerDetails->resolve
})
}

let getPaymentManagementMethods = (~ephemeralKey, ~logger, ~switchToCustomPod, ~endpoint) => {
let getSavedPaymentManagementMethodsList = _ => {
PaymentHelpers.fetchSavedPaymentMethodList(
~ephemeralKey,
~optLogger=Some(logger),
~switchToCustomPod=false,
~endpoint,
)
->then(response => {
response->resolve
})
->catch(err => {
let exceptionMessage = err->formatException->JSON.stringify
let updatedCustomerDetails =
[
(
"error",
[
("type", "server_error"->JSON.Encode.string),
("message", exceptionMessage->JSON.Encode.string),
]->getJsonFromArrayOfJson,
),
]->getJsonFromArrayOfJson
updatedCustomerDetails->resolve
})
}

let deleteSavedPaymentMethod = paymentMethodId => {
PaymentHelpers.deletePaymentMethod(
~ephemeralKey,
~paymentMethodId={paymentMethodId->JSON.Decode.string->Option.getOr("")},
~logger,
~switchToCustomPod,
)
->then(response => {
response->resolve
})
->catch(err => {
let exceptionMessage = err->formatException->JSON.stringify
let updatedCustomerDetails =
[
(
"error",
[
("type", "server_error"->JSON.Encode.string),
("message", exceptionMessage->JSON.Encode.string),
]->getJsonFromArrayOfJson,
),
]->getJsonFromArrayOfJson

updatedCustomerDetails->resolve
})
}

{
getSavedPaymentManagementMethodsList,
deleteSavedPaymentMethod,
}
->Identity.anyTypeToJson
->resolve
}
23 changes: 22 additions & 1 deletion src/orca-loader/Types.res
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ type getCustomerSavedPaymentMethods = {
confirmWithLastUsedPaymentMethod: JSON.t => Promise.t<JSON.t>,
}

type initPaymentSession = {getCustomerSavedPaymentMethods: unit => Promise.t<JSON.t>}
type getPaymentManagementMethods = {
getSavedPaymentManagementMethodsList: unit => Promise.t<JSON.t>,
deleteSavedPaymentMethod: JSON.t => Promise.t<JSON.t>,
}

type initPaymentSession = {
getCustomerSavedPaymentMethods: unit => Promise.t<JSON.t>,
getPaymentManagementMethods: unit => Promise.t<JSON.t>,
}

type confirmParams = {return_url: string}

Expand Down Expand Up @@ -125,6 +133,14 @@ let getCustomerDefaultSavedPaymentMethodData = () => {
JSON.Encode.null
}

let getSavedPaymentManagementMethodsList = () => {
JSON.Encode.null
}

let deleteSavedPaymentMethod = () => {
JSON.Encode.null
}

let getCustomerLastUsedPaymentMethodData = () => {
JSON.Encode.null
}
Expand All @@ -146,8 +162,13 @@ let defaultGetCustomerSavedPaymentMethods = () => {
Promise.resolve(JSON.Encode.null)
}

let defaultGetPaymentManagementMethods = () => {
Promise.resolve(JSON.Encode.null)
}

let defaultInitPaymentSession: initPaymentSession = {
getCustomerSavedPaymentMethods: defaultGetCustomerSavedPaymentMethods,
getPaymentManagementMethods: defaultGetPaymentManagementMethods,
}

let defaultHyperInstance = {
Expand Down

0 comments on commit 54bcf49

Please sign in to comment.