Skip to content

Commit

Permalink
Merge branch 'main' into fix/klarna_cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored May 30, 2024
2 parents 545943d + cc00bb0 commit 1a0cf04
Show file tree
Hide file tree
Showing 14 changed files with 503 additions and 133 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## [0.57.1](https://github.com/juspay/hyperswitch-web/compare/v0.57.0...v0.57.1) (2024-05-30)


### Bug Fixes

* hide terms based upon prop ([#408](https://github.com/juspay/hyperswitch-web/issues/408)) ([8a5d554](https://github.com/juspay/hyperswitch-web/commit/8a5d5548d70750725a61381abf4fa68879fa4746))

# [0.57.0](https://github.com/juspay/hyperswitch-web/compare/v0.56.1...v0.57.0) (2024-05-30)


### Bug Fixes

* fixed ApplePay Event Handler ([#406](https://github.com/juspay/hyperswitch-web/issues/406)) ([bfc7470](https://github.com/juspay/hyperswitch-web/commit/bfc747010c6a5c891d0d93e7ce9dbbcdd8980e07))


### Features

* added PayPal SDK Via PayPal ([#404](https://github.com/juspay/hyperswitch-web/issues/404)) ([084932d](https://github.com/juspay/hyperswitch-web/commit/084932d644cc4f7da9aebe124e069e97ee14476b))

## [0.56.1](https://github.com/juspay/hyperswitch-web/compare/v0.56.0...v0.56.1) (2024-05-27)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orca-payment-page",
"version": "0.56.1",
"version": "0.57.1",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ let make = (
<SaveDetailsCheckbox isChecked=isSaveCardsChecked setIsChecked=setIsSaveCardsChecked />
</div>
</RenderIf>
<RenderIf condition={paymentMethodListValue.payment_type === SETUP_MANDATE}>
<RenderIf
condition={displaySavedPaymentMethodsCheckbox &&
paymentMethodListValue.payment_type === SETUP_MANDATE}>
<div
className="opacity-50 text-xs mb-2 text-left"
style={
Expand Down
1 change: 0 additions & 1 deletion src/Payments/Boleto.res
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ let make = (~paymentType: CardThemeType.mode) => {
~iframeId,
(),
)
()
} 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 @@ -355,7 +355,7 @@ let make = (
<RenderIf condition={showFields || isBancontact}>
<Surcharge paymentMethod paymentMethodType cardBrand={cardBrand->CardUtils.getCardType} />
</RenderIf>
<RenderIf condition={!isBancontact}>
<RenderIf condition={displaySavedPaymentMethodsCheckbox && !isBancontact}>
{switch (
paymentMethodListValue.mandate_payment,
options.terms.card,
Expand Down
175 changes: 61 additions & 114 deletions src/Payments/PaypalSDK.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open PaypalSDKTypes
open Promise

@react.component
let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) => {
Expand All @@ -13,6 +12,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
let token = sessionObj.token
let orderDetails = sessionObj.orderDetails->getOrderDetails(paymentType)
let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Paypal)
let completeAuthorize = PaymentHelpers.useCompleteAuthorize(Some(loggerState), Paypal)
let checkoutScript =
Window.document(Window.window)->Window.getElementById("braintree-checkout")->Nullable.toOption
let clientScript =
Expand Down Expand Up @@ -51,123 +51,70 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =

PaymentUtils.useStatesJson(setStatesJson)

let loadPaypalSdk = () => {
loggerState.setLogInfo(
~value="Paypal SDK Button Clicked",
~eventName=PAYPAL_SDK_FLOW,
~paymentMethod="PAYPAL",
(),
)
Utils.makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)
->then(result => {
let result = result->JSON.Decode.bool->Option.getOr(false)
if result {
braintree.client.create({authorization: token}, (clientErr, clientInstance) => {
if clientErr {
Console.error2("Error creating client", clientErr)
}
braintree.paypalCheckout.create(
{client: clientInstance},
(paypalCheckoutErr, paypalCheckoutInstance) => {
switch paypalCheckoutErr->Nullable.toOption {
| Some(val) => Console.warn(`INTEGRATION ERROR: ${val.message}`)
| None => ()
}
paypalCheckoutInstance.loadPayPalSDK(
{vault: true},
() => {
let paypalWrapper = GooglePayType.getElementById(Utils.document, "paypal-button")
paypalWrapper.innerHTML = ""
paypal["Buttons"]({
style: buttonStyle,
fundingSource: paypal["FUNDING"]["PAYPAL"],
createBillingAgreement: () => {
//Paypal Clicked
Utils.handlePostMessage([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
])
options.readOnly ? () : paypalCheckoutInstance.createPayment(orderDetails)
},
onApprove: (data, _actions) => {
options.readOnly
? ()
: paypalCheckoutInstance.tokenizePayment(
data,
(_err, payload) => {
let (connectors, _) =
paymentMethodListValue->PaymentUtils.getConnectors(
Wallets(Paypal(SDK)),
)
let body = PaymentBody.paypalSdkBody(
~token=payload.nonce,
~connectors,
)

let requiredFieldsBody = DynamicFieldsUtils.getPaypalRequiredFields(
~details=payload.details,
~paymentMethodTypes,
~statesList=stateJson,
)

let paypalBody =
body
->Utils.getJsonFromArrayOfJson
->Utils.flattenObject(true)
->Utils.mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->Utils.getArrayOfTupleFromDict

let modifiedPaymentBody = PaymentUtils.appendedCustomerAcceptance(
~isGuestCustomer,
~paymentType=paymentMethodListValue.payment_type,
~body=paypalBody,
)

intent(
~bodyArr=modifiedPaymentBody,
~confirmParam={
return_url: options.wallets.walletReturnUrl,
publishableKey,
},
~handleUserError=true,
(),
)
},
)
},
onCancel: _data => {
handleCloseLoader()
},
onError: _err => {
handleCloseLoader()
},
}).render("#paypal-button")
areOneClickWalletsRendered(
prev => {
...prev,
isPaypal: true,
},
)
},
)
},
)
})->ignore
}
resolve()
let mountPaypalSDK = () => {
let clientId = sessionObj.token
let paypalScriptURL = `https://www.paypal.com/sdk/js?client-id=${clientId}&components=buttons,hosted-fields`
loggerState.setLogInfo(~value="PayPal SDK Script Loading", ~eventName=PAYPAL_SDK_FLOW, ())
let paypalScript = Window.createElement("script")
paypalScript->Window.elementSrc(paypalScriptURL)
paypalScript->Window.elementOnerror(exn => {
let err = exn->Identity.anyTypeToJson->JSON.stringify
loggerState.setLogError(
~value=`Error During Loading PayPal SDK Script: ${err}`,
~eventName=PAYPAL_SDK_FLOW,
(),
)
})
paypalScript->Window.elementOnload(_ => {
loggerState.setLogInfo(~value="PayPal SDK Script Loaded", ~eventName=PAYPAL_SDK_FLOW, ())
PaypalSDKHelpers.loadPaypalSDK(
~loggerState,
~sdkHandleOneClickConfirmPayment,
~buttonStyle,
~iframeId,
~paymentMethodListValue,
~isGuestCustomer,
~intent,
~options,
~publishableKey,
~paymentMethodTypes,
~stateJson,
~completeAuthorize,
~handleCloseLoader,
~areOneClickWalletsRendered,
)
})
->ignore
Window.body->Window.appendChild(paypalScript)
}

React.useEffect(() => {
try {
switch (
checkoutScript,
clientScript,
stateJson->Identity.jsonToNullableJson->Js.Nullable.isNullable,
) {
| (Some(_), Some(_), false) => loadPaypalSdk()
| (_, _, _) => Utils.logInfo(Console.log("Error loading Paypal"))
if stateJson->Identity.jsonToNullableJson->Js.Nullable.isNullable->not {
switch sessionObj.connector {
| "paypal" => mountPaypalSDK()
| _ =>
switch (checkoutScript, clientScript) {
| (Some(_), Some(_)) =>
PaypalSDKHelpers.loadBraintreePaypalSdk(
~loggerState,
~sdkHandleOneClickConfirmPayment,
~token,
~buttonStyle,
~iframeId,
~paymentMethodListValue,
~isGuestCustomer,
~intent,
~options,
~orderDetails,
~publishableKey,
~paymentMethodTypes,
~stateJson,
~handleCloseLoader,
~areOneClickWalletsRendered,
)
| _ => ()
}
}
}
} catch {
| _err => Utils.logInfo(Console.log("Error loading Paypal"))
Expand Down
Loading

0 comments on commit 1a0cf04

Please sign in to comment.