-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added samsung pay #112
base: main
Are you sure you want to change the base?
Changes from all commits
de395a0
092c74a
82902e3
d7e156c
30bd83f
f4d0ef3
4fb684f
f30ed36
38080f8
12be9e1
453f6e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open ExternalThreeDsTypes | ||
|
||
type module_ = { | ||
checkSamsungPayValidity: (string, statusType => unit) => unit, | ||
presentSamsungPayPaymentSheet: (statusType => unit) => unit, | ||
isAvailable: bool, | ||
} | ||
|
||
@val external require: string => module_ = "require" | ||
|
||
let (checkSamsungPayValidity, presentSamsungPayPaymentSheet, isAvailable) = switch try { | ||
require("react-native-hyperswitch-samsung-pay")->Some | ||
} catch { | ||
| _ => None | ||
} { | ||
| Some(mod) => (mod.checkSamsungPayValidity, mod.presentSamsungPayPaymentSheet, mod.isAvailable) | ||
| None => ((_, _) => (), _ => (), false) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
open SamsungPayType | ||
|
||
type samsungPayWalletValidity = Checking | Valid | Invalid | Not_Started | ||
let val = ref(Not_Started) | ||
|
||
let isSamsungPayValid = state => { | ||
state != Checking && state != Not_Started | ||
} | ||
|
||
let useSamsungPayValidityHook = () => { | ||
let (state, setState) = React.useState(_ => val.contents) | ||
let isSamsungPayAvailable = SamsungPayModule.isAvailable | ||
let (allApiData, _) = React.useContext(AllApiDataContext.allApiDataContext) | ||
let sessionToken = allApiData.sessions->getSamsungPaySessionObject | ||
|
||
let stringifiedSessionToken = | ||
sessionToken | ||
->Utils.getJsonObjectFromRecord | ||
->JSON.stringify | ||
|
||
React.useEffect2(() => { | ||
switch (val.contents, isSamsungPayAvailable, allApiData.sessions) { | ||
| (_, false, _) => | ||
setState(_ => { | ||
val := Invalid | ||
Invalid | ||
}) | ||
| (Not_Started, true, Some(_)) => { | ||
setState(_ => { | ||
val := Checking | ||
Checking | ||
}) | ||
if isSamsungPayAvailable { | ||
SamsungPayModule.checkSamsungPayValidity(stringifiedSessionToken, status => { | ||
if status->ThreeDsUtils.isStatusSuccess { | ||
setState( | ||
_ => { | ||
val := Valid | ||
Valid | ||
}, | ||
) | ||
} else { | ||
setState( | ||
_ => { | ||
val := Invalid | ||
Invalid | ||
}, | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
| (_, _, _) => () | ||
}->ignore | ||
None | ||
}, (isSamsungPayAvailable, allApiData.sessions)) | ||
|
||
state | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
open Utils | ||
type payment3DS = { | ||
\"type": string, | ||
version: string, | ||
data: string, | ||
} | ||
|
||
type paymentShippingAddress = { | ||
shipping: Js.Json.t, // Assuming this is a complex object, we use Js.Json.t for now | ||
email: string, | ||
} | ||
|
||
type paymentCredential = { | ||
\"3_d_s": payment3DS, | ||
card_brand: string, | ||
// payment_currency_type: string, | ||
// payment_last4_dpan: string, | ||
// payment_last4_fpan: string, | ||
card_last4digits: string, | ||
// merchant_ref: string, | ||
method: string, | ||
recurring_payment: bool, | ||
// payment_shipping_address: paymentShippingAddress, | ||
// payment_shipping_method: string, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we handle billing address requirements for a processor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not collecting it via Samsung Pay, as it will add extra friction of filling all these details in Samsung Pay Sheet. We will either accept that in create or confirm ( via HS SDK) |
||
type paymentMethodData = {payment_credential: paymentCredential} | ||
|
||
let defaultSPayPaymentMethodData = { | ||
payment_credential: { | ||
card_brand: "", | ||
recurring_payment: false, | ||
card_last4digits: "", | ||
method: "", | ||
\"3_d_s": { | ||
\"type": "", | ||
version: "", | ||
data: "", | ||
}, | ||
}, | ||
} | ||
|
||
let get3DSData = (dict, str) => { | ||
dict | ||
->Dict.get(str) | ||
->Option.flatMap(JSON.Decode.object) | ||
->Option.map(json => { | ||
{ | ||
\"type": getString(json, "type", ""), | ||
version: getString(json, "version", ""), | ||
data: getString(json, "data", ""), | ||
} | ||
}) | ||
->Option.getOr({\"type": "", version: "", data: ""}) | ||
} | ||
let getPaymentMethodData = dict => { | ||
{ | ||
payment_credential: { | ||
card_brand: getString(dict, "payment_card_brand", ""), | ||
recurring_payment: getBool(dict, "recurring_payment", false), | ||
card_last4digits: getString(dict, "payment_last4_fpan", ""), | ||
method: getString(dict, "method", ""), | ||
\"3_d_s": get3DSData(dict, "3DS"), | ||
}, | ||
} | ||
} | ||
|
||
type paymentDataFromSPay = {paymentMethodData: paymentMethodData, email?: string} | ||
let itemToObjMapper = dict => { | ||
getPaymentMethodData(dict) | ||
} | ||
|
||
let getSamsungPaySessionObject = (sessionData: AllApiDataContext.sessions) => { | ||
let sessionObject = switch sessionData { | ||
| Some(sessionData) => | ||
sessionData | ||
->Array.find(item => item.wallet_name == SAMSUNG_PAY) | ||
->Option.getOr(SessionsType.defaultToken) | ||
| _ => SessionsType.defaultToken | ||
} | ||
|
||
sessionObject | ||
//TO DO order_number should not contain _ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to PMListModifier.res as checks for other wallets are also handled there