Skip to content

Commit

Permalink
fix: paypal bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 committed Dec 15, 2023
1 parent 61bb151 commit d3ea8d7
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
apiBaseUrl=https://sandbox.hyperswitch.io
apiBaseUrl=https://integ-api.hyperswitch.io
sdkBaseUrl=https://beta.hyperswitch.io/v1/HyperLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ let make = (
try {
if connector->Js.String2.length > 0 {
let dict = isPayoutFlow
? Window.getPayoutConnectorConfig(connector)
: Window.getConnectorConfig(connector)
? Window.getPayoutConnectorConfig(connector->Js.String2.toLowerCase)
: Window.getConnectorConfig(connector->Js.String2.toLowerCase)
setScreenState(_ => Success)
dict
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let make = (
try {
setScreenState(_ => Loading)
let obj: ConnectorTypes.wasmRequest = {
connector,
connector: connector->Js.String2.toLowerCase,
payment_methods_enabled: paymentMethodsEnabled,
metadata: metaData,
}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/Connectors/ConnectorPreview.res
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ module ConnectorSummaryGrid = {
try {
if connector->Js.String2.length > 0 {
let dict = isPayoutFlow
? Window.getPayoutConnectorConfig(connector)
: Window.getConnectorConfig(connector)
? Window.getPayoutConnectorConfig(connector->Js.String2.toLowerCase)
: Window.getConnectorConfig(connector->Js.String2.toLowerCase)
setScreenState(_ => Success)
dict
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/screens/HyperSwitch/Connectors/ConnectorTableUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ let getProcessorPayloadType = dict => {
open LogicUtils
{
connector_type: dict->getString("connector_type", ""),
connector_name: dict->getString("connector_name", ""),
connector_name: dict
->getString("connector_name", "")
->ConnectorUtils.getConnectorNameTypeFromString
->ConnectorUtils.getConnectorNameString,
connector_label: dict->getString("connector_label", ""),
connector_account_details: dict
->getObj("connector_account_details", Js.Dict.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ module PaymentMethodsRender = {
let pmts = React.useMemo1(() => {
(
isPayoutFlow
? Window.getPayoutConnectorConfig(connector)
: Window.getConnectorConfig(connector)
? Window.getPayoutConnectorConfig(connector->Js.String2.toLowerCase)
: Window.getConnectorConfig(connector->Js.String2.toLowerCase)
)->getDictFromJsonObject
}, [connector])
let keys =
Expand Down
17 changes: 9 additions & 8 deletions src/screens/HyperSwitch/Connectors/ConnectorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ let stripeTestInfo = {
}

let paypalTestInfo = {
description: "A paypal test processor to simulate payment flows and experience hyperswitch checkout.",
description: "A payPal test processor to simulate payment flows and experience hyperswitch checkout.",
}

let wiseInfo = {
Expand Down Expand Up @@ -489,7 +489,7 @@ let getConnectorNameString = connector => {
| MOLLIE => "mollie"
| TRUSTPAY => "trustpay"
| ZEN => "zen"
| PAYPAL => "paypal"
| PAYPAL => "payPal"
| COINBASE => "coinbase"
| OPENNODE => "opennode"
| NMI => "nmi"
Expand All @@ -508,7 +508,7 @@ let getConnectorNameString = connector => {
| TSYS => "tsys"
| NOON => "noon"
| STRIPE_TEST => "stripe_test"
| PAYPAL_TEST => "paypal_test"
| PAYPAL_TEST => "payPal_test"
| WISE => "wise"
| STAX => "stax"
| GOCARDLESS => "gocardless"
Expand Down Expand Up @@ -546,7 +546,7 @@ let getConnectorNameTypeFromString = connector => {
| "mollie" => MOLLIE
| "trustpay" => TRUSTPAY
| "zen" => ZEN
| "paypal" => PAYPAL
| "payPal" | "paypal" => PAYPAL
| "coinbase" => COINBASE
| "opennode" => OPENNODE
| "nmi" => NMI
Expand All @@ -558,7 +558,7 @@ let getConnectorNameTypeFromString = connector => {
| "fauxpay" => FAUXPAY
| "pretendpay" => PRETENDPAY
| "stripe_test" => STRIPE_TEST
| "paypal_test" => PAYPAL_TEST
| "payPal_test" => PAYPAL_TEST
| "cashtocode" => CASHTOCODE
| "payme" => PAYME
| "globepay" => GLOBEPAY
Expand Down Expand Up @@ -803,7 +803,7 @@ let generateInitialValuesDict = (

dict->Js.Dict.set("connector_account_details", connectorAccountDetails->Js.Json.object_)

dict->Js.Dict.set("connector_name", connector->Js.Json.string)
dict->Js.Dict.set("connector_name", connector->Js.String2.toLowerCase->Js.Json.string)
dict->Js.Dict.set(
"connector_type",
getConnectorType(connector->getConnectorNameTypeFromString, ~isPayoutFlow, ())->Js.Json.string,
Expand Down Expand Up @@ -1168,6 +1168,7 @@ let constructConnectorRequestBody = (wasmRequest: wasmRequest, payload: Js.Json.
let dict = Js.Dict.fromArray([
("connector_account_details", connectorAccountDetails),
("connector_label", dict->getString("connector_label", "")->Js.Json.string),
("status", dict->getString("status", "active")->Js.Json.string),
])
values
->getDictFromJsonObject
Expand Down Expand Up @@ -1210,8 +1211,8 @@ let defaultSelectAllCards = (
let config =
(
isPayoutFlow
? Window.getPayoutConnectorConfig(connector)
: Window.getConnectorConfig(connector)
? Window.getPayoutConnectorConfig(connector->Js.String.toLowerCase)
: Window.getConnectorConfig(connector->Js.String.toLowerCase)
)->getDictFromJsonObject
pmts->Js.Array2.forEach(val => {
switch val.payment_method->getPaymentMethodFromString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ let make = (
->Belt.Option.getWithDefault("")
->LogicUtils.getBoolFromString(false)

let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading)
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Success)
let (configuartionType, setConfigurationType) = React.useState(_ => ConnectorTypes.NotSelected)

let (retryTime, setRetryTime) = React.useState(_ => 0)
Expand All @@ -297,6 +297,7 @@ let make = (
open ConnectorUtils
open SimpleConnectorFlowUtils
try {
setScreenState(_ => Loading)
let profileIdValue =
values->LogicUtils.getDictFromJsonObject->LogicUtils.getString("profile_id", "")
let body = generateConnectorPayloadPayPal(
Expand All @@ -319,14 +320,14 @@ let make = (
)
let res = await updateDetails(url, body, Post)

setScreenState(_ => Success)
setInitialValues(_ => res)
let connectorId =
res->LogicUtils.getDictFromJsonObject->LogicUtils.getString("merchant_connector_id", "")
if !isUpdateFlow {
RescriptReactRouter.push(`/connectors/new?name=paypal&connectorId=${connectorId}`)
RescriptReactRouter.push(`/connectors/new?name=payPal&connectorId=${connectorId}`)
}
setConnectorId(_ => connectorId)
setScreenState(_ => Success)
} catch {
| Js.Exn.Error(e) => {
setShowVerifyModal(_ => false)
Expand Down Expand Up @@ -415,80 +416,91 @@ let make = (
switch setupAccountStatus {
| Account_not_found =>
switch configuartionType {
| Manual => setSetupAccountStatus(._ => Manual_setup_flow)
| Manual
| NotSelected =>
setSetupAccountStatus(._ => Manual_setup_flow)

| Automatic => handleConnector(values)->ignore
}
| Manual_setup_flow => handleConnectorConnected(values)
| Manual_setup_flow => {
let dictOfInitialValues = values->LogicUtils.getDictFromJsonObject
dictOfInitialValues->Js.Dict.set("disabled", false->Js.Json.boolean)
dictOfInitialValues->Js.Dict.set("status", "active"->Js.Json.string)
setInitialValues(_ => dictOfInitialValues->Js.Json.object_)
handleConnectorConnected(dictOfInitialValues->Js.Json.object_)
}
| _ => ()
}
Js.Nullable.null->Js.Promise.resolve
}

<div className="w-full h-full flex flex-col gap-8 justify-between">
<Form
initialValues
validate={validateMandatoryFieldForPaypal}
formClass="flex flex-col gap-8"
onSubmit={handleOnSubmit}>
<div className="flex flex-col gap-8">
<ConnectorAccountDetailsHelper.ConnectorHeaderWrapper
connector
headerButton={<FormRenderer.SubmitButton
loadingText="Processing..."
text="Proceed"
disabledParamter={configuartionType === NotSelected ? true : false}
/>}
setShowModal>
<div className="mx-12">
{switch setupAccountStatus {
| Account_not_found =>
<div className="flex flex-col gap-4">
// <UIUtils.RenderIf condition={!HSwitchGlobalVars.isLiveHyperSwitchDashboard}>
<ConnectorAccountDetailsHelper.BusinessProfileRender
isUpdateFlow selectedConnector={connector}
<PageLoaderWrapper screenState>
<Form
initialValues
validate={validateMandatoryFieldForPaypal}
formClass="flex flex-col gap-8"
onSubmit={handleOnSubmit}>
<div className="flex flex-col gap-8">
<ConnectorAccountDetailsHelper.ConnectorHeaderWrapper
connector
headerButton={<FormRenderer.SubmitButton
loadingText="Processing..."
text="Proceed"
disabledParamter={configuartionType === NotSelected ? true : false}
/>}
setShowModal>
<div className="mx-12">
{switch setupAccountStatus {
| Account_not_found =>
<div className="flex flex-col gap-4">
// <UIUtils.RenderIf condition={!HSwitchGlobalVars.isLiveHyperSwitchDashboard}>
<ConnectorAccountDetailsHelper.BusinessProfileRender
isUpdateFlow selectedConnector={connector}
/>
// </UIUtils.RenderIf>
<LandingScreen configuartionType setConfigurationType />
</div>
| Redirecting_to_paypal =>
<RedirectionToPayPalFlow actionUrl setActionUrl connectorId getStatus />
| Manual_setup_flow =>
<ManualSetupScreen
connector
connectorAccountFields
selectedConnector
connectorMetaDataFields
connectorWebHookDetails
isUpdateFlow
configuartionType
connectorLabelDetailField
/>
// </UIUtils.RenderIf>
<LandingScreen configuartionType setConfigurationType />
</div>
| Redirecting_to_paypal =>
<RedirectionToPayPalFlow actionUrl setActionUrl connectorId getStatus />
| Manual_setup_flow =>
<ManualSetupScreen
connector
connectorAccountFields
selectedConnector
connectorMetaDataFields
connectorWebHookDetails
isUpdateFlow
configuartionType
connectorLabelDetailField
/>
| Payments_not_receivable
| Ppcp_custom_denied
| More_permissions_needed
| Email_not_verified =>
<ErrorPage setupAccountStatus retryTime actionUrl getStatus />
| _ => React.null
}}
</div>
<FormValuesSpy />
</ConnectorAccountDetailsHelper.ConnectorHeaderWrapper>
<ConnectorAccountDetailsHelper.VerifyConnectoModal
showVerifyModal
setShowVerifyModal
connector
verifyErrorMessage
suggestedActionExists
suggestedAction
setVerifyDone
/>
| Payments_not_receivable
| Ppcp_custom_denied
| More_permissions_needed
| Email_not_verified =>
<ErrorPage setupAccountStatus retryTime actionUrl getStatus />
| _ => React.null
}}
</div>
<FormValuesSpy />
</ConnectorAccountDetailsHelper.ConnectorHeaderWrapper>
<ConnectorAccountDetailsHelper.VerifyConnectoModal
showVerifyModal
setShowVerifyModal
connector
verifyErrorMessage
suggestedActionExists
suggestedAction
setVerifyDone
/>
</div>
</Form>
<div className="border-t-2 flex py-2 px-6 gap-4 items-center">
<img src="/assets/PayPalFullLogo.svg" />
<p className=p2RedularTextClass>
{"| Hyperswitch is PayPal's trusted partner, your credentials are secure & never stored with us."->React.string}
</p>
</div>
</Form>
<div className="border-t-2 flex py-2 px-6 gap-4 items-center">
<img src="/assets/PayPalFullLogo.svg" />
<p className=p2RedularTextClass>
{"| Hyperswitch is PayPal's trusted partner, your credentials are secure & never stored with us."->React.string}
</p>
</div>
</PageLoaderWrapper>
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let getBodyType = (isUpdateFlow, configuartionType, setupAccountStatus) => {
| (true, _) =>
switch configuartionType {
| Manual => "BodyKey"
| Automatic => "SignatureKey "
| Automatic | NotSelected => "SignatureKey"
}
}
bodyType
Expand All @@ -99,7 +99,7 @@ let generateConnectorPayloadPayPal = (
let initialValues =
[
("profile_id", profileId->Js.Json.string),
("connector_name", connector->Js.Json.string),
("connector_name", connector->Js.String2.toLowerCase->Js.Json.string),
("connector_type", "payment_processor"->Js.Json.string),
("disabled", true->Js.Json.boolean),
("test_mode", true->Js.Json.boolean),
Expand Down

0 comments on commit d3ea8d7

Please sign in to comment.