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

Payment Stripe Error #34

Open
talmax1124 opened this issue Jul 16, 2022 · 3 comments
Open

Payment Stripe Error #34

talmax1124 opened this issue Jul 16, 2022 · 3 comments

Comments

@talmax1124
Copy link

Once, I set the payment, it shows this error:

Error: not allowed: {"response":{"errors":[{"message":"not allowed","extensions":{"code":"403","path":["orders"]}}],"data":{"orders":[]},"status":200},"request":{"query":"\n query OrderSessionIdQuery($id: String!) {\n orders(first: 1, stage: DRAFT, where: { stripeCheckoutId: $id }) {\n id\n orderItems {\n id\n product {\n images {\n id\n height\n url\n width\n }\n name\n }\n quantity\n total\n }\n total\n }\n }\n","variables":{"id":"cs_test_a1YNicvic2rA6IXuYzYBcSqcdZDT54w5XErQUolix5LSuLDeOrkO09FFq9"}}}

Screen Shot 2022-07-16 at 3 09 50 PM

I am thinking because I didn't setup the Stripe Webhook. I don't know how to do that.

@DanielAtCosmicDNA
Copy link

If the order creation mentioned at

await createOrder({ sessionId: event.data.object.id })
failed for any reason, querying the order with the resulting id from stripe API will not find a match in Hygraph database, therefore triggering the runtime error you mentioned.

I experienced exactly the same problem that seems to be associated with the version of the Stripe API because triggering the event checkout.session.completed results in the following error:

Failed to trigger event: checkout.session.completed. Trigger failed: Request failed, status=400, body={
  "error": {
    "message": "You cannot use `line_items.amount`, `line_items.currency`, `line_items.name`, `line_items.description`, or `line_items.images` in this API version. Please use `line_items.price` or `line_items.price_data`.",
    "type": "invalid_request_error"
  }
}

And looking at the Release Notes of the most recent Stripe API version, I noticed that:

The following parameters have been removed from create Checkout Session:
line_items[amount]
line_items[currency]
line_items[name]
line_items[description]
line_items[images]

This seems to indicate that the API version being used by the webhook needs to be downgraded to the previous version where this functionality might resume working.

@DanielAtCosmicDNA
Copy link

Updating the dependencies @stripe/stripe-js to 1.35.0, stripe to 10.0.0 in the package.json file and the Stripe CLI to 1.10.4, I was able to fix the order creation by using customer_details instead of customer in the file create-order.js.

The resulting code:

async function createOrder({ sessionId }) {
  const {
    customer_details,
    line_items,
    ...session
  } = await stripe.checkout.sessions.retrieve(sessionId, {
    expand: ['line_items.data.price.product', 'customer_details']
  })

  return await hygraphMutationClient.request(createOrderMutation, {
    order: {
      email: customer_details.email,
      total: session.amount_total,
      stripeCheckoutId: session.id,
      orderItems: {
        create: line_items.data.map((item) => ({
          quantity: item.quantity,
          total: item.amount_total,
          product: {
            connect: {
              id: item.price.product.metadata.productId
            }
          }
        }))
      }
    }
  })
}

Although the order creation in Hygraph database was fixed, the request from the line

} = await hygraphClient.request(getOrderSessionIdQuery, {
called by
const { order } = await getOrderBySessionId({ id: router.query.id })
fails with the error you mentioned.

If the same request is done directly within Hygraph playground, the graphql request succeeds though.

@DanielAtCosmicDNA
Copy link

I found out that this problem was being triggered because I was using a Hypergraph Permanent Auth Token without authorization to read from the API. After setting up the environment variable the correct public NEXT_PUBLIC_GRAPHCMS_TOKEN, it is now working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants