1

I am building a webshop for a client who makes use of drop shipping service. The customer can place the order on the website and the order will be send to the dropshipper automatically. This is done via a POST request by my server, a XML-code containing all the information about the order and is sent to the dropshipper.

This is what I know so far (but not sure how to execute):

  • The XML-code has to be sent via the POST method to an URL.
  • I need to use the correct API-key and have to make sure the XML structure is located within the “data” POST variable.
  • The POST variable “data” ($_POST[‘data’]) should contain the XML-code. All strings must be UTF-8 encoded.
  • It uses the "advanced output" (advanced), so you will receive a detailed output. The output is a JSON string, a string that can be converted into a PHP array of object easily, using the following PHP code: $outputarray = json_decode($output_string,true);

The JSON string always contains the key “result”. You should check the value of this key to find out whether your order request was successful or not. The value will be “OK” in the case your order was placed successfully, and “FAIL” is an error has occurred.

So it's possible to place orders automatically, via API (XML). However, this requires programming skills, and since my programming skills are still on a basic level, I am wondering if anyone is able to help me out :)

I can sent a test order to a special testaccount, test email and test API. This is my code so far:

<?php

// Configuration
$email = 'testorder@testaccount.nl';
$apikey = '123456789';

// API URL
$apiurl = 'https://www.testurl.nl/';

$xml = '<?xml version="1.0" encoding="UTF-8"?>
<orderdetails>
        <customerdetails>
            <email>'.$email.'</email>
            <apikey>'.$apikey.'</apikey>
            <output>advanced</output>
        </customerdetails>
        <receiver>
            <name>Test Person</name>
            <street>Test Street</street>
            <house_nr>24</house_nr>
            <postalcode>2628BL</postalcode>
            <city>Test city</city>
            <country>The Netherlands</country>
            <phone>+31633310000</phone>
        </receiver>
        <products>
            <artnr></artnr>
        </products>
</orderdetails>';

// Check whether the config vars are all set
if(empty($email) || empty($apikey)){
    die('Please enter your config vars');
}

// Check whether the cURL module has been installed
if(!function_exists('curl_init')){
    die('You do not have the cURL functions installed! Ask your host for more info.');
} else {

// Send the XML request
$postfields = 'data='.$xml;
$ch = curl_init($apiurl);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postfields);
$result = curl_exec($ch);
curl_close($ch);

if($ch === false || $result === false){
    die('There was a problem with the connection');
} else {
    $json = json_decode($result,true);

    // Success
    if($json['result'] == 'OK'){

        echo '<pre>';
        echo 'The order was successful. The following output was received:'.PHP_EOL;
        print_r($json);
        echo '</pre>';

    // Failure
    } else {
        echo '<pre>';
        echo 'There was a problem with the order request. The following output was received:'.PHP_EOL;
        print_r($json);
        echo '</pre>';
    }
}
}

?>

Of course I get a big FAIL while trying to run the test order.

Not sure if you need this information... But I am using the plugin WP All Export (http://www.wpallimport.com/export/), which allows me to easily sent XML files. In this plugin I have a XML editor and a Functions editor.

I sincerely hope anyone can help me figure this out!

closed as too broad by Mark Kaplun, cjbj, Howdy_McGee Aug 18 '17 at 3:15

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • sorry, but if programing skills are not your best feature, then for sure for such a thing you need to hire someone. – Mark Kaplun Aug 15 '17 at 9:07
  • Thank you for your reply. Yes, hiring someone would be my next step. – Celsa92 Aug 15 '17 at 9:41

Browse other questions tagged or ask your own question.