Skip to content

Commit

Permalink
Devex (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: sh-iv-am <[email protected]>
  • Loading branch information
sh-iv-am and sh-iv-am authored Jun 12, 2024
1 parent c283af3 commit 0535029
Show file tree
Hide file tree
Showing 14 changed files with 617 additions and 208 deletions.
2 changes: 1 addition & 1 deletion android
Submodule android updated 27 files
+34 −70 app/src/main/java/io/hyperswitch/MainActivity.kt
+0 −181 app/src/main/java/io/hyperswitch/MainFragment.kt
+323 −137 app/src/main/java/io/hyperswitch/PaymentSession.kt
+3 −4 app/src/main/java/io/hyperswitch/payments/gpay/GooglePayActivity.kt
+2 −3 app/src/main/java/io/hyperswitch/paymentsheet/DefaultFlowController.kt
+36 −11 app/src/main/java/io/hyperswitch/paymentsheet/DefaultPaymentSheetLauncher.kt
+9 −9 app/src/main/java/io/hyperswitch/paymentsheet/FlowControllerFactory.kt
+6 −37 app/src/main/java/io/hyperswitch/paymentsheet/PaymentSheet.kt
+10 −7 app/src/main/java/io/hyperswitch/react/HyperHeadlessModule.kt
+6 −5 app/src/main/java/io/hyperswitch/react/HyperModule.kt
+1 −1 app/src/main/java/io/hyperswitch/react/MainApplication.kt
+7 −6 app/src/main/java/io/hyperswitch/react/Utils.kt
+0 −7 app/src/main/res/layout/fragment_main.xml
+1 −6 app/src/main/res/layout/main_activity.xml
+2 −2 build.gradle
+ maven/io/hyperswitch/base-release/1.0.0/base-release-1.0.0.aar
+9 −0 maven/io/hyperswitch/base-release/1.0.0/base-release-1.0.0.pom
+13 −0 maven/io/hyperswitch/base-release/maven-metadata-local.xml
+ maven/io/hyperswitch/camera-core-release/1.0.0/camera-core-release-1.0.0.aar
+9 −0 maven/io/hyperswitch/camera-core-release/1.0.0/camera-core-release-1.0.0.pom
+14 −0 maven/io/hyperswitch/camera-core-release/maven-metadata-local.xml
+ maven/io/hyperswitch/cardscan-release/1.0.0/cardscan-release-1.0.0.aar
+9 −0 maven/io/hyperswitch/cardscan-release/1.0.0/cardscan-release-1.0.0.pom
+14 −0 maven/io/hyperswitch/cardscan-release/maven-metadata-local.xml
+ maven/io/hyperswitch/hscardscan-release/1.0.0/hscardscan-release-1.0.0.aar
+9 −0 maven/io/hyperswitch/hscardscan-release/1.0.0/hscardscan-release-1.0.0.pom
+14 −0 maven/io/hyperswitch/hscardscan-release/maven-metadata-local.xml
2 changes: 1 addition & 1 deletion ios
Submodule ios updated from 2dce4d to b3ef2a
2 changes: 1 addition & 1 deletion src/components/common/CustomButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ let make = (
onPress={switch onPress {
| Some(val) =>
x => {
fillButton()
val(x)
}
| None => _ => ()
Expand All @@ -185,6 +184,7 @@ let make = (
| NoIcon => React.null
}}
{if buttonState == LoadingButton {
fillButton()
<Animated.View style={array([fillStyle, widthStyle])} />
} else {
React.null
Expand Down
217 changes: 134 additions & 83 deletions src/components/elements/ButtonElement.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
open ReactNative
open PaymentMethodListType
open GooglePayType

external parser: paymentMethodData => JSON.t = "%identity"
external parser2: GooglePayType.requestType => JSON.t = "%identity"
external parser: GooglePayTypeNew.paymentMethodData => JSON.t = "%identity"
external parser2: SdkTypes.addressDetails => JSON.t = "%identity"

type item = {
linearGradientColorTuple: option<ThemebasedStyle.buttonColorConfig>,
Expand Down Expand Up @@ -90,7 +89,7 @@ let make = (
}
}

let processRequest = (~payment_method_data, ~walletTypeAlt=?, ()) => {
let processRequest = (~payment_method_data, ~walletTypeAlt=?, ~email=?, ()) => {
let walletType = switch walletTypeAlt {
| Some(wallet) => wallet
| None => walletType
Expand Down Expand Up @@ -171,6 +170,7 @@ let make = (
| Some(id) => Some(id ++ ".hyperswitch://")
| None => None
},
?email,
// customer_id: ?switch nativeProp.configuration.customer {
// | Some(customer) => customer.id
// | None => None
Expand Down Expand Up @@ -254,12 +254,30 @@ let make = (
}
}

let (statesJson, setStatesJson) = React.useState(_ => None)

React.useEffect0(() => {
// Dynamically import/download Postal codes and states JSON
RequiredFieldsTypes.importStates("./../../utility/reusableCodeFromWeb/States.json")
->Promise.then(res => {
setStatesJson(_ => Some(res.states))
Promise.resolve()
})
->Promise.catch(_ => {
setStatesJson(_ => None)
Promise.resolve()
})
->ignore

None
})

let confirmGPay = var => {
let paymentData = var->PaymentConfirmTypes.itemToObjMapperJava
switch paymentData.error {
| "" =>
let json = paymentData.paymentMethodData->JSON.parseExn
let obj = json->Utils.getDictFromJson->itemToObjMapper
let obj = json->Utils.getDictFromJson->GooglePayTypeNew.itemToObjMapper(statesJson)
let payment_method_data =
[
(
Expand All @@ -268,10 +286,21 @@ let make = (
->Dict.fromArray
->JSON.Encode.object,
),
(
"billing",
switch obj.paymentMethodData.info {
| Some(info) =>
switch info.billing_address {
| Some(address) => address->parser2
| None => JSON.Encode.null
}
| None => JSON.Encode.null
},
),
]
->Dict.fromArray
->JSON.Encode.object
processRequest(~payment_method_data, ())
processRequest(~payment_method_data, ~email=?obj.email, ())
| "Cancel" =>
setLoading(FillingDetails)
showAlert(~errorType="warning", ~message="Payment was Cancelled")
Expand Down Expand Up @@ -324,12 +353,28 @@ let make = (
[
(
walletType.payment_method,
[(walletType.payment_method_type, paymentData)]->Dict.fromArray->JSON.Encode.object,
[(walletType.payment_method_type, paymentData)]
->Dict.fromArray
->JSON.Encode.object,
),
(
"billing",
switch var->GooglePayTypeNew.getBillingContact("billing_contact", statesJson) {
| Some(billing) => billing->parser2
| None => JSON.Encode.null
},
),
]
->Dict.fromArray
->JSON.Encode.object
processRequest(~payment_method_data, ())
processRequest(
~payment_method_data,
~email=?switch var->GooglePayTypeNew.getBillingContact("billing_contact", statesJson) {
| Some(billing) => billing.email
| None => None
},
(),
)
}
}
}
Expand All @@ -347,86 +392,92 @@ let make = (
),
(),
)
switch walletType.payment_experience[0]->Option.map(paymentExperience =>
paymentExperience.payment_experience_type_decode
) {
| Some(INVOKE_SDK_CLIENT) =>
switch walletType.payment_method_type_wallet {
| GOOGLE_PAY =>
HyperModule.launchGPay(
GooglePayType.getGpayToken(~obj=sessionObject, ~appEnv=nativeProp.env),
confirmGPay,
)
| PAYPAL =>
if sessionObject.session_token !== "" && ReactNative.Platform.os == #android {
PaypalModule.launchPayPal(sessionObject.session_token, confirmPayPal)
} else {
let redirectData = []->Dict.fromArray->JSON.Encode.object
let payment_method_data =
[
(
walletType.payment_method,
[(walletType.payment_method_type ++ "_redirect", redirectData)]
->Dict.fromArray
->JSON.Encode.object,
),
]
->Dict.fromArray
->JSON.Encode.object
let altPaymentExperience =
walletType.payment_experience->Array.find(x =>
x.payment_experience_type_decode === REDIRECT_TO_URL
setTimeout(_ => {
switch walletType.payment_experience[0]->Option.map(paymentExperience =>
paymentExperience.payment_experience_type_decode
) {
| Some(INVOKE_SDK_CLIENT) =>
switch walletType.payment_method_type_wallet {
| GOOGLE_PAY =>
HyperModule.launchGPay(
GooglePayTypeNew.getGpayToken(
~obj=sessionObject,
~appEnv=nativeProp.env,
~requiredFields=walletType.required_field,
),
confirmGPay,
)
| PAYPAL =>
if sessionObject.session_token !== "" && ReactNative.Platform.os == #android {
PaypalModule.launchPayPal(sessionObject.session_token, confirmPayPal)
} else {
let redirectData = []->Dict.fromArray->JSON.Encode.object
let payment_method_data =
[
(
walletType.payment_method,
[(walletType.payment_method_type ++ "_redirect", redirectData)]
->Dict.fromArray
->JSON.Encode.object,
),
]
->Dict.fromArray
->JSON.Encode.object
let altPaymentExperience =
walletType.payment_experience->Array.find(x =>
x.payment_experience_type_decode === REDIRECT_TO_URL
)
let walletTypeAlt = {
...walletType,
payment_experience: [
altPaymentExperience->Option.getOr({
payment_experience_type: "",
payment_experience_type_decode: NONE,
eligible_connectors: [],
}),
],
}
// when session token for paypal is absent, switch to redirect flow
processRequest(~payment_method_data, ~walletTypeAlt, ())
}
| APPLE_PAY =>
if (
sessionObject.session_token_data == JSON.Encode.null ||
sessionObject.payment_request_data == JSON.Encode.null
) {
setLoading(FillingDetails)
showAlert(~errorType="warning", ~message="Waiting for Sessions API")
} else {
HyperModule.launchApplePay(
[
("session_token_data", sessionObject.session_token_data),
("payment_request_data", sessionObject.payment_request_data),
]
->Dict.fromArray
->JSON.Encode.object
->JSON.stringify,
confirmApplePay,
)
let walletTypeAlt = {
...walletType,
payment_experience: [
altPaymentExperience->Option.getOr({
payment_experience_type: "",
payment_experience_type_decode: NONE,
eligible_connectors: [],
}),
],
}
// when session token for paypal is absent, switch to redirect flow
processRequest(~payment_method_data, ~walletTypeAlt, ())
}
| APPLE_PAY =>
if (
sessionObject.session_token_data == JSON.Encode.null ||
sessionObject.payment_request_data == JSON.Encode.null
) {
setLoading(FillingDetails)
showAlert(~errorType="warning", ~message="Waiting for Sessions API")
} else {
HyperModule.launchApplePay(
[
("session_token_data", sessionObject.session_token_data),
("payment_request_data", sessionObject.payment_request_data),
]
->Dict.fromArray
->JSON.Encode.object
->JSON.stringify,
confirmApplePay,
)
| _ => ()
}
| Some(REDIRECT_TO_URL) =>
let redirectData = []->Dict.fromArray->JSON.Encode.object
let payment_method_data =
[
(
walletType.payment_method,
[(walletType.payment_method_type ++ "_redirect", redirectData)]
->Dict.fromArray
->JSON.Encode.object,
),
]
->Dict.fromArray
->JSON.Encode.object
processRequest(~payment_method_data, ())
| _ => ()
}
| Some(REDIRECT_TO_URL) =>
let redirectData = []->Dict.fromArray->JSON.Encode.object
let payment_method_data =
[
(
walletType.payment_method,
[(walletType.payment_method_type ++ "_redirect", redirectData)]
->Dict.fromArray
->JSON.Encode.object,
),
]
->Dict.fromArray
->JSON.Encode.object
processRequest(~payment_method_data, ())
| _ => ()
}
}, 1000)->ignore
}

React.useEffect1(_ => {
Expand Down
Loading

0 comments on commit 0535029

Please sign in to comment.