export async function processPayment()

in src/frontend/src/store/bookings/payment.js [28:68]


export async function processPayment({
  paymentToken,
  outboundFlight,
  customerEmail
}) {
  console.group('store/bookings/actions/processPayment')
  Loading.show({
    message: 'Processing payment...'
  })

  if (!paymentToken) throw 'Invalid payment token'

  const chargeData = {
    amount: outboundFlight.ticketPrice,
    currency: outboundFlight.ticketCurrency,
    stripeToken: paymentToken.details.id,
    description: `Payment by ${customerEmail}`,
    email: customerEmail
  }

  console.log('Charge data to be processed')
  console.log(chargeData)
  try {
    const data = await axios.post(paymentEndpoint, chargeData)
    const {
      data: {
        createdCharge: { id: chargeId }
      }
    } = data

    Loading.show({
      message: 'Payment authorized successfully...'
    })

    console.groupEnd()
    return chargeId
  } catch (err) {
    console.error(err)
    throw new Error(err)
  }
}