-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added One Click Widgets (ApplePay, GooglePay, PayPal)
- Loading branch information
1 parent
ce71d4b
commit 85b3581
Showing
10 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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,81 @@ | ||
open PaymentType | ||
open RecoilAtoms | ||
|
||
@react.component | ||
let make = (~paymentType: CardThemeType.mode) => { | ||
let sessionsObj = Recoil.useRecoilValueFromAtom(sessions) | ||
let {paymentMethodOrder} = Recoil.useRecoilValueFromAtom(optionAtom) | ||
let isApplePayReady = Recoil.useRecoilValueFromAtom(isApplePayReady) | ||
let isGooglePayReady = Recoil.useRecoilValueFromAtom(isGooglePayReady) | ||
let methodslist = Recoil.useRecoilValueFromAtom(list) | ||
let paymentOrder = paymentMethodOrder->Utils.getOptionalArr->Utils.removeDuplicate | ||
let (sessions, setSessions) = React.useState(_ => Dict.make()->JSON.Encode.object) | ||
let (walletOptions, setWalletOptions) = React.useState(_ => []) | ||
|
||
let (list, setList) = React.useState(_ => PaymentMethodsRecord.defaultList) | ||
|
||
let areAllGooglePayRequiredFieldsPrefilled = DynamicFieldsUtils.useAreAllRequiredFieldsPrefilled( | ||
~list, | ||
~paymentMethod="wallet", | ||
~paymentMethodType="google_pay", | ||
) | ||
|
||
let areAllApplePayRequiredFieldsPrefilled = DynamicFieldsUtils.useAreAllRequiredFieldsPrefilled( | ||
~list, | ||
~paymentMethod="wallet", | ||
~paymentMethodType="apple_pay", | ||
) | ||
|
||
let walletList = React.useMemo(() => { | ||
switch methodslist { | ||
| Loaded(paymentlist) => | ||
let paymentOrder = | ||
paymentOrder->Array.length > 0 ? paymentOrder : PaymentModeType.defaultOrder | ||
let plist = paymentlist->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper | ||
let (wallets, _) = | ||
plist->PaymentUtils.paymentListLookupNew( | ||
~order=paymentOrder, | ||
~showApplePay=isApplePayReady, | ||
~showGooglePay=isGooglePayReady, | ||
~areAllGooglePayRequiredFieldsPrefilled, | ||
~areAllApplePayRequiredFieldsPrefilled, | ||
) | ||
wallets->Utils.removeDuplicate->Utils.getWalletPaymentMethod(paymentType) | ||
| _ => [] | ||
} | ||
}, ( | ||
methodslist, | ||
paymentMethodOrder, | ||
isApplePayReady, | ||
isGooglePayReady, | ||
areAllGooglePayRequiredFieldsPrefilled, | ||
areAllApplePayRequiredFieldsPrefilled, | ||
)) | ||
|
||
React.useEffect(() => { | ||
switch methodslist { | ||
| Loaded(paymentlist) => | ||
let plist = paymentlist->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper | ||
|
||
setWalletOptions(_ => walletList) | ||
setList(_ => plist) | ||
| _ => () | ||
} | ||
None | ||
}, (methodslist, walletList)) | ||
React.useEffect(() => { | ||
switch sessionsObj { | ||
| Loaded(ssn) => setSessions(_ => ssn) | ||
| _ => () | ||
} | ||
None | ||
}, [sessionsObj]) | ||
|
||
<RenderIf condition={walletOptions->Array.length > 0}> | ||
<div className="flex flex-col place-items-center"> | ||
<ErrorBoundary key="payment_request_buttons_all" level={ErrorBoundary.RequestButton}> | ||
<PaymentRequestButtonElement sessions walletOptions list /> | ||
</ErrorBoundary> | ||
</div> | ||
</RenderIf> | ||
} |
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