News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Communicate with external API on order confirmed

Started by Marttyn, October 04, 2022, 12:23:12 PM

Previous topic - Next topic

Marttyn

Hi!
There is a website that can plant trees on behalf of your customer for every order, or for every product they buy. They have plugins for some online shops, but not for VM.
It only cost 0.15€ per tree! So its very affordable, it can generate a good impact on the environment, and its also nice for your customer. I think its a great idea!

I would like to plant a tree on every order. Ive been checking the API and its very simple, only one JSON with very few fields:
https://documenter.getpostman.com/view/6643991/S17m1X5P#auth-info-c42e4c98-1dc2-4eec-a451-f69695b1dfca

<?php

$curl 
curl_init();

curl_setopt_array($curl, array(
  
CURLOPT_URL => 'https://tree-nation.com/api/plant',
  
CURLOPT_RETURNTRANSFER => true,
  
CURLOPT_ENCODING => '',
  
CURLOPT_MAXREDIRS => 10,
  
CURLOPT_TIMEOUT => 0,
  
CURLOPT_FOLLOWLOCATION => true,
  
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  
CURLOPT_CUSTOMREQUEST => 'POST',
  
CURLOPT_POSTFIELDS =>'{
"recipients": [
{
"name": "test user",
"email": "test875349@test.com"
}
],
"planter_id": 2,
"species_id": 17,
"quantity": 2
}'
,
  
CURLOPT_HTTPHEADER => array(
    
'Content-Type: application/json'
  
),
));

$response curl_exec($curl);

curl_close($curl);
echo 
$response;


I was about to code this on the order confirmation page, after checkout... But then I realized that all orders that are not confirmed on checkout (bank transfer for example), orders created manually or order that update the status manually or asycronally will not plant a tree.
So i think to create a simple plugin would be the correct thing to do. Triggering on order status change.
Is there anyone interested on a project like this? I could sponsor with some money the creation of this plugin  ;D