Jay
Jay

Reputation: 257

How to handle payments with Wordpress WooCommerce Mollie REST API

I am wondering how to implement payments in Flutter(or any other framework, like react or angular). There is an existing website built in Wordpress and WooCommerce. The following plugin is used:

How can I handle a payment, that matches the order id and moves the user to the payment banking screen?

When a user presses the "Checkout" button in the frontend, do I need to do the following?

  1. Call a custom function that was made in Wordpress PHP (wp-json/payment/create)
  2. Call the woocommerce endpoint create order in that PHP function. https://woocommerce.github.io/woocommerce-rest-api-docs/#create-an-order.
  3. And then call the mollie endpoint create payment in that PHP function? https://docs.mollie.com/reference/v2/payments-api/create-payment. Put order id in parameters that I received from the woocommerce endpoint.
  4. Then return the redirect link to the react or flutter app
  5. How can I know that the payment is succesful? Then I can call 'update order' and set the status from 'waiting for payment' to 'processing order'. (So Wordpress admin can see that the customer paid.

I could not find a tutorial on this topic and therefore I decided to make this question public. I only saw wordpress tutorials... So I hope this question can help a lot of people.

Upvotes: 1

Views: 1581

Answers (1)

Humpff
Humpff

Reputation: 328

How far are you with this? Because I don't know if using the regular mollie plugin is going to help out.

Mollie has documentation on how to also implement their api on JS framework.

The question you need to answer first is:

  • Are you able to create an order using the WooCommerce API. So can you order a product, without actually using a payment gateway (the add to cart to checkout flow)?
  • Have you tried using the Mollie nodejs version?

A tip: Any payment gateway(stripe, mollie etc) add the order_id as meta_data on a order. So after going through the payment flow the order has to be created, with the right payment_id + the status (failed, pending blabla).

Edit:

Another option could be to create custom endpoints which loads something like this: https://github.com/mollie/mollie-api-php

So maybe something like:

  1. create the order using the woocommerce api
  2. after creating the order, return to the js app and then trigger another endpoint
  3. this endpoint would load the custom Mollie api

I hope this makes sense?

Upvotes: 0

Related Questions