Skip to content
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

fix: paypal flow fixed for one click handler #711

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 68 additions & 68 deletions src/Payments/PaypalSDKHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ let loadPaypalSDK = (
~eventName=PAYPAL_SDK_FLOW,
~paymentMethod="PAYPAL",
)
Utils.makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)
->then(result => {
let result = result->JSON.Decode.bool->Option.getOr(false)
if result {
let paypalWrapper = GooglePayType.getElementById(Utils.document, "paypal-button")
paypalWrapper.innerHTML = ""
setIsCompleted(_ => true)
paypal["Buttons"]({
style: buttonStyle,
fundingSource: paypal["FUNDING"]["PAYPAL"],
createOrder: () => {
let paypalWrapper = GooglePayType.getElementById(Utils.document, "paypal-button")
paypalWrapper.innerHTML = ""
setIsCompleted(_ => true)
paypal["Buttons"]({
style: buttonStyle,
fundingSource: paypal["FUNDING"]["PAYPAL"],
createOrder: () => {
Utils.makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)->then(result => {
let result = result->JSON.Decode.bool->Option.getOr(false)
if result {
Utils.messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("param", "paymentloader"->JSON.Encode.string),
Expand All @@ -63,68 +62,69 @@ let loadPaypalSDK = (
~manualRetry=isManualRetryEnabled,
)
})
},
onApprove: (_data, actions) => {
if !options.readOnly {
actions.order.get()
->then(val => {
let purchaseUnit =
val
->Utils.getDictFromJson
->Utils.getArray("purchase_units")
->Array.get(0)
->Option.flatMap(JSON.Decode.object)
->Option.getOr(Dict.make())
let payerDetails =
val
->Utils.getDictFromJson
->Dict.get("payer")
->Option.flatMap(JSON.Decode.object)
->Option.getOr(Dict.make())
->PaymentType.itemToPayerDetailsObjectMapper
} else {
resolve("")
}
})
},
onApprove: (_data, actions) => {
if !options.readOnly {
actions.order.get()
->then(val => {
let purchaseUnit =
val
->Utils.getDictFromJson
->Utils.getArray("purchase_units")
->Array.get(0)
->Option.flatMap(JSON.Decode.object)
->Option.getOr(Dict.make())
let payerDetails =
val
->Utils.getDictFromJson
->Dict.get("payer")
->Option.flatMap(JSON.Decode.object)
->Option.getOr(Dict.make())
->PaymentType.itemToPayerDetailsObjectMapper

let details = purchaseUnit->paypalShippingDetails(payerDetails)
let requiredFieldsBody = DynamicFieldsUtils.getPaypalRequiredFields(
~details,
~paymentMethodTypes,
~statesList=stateJson,
)
let details = purchaseUnit->paypalShippingDetails(payerDetails)
let requiredFieldsBody = DynamicFieldsUtils.getPaypalRequiredFields(
~details,
~paymentMethodTypes,
~statesList=stateJson,
)

let bodyArr =
requiredFieldsBody
->JSON.Encode.object
->Utils.unflattenObject
->Utils.getArrayOfTupleFromDict
let bodyArr =
requiredFieldsBody
->JSON.Encode.object
->Utils.unflattenObject
->Utils.getArrayOfTupleFromDict

completeAuthorize(
~bodyArr,
~confirmParam={
return_url: options.wallets.walletReturnUrl,
publishableKey,
},
~handleUserError=true,
)
completeAuthorize(
~bodyArr,
~confirmParam={
return_url: options.wallets.walletReturnUrl,
publishableKey,
},
~handleUserError=true,
)

resolve()
})
->ignore
}
},
onCancel: _data => {
handleCloseLoader()
},
onError: _err => {
handleCloseLoader()
},
}).render("#paypal-button")
areOneClickWalletsRendered(prev => {
...prev,
isPaypal: true,
})
}
resolve()
resolve()
})
->ignore
}
},
onCancel: _data => {
handleCloseLoader()
},
onError: _err => {
handleCloseLoader()
},
}).render("#paypal-button")
areOneClickWalletsRendered(prev => {
...prev,
isPaypal: true,
})
->ignore
resolve()->ignore
}

let loadBraintreePaypalSdk = (
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ let makeOneClickHandlerPromise = sdkHandleOneClickConfirmPayment => {
resolve(JSON.Encode.bool(true))
} else {
let handleMessage = (event: Types.event) => {
let json = event.data->anyTypeToJson->getStringFromJson("")->safeParse
let json = event.data->anyTypeToJson

let dict = json->getDictFromJson
if dict->Dict.get("oneClickDoSubmit")->Option.isSome {
Expand Down
Loading