Skip to content

Commit

Permalink
fix: added a callback in the usePaymentIntent
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed May 29, 2024
1 parent 944ece0 commit 0c76d24
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let make = (
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)->ignore
)
} else {
if isUnknownPaymentMethod || confirm.confirmTimestamp < confirm.readyTimestamp {
setUserError(localeString.selectPaymentMethodText)
Expand Down
2 changes: 1 addition & 1 deletion src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
}

let submitAPICall = (body, confirmParam) => {
intent(~bodyArr=body, ~confirmParam, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam, ~handleUserError=false, ())
}
React.useEffect(() => {
setCvcNumber(_ => "")
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~state=state.value,
~paymentType=paymentMethodListValue.payment_type,
)
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
| None => ()
}
()
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~handleUserError=false,
~iframeId,
(),
)->ignore
)
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let make = (~sessionObj: option<JSON.t>) => {
~handleUserError=true,
~isThirdPartyFlow,
(),
)->ignore
)
}

let syncPayment = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~country=getCountryCode(country.value).isoAlpha2,
~bankAccountHolderName=fullName.value,
)
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
()
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BacsBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let default = (paymentType: CardThemeType.mode) => {
~handleUserError=false,
~iframeId,
(),
)->ignore
)
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/BecsBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~postalCode=postalCode.value,
~state=state.value,
)
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
}
| None => ()
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/Boleto.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~handleUserError=false,
~iframeId,
(),
)->ignore
)
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let make = (
~confirmParam=confirm.confirmParams,
~handleUserError=false,
(),
)->ignore
)
} else {
if cardNumber === "" {
setCardError(_ => localeString.cardNumberEmptyText)
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
~handleUserError=true,
~isThirdPartyFlow,
(),
)->ignore
)
}

let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList(
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let make = (~paymentType) => {
)
if confirm.doSubmit {
if complete {
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/KlarnaSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let make = (~sessionObj: SessionsType.token) => {
paymentMethodListValue->PaymentUtils.getConnectors(PayLater(Klarna(SDK)))
let body = PaymentBody.klarnaSDKbody(~token=res.authorization_token, ~connectors)
res.approved
? intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
? intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
: handleCloseLoader()
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PayPal.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let make = () => {
},
~handleUserError=true,
(),
)->ignore
)
} else {
setPaypalClicked(_ => false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
~handleUserError=false,
~iframeId,
(),
)->ignore
)
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
24 changes: 14 additions & 10 deletions src/Payments/PaypalSDKHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ let loadPaypalSDK = (
~paymentType=paymentMethodListValue.payment_type,
~body,
)
intent(
~bodyArr=modifiedPaymentBody,
~confirmParam={
return_url: options.wallets.walletReturnUrl,
publishableKey,
},
~handleUserError=true,
(),
)->then(val => val->Utils.getDictFromJson->Utils.getString("orderId", "")->resolve)
Promise.make((resolve, _) => {
intent(
~bodyArr=modifiedPaymentBody,
~confirmParam={
return_url: options.wallets.walletReturnUrl,
publishableKey,
},
~handleUserError=true,
~intentCallback=val =>
val->Utils.getDictFromJson->Utils.getString("orderId", "")->resolve,
(),
)
})
},
onApprove: (_data, actions) => {
if !options.readOnly {
Expand Down Expand Up @@ -210,7 +214,7 @@ let loadBraintreePaypalSdk = (
},
~handleUserError=true,
(),
)->ignore
)
},
)
},
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/SepaBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let make = (~paymentType: CardThemeType.mode) => {
~postalCode=postalCode.value,
~state=state.value,
)
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())->ignore
intent(~bodyArr=body, ~confirmParam=confirm.confirmParams, ~handleUserError=false, ())
}
| None => ()
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/SepaBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let make = (~paymentType) => {
~handleUserError=false,
~iframeId,
(),
)->ignore
)
} else {
postFailedSubmitResponse(~errortype="validation_error", ~message="Please enter all fields")
}
Expand Down
17 changes: 10 additions & 7 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ let closePaymentLoaderIfAny = () => handlePostMessage([("fullscreen", false->JSO

type paymentIntent = (
~handleUserError: bool=?,
~bodyArr: array<(string, RescriptCore.JSON.t)>,
~bodyArr: array<(string, JSON.t)>,
~confirmParam: ConfirmType.confirmParams,
~iframeId: string=?,
~isThirdPartyFlow: bool=?,
~intentCallback: Core__JSON.t => unit=?,
unit,
) => RescriptCore.Promise.t<Core__JSON.t>
) => unit

type completeAuthorize = (
~handleUserError: bool=?,
~bodyArr: array<(string, RescriptCore.JSON.t)>,
~bodyArr: array<(string, JSON.t)>,
~confirmParam: ConfirmType.confirmParams,
~iframeId: string=?,
unit,
Expand Down Expand Up @@ -997,6 +998,7 @@ let usePaymentIntent = (optLogger, paymentType) => {
~confirmParam: ConfirmType.confirmParams,
~iframeId=keys.iframeId,
~isThirdPartyFlow=false,
~intentCallback=_ => (),
(),
) => {
switch keys.clientSecret {
Expand Down Expand Up @@ -1069,7 +1071,6 @@ let usePaymentIntent = (optLogger, paymentType) => {
}
if blockConfirm && Window.isInteg {
Console.log3("CONFIRM IS BLOCKED", body->JSON.parseExn, headers)
JSON.Encode.null->resolve
} else {
intentCall(
~fetchApi,
Expand All @@ -1089,6 +1090,11 @@ let usePaymentIntent = (optLogger, paymentType) => {
~counter=0,
(),
)
->then(val => {
intentCallback(val)
resolve()
})
->ignore
}
}

Expand Down Expand Up @@ -1143,22 +1149,19 @@ let usePaymentIntent = (optLogger, paymentType) => {
~message="Payment Failed. Try again!",
)
Console.warn("Please enable atleast one Payment method.")
JSON.Encode.null->resolve
}
| SemiLoaded => intentWithoutMandate("")
| _ =>
postFailedSubmitResponse(
~errortype="payment_methods_loading",
~message="Please wait. Try again!",
)
JSON.Encode.null->resolve
}
| None =>
postFailedSubmitResponse(
~errortype="confirm_payment_failed",
~message="Payment failed. Try again!",
)
JSON.Encode.null->resolve
}
}
}
Expand Down

0 comments on commit 0c76d24

Please sign in to comment.