We have an app built on Firebase and our customers purchase a subscription to our app via our website.
What we would ideally like to do is once the order is placed, send the following:
ID - primary key. This is generated using the order number from WooCommerce
card_number - string. This is the order number prefixed with #VIP (e.g #VIP12345). This is needed because of a legacy setup when we first launched. Hopefully it'll be phased out soon.
forename - string
surname - string
user_id - always an empty string. This is completed when the user first signs in.
email - string
expiry - int. The cards expiry date formatted as an epoch
business_reward_admin - always the string 'FALSE'
business_reward_user - always the string 'FALSE'
business_reward_id - always an empty string
Does anyone have any expirence with this type of integration?
We don't need 2 way syncing at the moment, but will be working on that later on once we work this bit out.
Basically just need the order_id, first_name, last_name, email and the order_date + 365 days for the expiry - to be sent to the database when the order is completed/thank you page.
Thanks, Kyle
EDIT:
I would like to do something like this - but haven't written CURL before - so apologies if completely wrong.
<?php
add_action('woocommerce_payment_complete', 'bnd_firebase_realtime_put', 10, 1);
function bnd_firebase_realtime_put ($order_id) {
$order = new WC_Order( $order_id );
// Loop through cart items
foreach( $order->get_items() as $item ){
// Get the Product ID
$order_id = trim( str_replace( '#', '', $order->get_id() ) );
// Get Users First Name
$firstname = $order->get_billing_first_name();
// Get Users Last Name
$lastname = $order->get_billing_last_name();
// Get Users Email Address
$email = $order->billing_email;
//Epoch Time + 365 days in Epoch time
$expiry = time() + 31556926;
//Get Product ID Number
$product_id = $item->get_product_id();
//Get Firebase Project ID number from Product Meta
$project_id = get_post_meta($product_id,'project_id', true);
//Get Firebase Access Token from Product Meta
$access_token = get_post_meta($product_id,'access_token', true);
curl -X PUT -d '{ "ID" : "'. $order_id . '", "card_number" : "#VIP'. $order_id . '" , "forename" : "' . $firstname .'" , "lastname" : "'. $lastname .'" , "email" : "' . $email . '" , "expiry" : "' . $expiry .'" }' \ 'https://'. $project_id .'.firebaseio.com/users.json?access_token=' . $access_token .'
}
}
?>