checkout-sdk-js icon indicating copy to clipboard operation
checkout-sdk-js copied to clipboard

Uncaught TypeError: Cannot read properties of undefined (reading 'bigpayBaseUrl')

Open garytsnaptravel opened this issue 3 years ago • 5 comments

Describe the bug Uncaught TypeError: Cannot read properties of undefined (reading 'bigpayBaseUrl') when calling await checkoutService.loadCheckout()

To Reproduce Steps to reproduce the behavior: Call this code from within an empty React component, where checkoutId is the cart ID from bc_cartId

useEffect(() => {
    const checkoutService = createCheckoutService()
    loadCheckout()
    async function loadCheckout() {
      const state = await checkoutService.loadCheckout(checkoutId)
    }

Expected behavior That I don't encounter this issue, because I am not looking to integrate with BigPay.

Screenshots (won't be of additional help) image

Desktop (please complete the following information): Desktop Chrome, Mac M1

Smartphone (please complete the following information): N/A

Additional context I'm basically following the https://github.com/bigcommerce/checkout-sdk-js#usage section. Is there any steps I might have missed, such as configuring environment variables?

garytsnaptravel avatar Oct 18 '21 19:10 garytsnaptravel

Hi @garytsnaptravel thanks for raising this. bigpayBaseUrl is a required config value under config here https://github.com/bigcommerce/checkout-sdk-js/blob/83f8f297eab4af8987dcf96f77c096d6e4a29e44/dist/checkout-sdk.d.ts#L5108 and https://github.com/bigcommerce/checkout-sdk-js/blob/83f8f297eab4af8987dcf96f77c096d6e4a29e44/dist/checkout-sdk.d.ts#L5842.

Out of curiosity can you please attach a screencast as to where and how you are trying to initialise the above component. Also can you check if there is a call to /api/storefront/checkout-settings endpoint is successful in the network team?

Also you have listed that you are using bc_cartId as checkoutId, I don't think they the same thing.

animesh1987 avatar Oct 20 '21 00:10 animesh1987

Hi @animesh1987, thank you for trying to help. This is the code for the whole page/component:

import { createCheckoutService } from '@bigcommerce/checkout-sdk'
import React, { useEffect, FC } from 'react'
interface Props {
  checkoutId?: string
}

const Checkout: FC<Props> = ({ checkoutId }) => {
  useEffect(() => {
    if (!checkoutId) return

    const checkoutService = createCheckoutService()

    loadCheckout()

    async function loadCheckout() {
      const state = await checkoutService.loadCheckout(checkoutId)
      console.log(state.data.getCart())
    }
  }, [checkoutId])

  return <h1>Test</h1>
}

export default Checkout

And this is the screenshot of the corresponding page: image

garytsnaptravel avatar Oct 20 '21 00:10 garytsnaptravel

I am aware that bigpayBaseUrl is part of those two interfaces, but I am confused where to pass in the config when I'm only calling createCheckoutService() or service.loadCheckout() - neither of the parameters expected have the store config or payment settings type expected.

Could you show a full example of how to pass in the bigPayBaseUrl explicitly but with dummy values?


I think bc_cartId, which is the cart ID, is synonymous with checkout ID. I'm not sure if this is causing the current issue though.


And yes, the /checkout-settings endpoint is called successfully: image

garytsnaptravel avatar Oct 20 '21 00:10 garytsnaptravel

So in the response of checkout-settings call you should have a paymentSettings with bigpayBaseUrl as a property Screen Shot 2021-10-20 at 3 55 41 pm (2)

Also fairly certain bc_cartId is not the checkoutId.

animesh1987 avatar Oct 20 '21 05:10 animesh1987

@animesh1987 , I see what you mean now - the /api/storefront/checkout-settings request was returning a "not found" page, but this means I have to implement my own backend API for that to return the store config - which I wouldn't know what to fill in anyway.

Nothing in the docs suggests anything about this part of the setup, so this is a very poor developer experience so far and not something one could have figured out on their own. I think I will try using the checkout APIs as well instead of messing with this SDK.

garytsnaptravel avatar Oct 24 '21 22:10 garytsnaptravel