Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Open
Changes from all 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
12 changes: 6 additions & 6 deletions shop/src/components/payment/PayPal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import useCurrencyOpts from 'utils/useCurrencyOpts'
const PayPal = ({ onChange, loading, encryptedData, submit, disabled }) => {
const { config } = useConfig()
const [{ cart }, dispatch] = useStateValue()

const { post } = useBackendApi({ authToken: true })

const currencyOpts = useCurrencyOpts()
Expand All @@ -30,8 +29,10 @@ const PayPal = ({ onChange, loading, encryptedData, submit, disabled }) => {
const isSelected = get(cart, 'paymentMethod.id') === 'paypal'
const paypalPaymentMethod = paymentMethods.find((o) => o.id === 'paypal')

const match = useRouteMatch('/checkout/payment/:intentId?')
const { intentId } = match.params
const match = useRouteMatch('/checkout/payment/:parameters?')
const { parameters } = match.params
// `parameters` may contain information we don't need. Therefore, we should filter it.
const intentId = parameters ? parameters.slice(0, 32) : null

const createOrderAndRedirect = async () => {
onChange({
Expand All @@ -50,7 +51,7 @@ const PayPal = ({ onChange, loading, encryptedData, submit, disabled }) => {

try {
const randomKey = randomstring.generate()
const returnUrl = `${window.location.origin}${window.location.pathname}#/checkout/payment/${randomKey}`
const returnUrl = `${window.location.origin}${window.location.pathname}${window.location.search}#/checkout/payment/${randomKey}`
const { authorizeUrl, orderId } = await post('/paypal/pay', {
body: JSON.stringify({
amount: (cart.total / 100).toFixed(2),
Expand All @@ -62,7 +63,6 @@ const PayPal = ({ onChange, loading, encryptedData, submit, disabled }) => {
currency: config.currency
})
})

window.location = authorizeUrl
localStorage[`paymentIntent${randomKey}`] = JSON.stringify({
hash: encryptedData.hash,
Expand All @@ -73,7 +73,7 @@ const PayPal = ({ onChange, loading, encryptedData, submit, disabled }) => {

return
} catch (err) {
console.error(err)
console.error(`Could not create order using Paypal. `, err)
setError(
fbt(
'Something went wrong. Please try again later.',
Expand Down