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

Checkout mutation payload contains WooCommerce error HTML and breaks JSON #265

Closed
zamson opened this issue Apr 24, 2020 · 7 comments
Closed
Labels
bug Something isn't working help wanted Extra attention is needed needs more discussion This PR needs more discussion before approval

Comments

@zamson
Copy link

zamson commented Apr 24, 2020

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

@zamson
Copy link
Author

zamson commented Apr 24, 2020

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

@zamson
Copy link
Author

zamson commented Apr 27, 2020

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.

@kidunot89
Copy link
Member

kidunot89 commented Apr 27, 2020

@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.

@zamson
Copy link
Author

zamson commented Apr 27, 2020

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.

@kidunot89
Copy link
Member

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

@zamson
Copy link
Author

zamson commented Apr 27, 2020

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

@kidunot89 kidunot89 added bug Something isn't working needs more discussion This PR needs more discussion before approval help wanted Extra attention is needed labels Apr 30, 2020
@zamson
Copy link
Author

zamson commented May 3, 2020

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... 🤦‍♂️)

@zamson zamson closed this as completed May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed needs more discussion This PR needs more discussion before approval
Projects
None yet
Development

No branches or pull requests

2 participants