-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: paze integration initial commit
- Loading branch information
1 parent
81f1776
commit 756ee62
Showing
8 changed files
with
280 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@react.component | ||
let make = () => { | ||
let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) | ||
<div className=" w-8 h-8 animate-spin" style={color: themeObj.colorTextSecondary}> | ||
<Icon size=32 name="loader" /> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@react.component | ||
let make = () => { | ||
open Utils | ||
open RecoilAtoms | ||
let {iframeId} = Recoil.useRecoilValueFromAtom(keys) | ||
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) | ||
let (isDisabled, setIsDisabled) = React.useState(() => false) | ||
let (showLoader, setShowLoader) = React.useState(() => false) | ||
|
||
let onClick = _ => { | ||
Console.log("Button clicked") | ||
setIsDisabled(_ => true) | ||
setShowLoader(_ => true) | ||
|
||
let metaData = [("isForceSync", true->JSON.Encode.bool)]->getJsonFromArrayOfJson | ||
let message = [ | ||
("fullscreen", true->JSON.Encode.bool), | ||
("param", "pazeWallet"->JSON.Encode.string), | ||
("iframeId", iframeId->JSON.Encode.string), | ||
("metadata", metaData), | ||
] | ||
|
||
messageParentWindow(message) | ||
} | ||
|
||
<button | ||
disabled=false | ||
onClick | ||
className={`w-full flex flex-row justify-center items-center`} | ||
style={ | ||
borderRadius: themeObj.buttonBorderRadius, | ||
backgroundColor: "#2B63FF", | ||
height: themeObj.buttonHeight, | ||
cursor: {isDisabled ? "not-allowed" : "pointer"}, | ||
opacity: {isDisabled ? "0.6" : "1"}, | ||
width: themeObj.buttonWidth, | ||
border: `${themeObj.buttonBorderWidth} solid ${themeObj.buttonBorderColor}`, | ||
}> | ||
{showLoader ? <Spinner /> : <Icon name="paze" size=55 />} | ||
</button> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
type client = { | ||
id: string, | ||
name: string, | ||
profileId: string, | ||
} | ||
type initialize = {client: client} | ||
|
||
type canCheckout = {emailAddress: string} | ||
|
||
type checkout = { | ||
acceptedPaymentCardNetworks: array<string>, | ||
emailAddress: string, | ||
sessionId: string, | ||
actionCode: string, | ||
transactionValue: JSON.t, | ||
shippingPreference: string, | ||
} | ||
|
||
type complete = { | ||
transactionOptions: JSON.t, | ||
transactionId: string, | ||
emailAddress: string, | ||
sessionId: string, | ||
transactionType: string, | ||
transactionValue: JSON.t, | ||
} | ||
|
||
type digitalWalletSdk = { | ||
canCheckout: canCheckout => promise<JSON.t>, | ||
checkout: checkout => promise<JSON.t>, | ||
complete: complete => promise<JSON.t>, | ||
initialize: initialize => promise<JSON.t>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
@val @scope("window") | ||
external digitalWalletSdk: PazeTypes.digitalWalletSdk = "DIGITAL_WALLET_SDK" | ||
|
||
@react.component | ||
let make = () => { | ||
open Promise | ||
let mountPazeSDK = () => { | ||
let pazeScriptURL = `https://sandbox.digitalwallet.earlywarning.com/web/resources/js/digitalwallet-sdk.js` | ||
|
||
let loadPazeSDK = _ => { | ||
digitalWalletSdk.initialize({ | ||
client: { | ||
id: "YK2L1TY5GL0Y1UYLYM9O13oRBRPaMPqYO20N34ByCkwn-c6Is", | ||
name: "Hyperswitch", | ||
profileId: "Getin", | ||
}, | ||
})->then(val => { | ||
Console.log2("PAZE --- init completed", val) | ||
digitalWalletSdk.canCheckout({ | ||
emailAddress: "[email protected]", | ||
})->then(consumerPresent => { | ||
Console.log("PAZE --- canCheckout completed") | ||
Console.log2("PAZE --- consumerPresent: ", consumerPresent) | ||
let transactionValue = { | ||
"transactionAmount": "50.21", | ||
"transactionCurrencyCode": "USD", | ||
}->Identity.anyTypeToJson | ||
|
||
let transactionOptions = { | ||
"billingPreference": "ALL", | ||
"merchantCategoryCode": "US", | ||
"payloadTypeIndicator": "PAYMENT", | ||
}->Identity.anyTypeToJson | ||
|
||
digitalWalletSdk.checkout({ | ||
acceptedPaymentCardNetworks: ["VISA", "MASTERCARD"], | ||
// emailAddress: "[email protected]", | ||
emailAddress: "[email protected]", | ||
sessionId: "m206xe0zacyslo1lsj", | ||
actionCode: "START_FLOW", | ||
transactionValue, | ||
shippingPreference: "ALL", | ||
})->then( | ||
checkoutResponse => { | ||
Console.log2("PAZE --- Checkout Response Object: ", checkoutResponse) | ||
digitalWalletSdk.complete({ | ||
transactionOptions, | ||
transactionId: "", | ||
emailAddress: "[email protected]", | ||
sessionId: "m206xe0zacyslo1lsj", | ||
transactionType: "PURCHASE", | ||
transactionValue, | ||
})->then( | ||
completeResponse => { | ||
Console.log2("PAZE --- Complete Response Object: ", completeResponse) | ||
resolve() | ||
}, | ||
) | ||
}, | ||
) | ||
}) | ||
}) | ||
} | ||
|
||
let pazeScript = Window.createElement("script") | ||
pazeScript->Window.elementSrc(pazeScriptURL) | ||
pazeScript->Window.elementOnerror(exn => { | ||
let err = exn->Identity.anyTypeToJson->JSON.stringify | ||
Console.log2("PAZE --- errrorrr", err) | ||
}) | ||
pazeScript->Window.elementOnload(_ => loadPazeSDK()->ignore) | ||
Window.body->Window.appendChild(pazeScript) | ||
} | ||
|
||
React.useEffect(() => { | ||
mountPazeSDK() | ||
None | ||
}, []) | ||
|
||
<div id="paze-button" className="w-full flex flex-row justify-center rounded-md h-auto" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters