Wp-graphql-woocommerce: Checkout mutation payload contains WooCommerce error HTML and breaks JSON

Created on 24 Apr 2020  ·  7Comments  ·  Source: wp-graphql/wp-graphql-woocommerce

Describe the bug
I've encountered a strange bug that only happens on one of my sites. When running the checkout mutation WooCommerce seems to output some errror HTML in payload and thus breaks the JSON formatting.

To Reproduce
Steps to reproduce the behavior:

  1. Run the checkout mutation
  2. Order gets created in WooCommerce dashboard
  3. Network error is returned and the function does not finish, can't run any functions in the callback and response comes back as undefined.

Expected behavior
Order should be created in WooCommerce and response data should be given

Screenshots
image-1

bug help wanted needs more discussion

All 7 comments

Okay it seems one particular payment gateway is issuing the alert. Have to do some further investigations.

After further investigation it seems my gateway is making an API request upon order creation. It's using a custom meta orderId that at the time of the request is NULL. Does woocommerce-graphql first create/process the order and then add the meta fields? I suspect the custom meta value is not available when the request is made.

_Edit:_ After some digging it seems this is the case. @kidunot89 Are there ways of making sure meta values are added before the order is processed? WooCommerce own order creation api wrapper adds the meta values before processing the order and since switching to the WooCommerce-GraphQL checkout mutation it's not working anymore.

@zamson here are the steps of the checkout mutation.

  1. Process input values.
  2. Create order
  3. Add meta to the new order
  4. Process payment.
  5. Return newly created order, payment processing results, and the redirect url.

If your gateway requires meta, you can use the metaData input field to add the meta, and it will be available when the gateway's process_payment function is called.

Also note, that in release v0.5.1, the graphql_{$payment_method}_process_payment_args filter has been added. The process_payment() requires only one parameter be set, the order_id, however some payment gateways may accept optional parameters alter the payment gateway behavior. The graphql_{$payment_method}_process_payment_args can be used to pass those optional.
For an example take a look at the graphql_stripe_process_payment_args.

I'm already supplying the meta values in the input of the checkout mutation.

The payments processes without problem when testing with a WP theme in WP and same gateway. I've also made sure the values are present and the same as a normal WP order, so I'm still thinking the value is not there when my gateway receives the order.

Screenshot 2020-04-27 at 20 54 48

I'll make sure to checkout 0.5.1 and the filter.

:thinking: I'll have to look into the Klarna payment gateway.

Btw, it says paymentMethod: cod in my screenshot, but this was just temporary. When testing it was set to "kco".

After some more digging in the Klarna code I realised my mistake. I had isPaid: false, Klarna Payment Gateway needed this to be isPaid: true (since payment is already confirmed... 🤦‍♂️)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricokahler picture ricokahler  ·  5Comments

IRediTOTO picture IRediTOTO  ·  4Comments

mehidi258 picture mehidi258  ·  3Comments

jacobarriola picture jacobarriola  ·  5Comments

zamson picture zamson  ·  4Comments