How to build an integration for your custom payment gateway to work with One Click Upsells?

Here is the Braintree gateway,
which should be really similar to the any other gateway:
https://www.dropbox.com/s/pi4zu9va8lo5fiy/gb-wc-1cu-braintree.php?dl=0
(you can use it as a framework/foundation for your gateway)

So, what needs to be done is this...

If you will evaluate the Braintree gateway's code,
you will find out that's the simple standard payment
gateway for WooCommerce, but with some additional methods:

  • "process_payment_short"
  • "get_customer_db"
  • "update_customer_db"

When customer purchases something, "get_customer_db"
checks if his email is in database (gb_ocu_customers table),
if not it creates the "customer" object using the gateway
API and saves his bank card details into this object,
get's back object's ID and adds it to the database
using "update_customer_db".

Next time if customer's email is found in the DB,
the saved data should be updated only if the card
has changed.

And finally "process_payment_short" uses the saved
customer's ID queried by his email, to charge
him for the 1 Click Upsell using the gateway's
API, without customer's additional confirmation.
‚Äč
Here is the DB table structure:

CREATE TABLE IF NOT EXISTS {$wpdb->gb_ocu_customers} ( id INT(9) AUTO_INCREMENT, gateway VARCHAR(255), customer_email VARCHAR(255), customer_id VARCHAR(255), user_id VARCHAR(255), order_id VARCHAR(255), meta TEXT, updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY (user_id), KEY (order_id) );