From 3794f07e542d22cfd0e2fd3bc48585a7f7c706a3 Mon Sep 17 00:00:00 2001 From: Hendrik Bahr Date: Tue, 13 Oct 2020 00:45:03 +0200 Subject: [PATCH 01/11] Add php example script for getOrders --- php/getStocks.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 php/getStocks.php diff --git a/php/getStocks.php b/php/getStocks.php new file mode 100644 index 0000000..300ddee --- /dev/null +++ b/php/getStocks.php @@ -0,0 +1,47 @@ + + */ + +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Get data from REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/stock/?channel=" . $sChannelId; +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_HEADER, 0); +curl_setopt($oCurl, CURLOPT_BINARYTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_TIMEOUT, 82800); // 23 hours +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +curl_close($oCurl); + +/* + * Process data as you need + */ +$oXml = simplexml_load_string($sResponse); +if ($oXml && $oXml->ARTICLE) { + foreach ($oXml->ARTICLE as $oProduct) { + echo (string)$oProduct->A_NR . ": " . (string)$oProduct->A_STOCK . PHP_EOL; + } +} else { + print_r($sResponse); +} From 4642607513a435245e202e11846049cd4b2f16b9 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Mon, 9 Nov 2020 15:09:53 +0100 Subject: [PATCH 02/11] 0067954 adding examples all cases (#1) * 0067954 - adding getArticlesFull * 0067954 - Adding getArticlesDelta example * 0067954 - Adding getArticlesDelta example * 0067954 - setting curl timeout to one hour * 0067954 - Adding example for get (and confirm) Orders * 0067954 - Adding getOrderMessages example * 0067954 Added call example for Set Stocks * 0067954 Adding SetOrder file and minor adjustments * 0067954 Adding SetOrderMessages file and adjustments to setOrder so they have the similar templates * 0067954 - Excluding some optional fields * 0067954 - Rename files * 0067954 - Adding Send Articles * 0067954 - Adding comments to "send" files and correcting the ones for orders * 0067954 - Correction to the url response after receiving order messages --- php/getArticlesDelta.php | 58 ++++++++++++++++++++ php/getArticlesFull.php | 55 +++++++++++++++++++ php/getOrder.php | 110 ++++++++++++++++++++++++++++++++++++++ php/getOrderMessages.php | 84 +++++++++++++++++++++++++++++ php/getStocks.php | 3 +- php/sendArticle.php | 84 +++++++++++++++++++++++++++++ php/sendOrder.php | 85 +++++++++++++++++++++++++++++ php/sendOrderMessages.php | 54 +++++++++++++++++++ php/sendStocks.php | 58 ++++++++++++++++++++ 9 files changed, 589 insertions(+), 2 deletions(-) create mode 100644 php/getArticlesDelta.php create mode 100644 php/getArticlesFull.php create mode 100644 php/getOrder.php create mode 100644 php/getOrderMessages.php create mode 100644 php/sendArticle.php create mode 100644 php/sendOrder.php create mode 100644 php/sendOrderMessages.php create mode 100644 php/sendStocks.php diff --git a/php/getArticlesDelta.php b/php/getArticlesDelta.php new file mode 100644 index 0000000..a456fce --- /dev/null +++ b/php/getArticlesDelta.php @@ -0,0 +1,58 @@ + + */ + +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Get data from REST API with curl + */ + +$iDelta = time() - (3600 * 12); //Get the delta for last 12 hours (current time minus 12 hours) +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/products/?channel=" . $sChannelId . '&delta=' . $iDelta; + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_HEADER, 0); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +curl_close($oCurl); + +/* + * Process data as you need + */ +$oXml = simplexml_load_string($sResponse); +if ($oXml && $oXml->PRODUCTDATA) { + + if ($oXml->SUPPLIER){ + echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; + } + + foreach ($oXml->PRODUCTDATA->PRODUCT as $oProduct) { + echo "Product n° " . (string)$oProduct->P_NR . " title: " . (string)$oProduct->P_NAME->VALUE . PHP_EOL; + + foreach ($oProduct->ARTICLEDATA->ARTICLE as $oArticle) { + echo "Article n° " . (string)$oArticle->A_NR . " ean: " . (string)$oArticle->A_EAN . PHP_EOL; + } + } +} else { + print_r($sResponse); +} \ No newline at end of file diff --git a/php/getArticlesFull.php b/php/getArticlesFull.php new file mode 100644 index 0000000..be6a89a --- /dev/null +++ b/php/getArticlesFull.php @@ -0,0 +1,55 @@ + + */ + +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Get data from REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/products/?channel=" . $sChannelId; +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_HEADER, 0); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +curl_close($oCurl); + +/* + * Process data as you need + */ +$oXml = simplexml_load_string($sResponse); +if ($oXml && $oXml->PRODUCTDATA) { + + if ($oXml->SUPPLIER){ + echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; + } + + foreach ($oXml->PRODUCTDATA->PRODUCT as $oProduct) { + echo "Product n° " . (string)$oProduct->P_NR . " title: " . (string)$oProduct->P_NAME->VALUE . PHP_EOL; + + foreach ($oProduct->ARTICLEDATA->ARTICLE as $oArticle) { + echo "Article n° " . (string)$oArticle->A_NR . " ean: " . (string)$oArticle->A_EAN . PHP_EOL; + } + } +} else { + print_r($sResponse); +} \ No newline at end of file diff --git a/php/getOrder.php b/php/getOrder.php new file mode 100644 index 0000000..d97af31 --- /dev/null +++ b/php/getOrder.php @@ -0,0 +1,110 @@ + + */ + +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Get data from REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/?channel=" . $sChannelId; +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_HEADER, 0); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +curl_close($oCurl); + +/** + * Process data as you need. + */ +$oXml = simplexml_load_string($sResponse); + +if ($oXml) { + + $ordersImported = []; + + foreach ($oXml->ORDER as $oOrder) { + echo "Order Date " . (string)$oOrder->ORDER_DATA->ORDER_DATE . PHP_EOL; + + $ordersImported[] = (string)$oOrder->ORDER_DATA->TB_ID; + echo "Order ID in Tradebyte " . (string)$oOrder->ORDER_DATA->TB_ID . PHP_EOL; + echo "Order Number (in channel): " . (string)$oOrder->ORDER_DATA->CHANNEL_NO . PHP_EOL; + + /** + * Example of Shipping Information + */ + if ($oOrder->SELL_TO){ + echo "Payment Address: " . $oXml->ORDER->SELL_TO->STREET_NO . PHP_EOL; + } + /** + * Tag SHIP_TO is mandatory so we don't need to check existence + */ + echo "Shipping Address: " . $oXml->ORDER->SHIP_TO->STREET_NO . PHP_EOL; + + echo "Order Items: " . PHP_EOL; + /** + * Here we loop through Order's Items + */ + foreach ($oOrder->ITEMS->ITEM as $oOrderItem) { + echo "Article EAN " . (string)$oOrderItem->EAN . + " Quantity: " . (string)$oOrderItem->QUANTITY . + " Price: " . (string)$oOrderItem->ITEM_PRICE . PHP_EOL; + + } + } + + /** + * Sending confirmation to Tradebyte + */ + sendExportedFlagToTradebyte($ordersImported, $sMerchantId, $sApiUser, $sApiPassword); + +} else { + print_r($sResponse); +} + + + +function sendExportedFlagToTradebyte($arrayOfIds, $sMerchantId, $sApiUser, $sApiPassword){ + + foreach ($arrayOfIds as $orderId){ + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; + + $oCurl = curl_init(); + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); + curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HEADER, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); + $sResponse = curl_exec($oCurl); + if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); + } + else{ + echo "Export Confirmation for Order: " . $orderId . " successfully sent." . PHP_EOL; + } + curl_close($oCurl); + } +} \ No newline at end of file diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php new file mode 100644 index 0000000..7b3678c --- /dev/null +++ b/php/getOrderMessages.php @@ -0,0 +1,84 @@ + + */ + +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + + +/* +* Get data from REST API with curl +*/ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/?channel=" . $sChannelId; + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_HEADER, 0); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +curl_close($oCurl); + +/** + * Process data as you need + */ +$oXml = simplexml_load_string($sResponse); +if ($oXml) { + + $messagesImported = []; + + foreach ($oXml->MESSAGE as $oMessage) { + $messagesImported[] = (string)$oMessage->TB_ORDER_ID; + echo "Message Type: " . (string)$oMessage->MESSAGE_TYPE . PHP_EOL; + echo " Order number in Channel : " . (string)$oMessage->CHANNEL_ORDER_ID . PHP_EOL; + } + /** + * Sending confirmation to Tradebyte + */ + sendReceivedFlagToTradebyte($messagesImported, $sMerchantId, $sChannelId, $sApiUser, $sApiPassword); + +} else { + print_r($sResponse); +} + +function sendReceivedFlagToTradebyte($arrayOfMessageIds, $sMerchantId, $sChannelId, $sApiUser, $sApiPassword){ + foreach ($arrayOfMessageIds as $messageId){ + + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . $messageId . "/processed?channel=" . $sChannelId; + + $oCurl = curl_init(); + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); + curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HEADER, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); + $sResponse = curl_exec($oCurl); + if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); + } + else{ + echo "'Message received' confirmation for Message id: " . $messageId . " successfully sent." . PHP_EOL; + } + curl_close($oCurl); + } +} diff --git a/php/getStocks.php b/php/getStocks.php index 300ddee..ef65e49 100644 --- a/php/getStocks.php +++ b/php/getStocks.php @@ -25,9 +25,8 @@ curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($oCurl, CURLOPT_HEADER, 0); -curl_setopt($oCurl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); -curl_setopt($oCurl, CURLOPT_TIMEOUT, 82800); // 23 hours +curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); $sResponse = curl_exec($oCurl); if ($sResponse === false) { echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); diff --git a/php/sendArticle.php b/php/sendArticle.php new file mode 100644 index 0000000..53ef776 --- /dev/null +++ b/php/sendArticle.php @@ -0,0 +1,84 @@ + + */ + +$sNewLine = "\n"; + +$sXml = '' . $sNewLine; +$sXml .='' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 1777' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 1' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' Product Test Name' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' Long Description of product and all details' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .='
' . $sNewLine; +$sXml .=' 1777-1' . $sNewLine; +$sXml .=' 1' . $sNewLine; +$sXml .=' 2515911601760' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 058de82247787f5fd54d523f0c823e0' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 79.00' . $sNewLine; +$sXml .=' 99.00' . $sNewLine; +$sXml .=' 99.00' . $sNewLine; +$sXml .=' 3' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' https://your.shop/pictures//product/1/picture001.jpg' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 48' . $sNewLine; +$sXml .='
' . $sNewLine; +$sXml .='
' . $sNewLine; +$sXml .='
' . $sNewLine; +$sXml .='
' . $sNewLine; +$sXml .='
' . $sNewLine; + + +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/** + * Name the file according to specifications + */ +$fileName = "TBCAT_".date("YmdHis").".xml"; + + +/* + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/sync/in/" . $fileName; + + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_POST, true); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +else { + print_r($sResponse); +} +curl_close($oCurl); \ No newline at end of file diff --git a/php/sendOrder.php b/php/sendOrder.php new file mode 100644 index 0000000..6716c24 --- /dev/null +++ b/php/sendOrder.php @@ -0,0 +1,85 @@ + + */ + +$sNewLine = "\n"; + +$sXml = '' . $sNewLine; +$sXml .='' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 2020-10-14' . $sNewLine; +$sXml .=' 5555' . $sNewLine; +$sXml .=' 555555555' . $sNewLine; +$sXml .=' 1' . $sNewLine; +$sXml .=' 1' . $sNewLine; +$sXml .=' 297.00' . $sNewLine; +$sXml .=' 2020-10-14T10:47:07' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 55' . $sNewLine; +$sXml .=' Max' . $sNewLine; +$sXml .=' Mustermann' . $sNewLine; +$sXml .=' Max Mustermann' . $sNewLine; +$sXml .=' Bahnhofsplatz 8' . $sNewLine; +$sXml .=' 91522' . $sNewLine; +$sXml .=' Ansbach' . $sNewLine; +$sXml .=' DE' . $sNewLine; +$sXml .=' example@tradebyte.com' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 55' . $sNewLine; +$sXml .=' Max' . $sNewLine; +$sXml .=' Mustermann' . $sNewLine; +$sXml .=' Max Mustermann' . $sNewLine; +$sXml .=' Bahnhofsplatz 8' . $sNewLine; +$sXml .=' 91522' . $sNewLine; +$sXml .=' Ansbach' . $sNewLine; +$sXml .=' DE' . $sNewLine; +$sXml .=' example@tradebyte.com' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' 675443254657' . $sNewLine; +$sXml .=' 555-85-853-6-5' . $sNewLine; +$sXml .=' 3' . $sNewLine; +$sXml .=' Example Product' . $sNewLine; +$sXml .=' 99.000' . $sNewLine; +$sXml .=' 99.000' . $sNewLine; +$sXml .=' 2020-10-14T10:47:07' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .=' ' . $sNewLine; +$sXml .='' . $sNewLine; + + +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/orders/?channel=" . $sChannelId; + + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_POST, true); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +else { + print_r($sResponse); +} +curl_close($oCurl); diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php new file mode 100644 index 0000000..85ee8a5 --- /dev/null +++ b/php/sendOrderMessages.php @@ -0,0 +1,54 @@ + + */ + +$sNewLine = "\n"; + +$sXml = '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' SHIP' . $sNewLine; +$sXml .= ' 42' . $sNewLine; +$sXml .= ' 52' . $sNewLine; +$sXml .= ' 1302' . $sNewLine; +$sXml .= ' 55test' . $sNewLine; +$sXml .= ' test858555/CHANNEL_ORDER_ID>' . $sNewLine; +$sXml .= ' kjgded-555' . $sNewLine; +$sXml .= ' 54454' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' DE57373542354235BR' . $sNewLine; +$sXml .= ' 2020-10-15T14:45:32' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= '' . $sNewLine; + +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/messages/?"; + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_POST, true); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +else { + print_r($sResponse); +} +curl_close($oCurl); \ No newline at end of file diff --git a/php/sendStocks.php b/php/sendStocks.php new file mode 100644 index 0000000..bdabb2f --- /dev/null +++ b/php/sendStocks.php @@ -0,0 +1,58 @@ + + */ + +$sNewLine = "\n"; + +// Values obtained in the shop, for example, to be sent to Tradebyte +$aStockInfo['article_number'] = "5552-55-853-6-2"; //Article Number +$aStockInfo['stock_value'] = 42; //updated stock + + +/** + * Preparing Xml structure according to Tradebyte specs + */ +$sXml = '' . $sNewLine; +$sXml .= "" . $sNewLine; +$sXml .= " " . $sNewLine; + +$sXml .= "
" . $sNewLine; +$sXml .= " {$aStockInfo['article_number']}" . $sNewLine; +$sXml .= " {$aStockInfo['stock_value']}" . $sNewLine; +$sXml .= "
" . $sNewLine; + +$sXml .= "
" . $sNewLine; +$sXml .= "
" . $sNewLine; + + +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/** + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/articles/stock"; + + +$oCurl = curl_init(); +curl_setopt($oCurl, CURLOPT_URL, $sUrl); +curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); +curl_setopt($oCurl, CURLOPT_POST, true); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} +else { + echo "Stock sent successfully"; +} From fa6ee267535c6f9289412ddcde2bad27b6f55db3 Mon Sep 17 00:00:00 2001 From: Hendrik Bahr Date: Mon, 9 Nov 2020 15:36:18 +0100 Subject: [PATCH 03/11] Modify comments and readability --- php/getArticlesDelta.php | 4 +- php/getArticlesFull.php | 4 +- php/getOrderMessages.php | 61 ++++++++++++----------------- php/{getOrder.php => getOrders.php} | 0 php/sendArticle.php | 30 ++++++++------ php/sendOrder.php | 23 ++++++----- php/sendOrderMessages.php | 25 +++++++----- php/sendStocks.php | 40 ++++++++++--------- 8 files changed, 97 insertions(+), 90 deletions(-) rename php/{getOrder.php => getOrders.php} (100%) diff --git a/php/getArticlesDelta.php b/php/getArticlesDelta.php index a456fce..83f5182 100644 --- a/php/getArticlesDelta.php +++ b/php/getArticlesDelta.php @@ -2,7 +2,7 @@ /** * This example script gets information on products and on its related articles from the Tradebyte REST API. * - * @author Marcos Doellerer + * @author Marcos Doellerer */ /* @@ -55,4 +55,4 @@ } } else { print_r($sResponse); -} \ No newline at end of file +} diff --git a/php/getArticlesFull.php b/php/getArticlesFull.php index be6a89a..0df6812 100644 --- a/php/getArticlesFull.php +++ b/php/getArticlesFull.php @@ -2,7 +2,7 @@ /** * This example script gets information on products and on its related articles from the Tradebyte REST API. * - * @author Marcos Doellerer + * @author Marcos Doellerer */ /* @@ -52,4 +52,4 @@ } } else { print_r($sResponse); -} \ No newline at end of file +} diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php index 7b3678c..a0aece8 100644 --- a/php/getOrderMessages.php +++ b/php/getOrderMessages.php @@ -1,9 +1,9 @@ + * @author Marcos Doellerer */ /* @@ -41,44 +41,31 @@ */ $oXml = simplexml_load_string($sResponse); if ($oXml) { - - $messagesImported = []; - foreach ($oXml->MESSAGE as $oMessage) { - $messagesImported[] = (string)$oMessage->TB_ORDER_ID; echo "Message Type: " . (string)$oMessage->MESSAGE_TYPE . PHP_EOL; echo " Order number in Channel : " . (string)$oMessage->CHANNEL_ORDER_ID . PHP_EOL; - } - /** - * Sending confirmation to Tradebyte - */ - sendReceivedFlagToTradebyte($messagesImported, $sMerchantId, $sChannelId, $sApiUser, $sApiPassword); + /** + * Sending confirmation to Tradebyte + */ + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (string)$oMessage->TB_ORDER_ID . "/processed?channel=" . $sChannelId; + $oCurl = curl_init(); + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); + curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HEADER, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); + $sResponse = curl_exec($oCurl); + if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); + }else{ + echo "'Message received' confirmation for Message id: " . $messageId . " successfully sent." . PHP_EOL; + } + curl_close($oCurl); + } } else { print_r($sResponse); } - -function sendReceivedFlagToTradebyte($arrayOfMessageIds, $sMerchantId, $sChannelId, $sApiUser, $sApiPassword){ - foreach ($arrayOfMessageIds as $messageId){ - - $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . $messageId . "/processed?channel=" . $sChannelId; - - $oCurl = curl_init(); - curl_setopt($oCurl, CURLOPT_URL, $sUrl); - curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); - curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! - curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($oCurl, CURLOPT_HEADER, 0); - curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); - $sResponse = curl_exec($oCurl); - if ($sResponse === false) { - echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); - } - else{ - echo "'Message received' confirmation for Message id: " . $messageId . " successfully sent." . PHP_EOL; - } - curl_close($oCurl); - } -} diff --git a/php/getOrder.php b/php/getOrders.php similarity index 100% rename from php/getOrder.php rename to php/getOrders.php diff --git a/php/sendArticle.php b/php/sendArticle.php index 53ef776..db78d85 100644 --- a/php/sendArticle.php +++ b/php/sendArticle.php @@ -2,11 +2,24 @@ /** * This example script prepares and sends information on products and on its related articles to the Tradebyte REST API. * - * @author Marcos Doellerer + * @author Marcos Doellerer */ -$sNewLine = "\n"; +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Product XML + */ +$sNewLine = "\n"; $sXml = '' . $sNewLine; $sXml .='' . $sNewLine; $sXml .=' ' . $sNewLine; @@ -37,20 +50,14 @@ $sXml .=' ' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' ' . $sNewLine; -$sXml .=' https://your.shop/pictures//product/1/picture001.jpg' . $sNewLine; +$sXml .=' https://i.picsum.photos/id/1000/1000/1000.jpg?hmac=YU8XuX62UAwEXXFELdXRqFZDQJfD9JDwDv13xTWCvL8' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' 48' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; - - -$sApiUser = 'api-user'; // Your API username -$sApiPassword = 'api-password'; // Your API password -$sMerchantId = '1234'; // Your digit merchant ID -$sChannelId = '5678'; // Your digit channel ID +$sXml .='' . $sNewLine; /** * Name the file according to specifications @@ -63,7 +70,6 @@ */ $sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/sync/in/" . $fileName; - $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); @@ -81,4 +87,4 @@ else { print_r($sResponse); } -curl_close($oCurl); \ No newline at end of file +curl_close($oCurl); diff --git a/php/sendOrder.php b/php/sendOrder.php index 6716c24..8c5e74e 100644 --- a/php/sendOrder.php +++ b/php/sendOrder.php @@ -2,11 +2,23 @@ /** * This example script prepares and sends information on orders to the Tradebyte REST API. * - * @author Marcos Doellerer + * @author Marcos Doellerer */ -$sNewLine = "\n"; +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID +/* + * Example order XML + */ +$sNewLine = "\n"; $sXml = '' . $sNewLine; $sXml .='' . $sNewLine; $sXml .=' ' . $sNewLine; @@ -53,18 +65,11 @@ $sXml .=' ' . $sNewLine; $sXml .='' . $sNewLine; - -$sApiUser = 'api-user'; // Your API username -$sApiPassword = 'api-password'; // Your API password -$sMerchantId = '1234'; // Your digit merchant ID -$sChannelId = '5678'; // Your digit channel ID - /* * Send data to REST API with curl */ $sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/orders/?channel=" . $sChannelId; - $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php index 85ee8a5..7eadb02 100644 --- a/php/sendOrderMessages.php +++ b/php/sendOrderMessages.php @@ -1,12 +1,24 @@ + * @author Marcos Doellerer */ -$sNewLine = "\n"; +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID +/* + * Example message + */ +$sNewLine = "\n"; $sXml = '' . $sNewLine; $sXml .= '' . $sNewLine; $sXml .= '' . $sNewLine; @@ -24,11 +36,6 @@ $sXml .= '' . $sNewLine; $sXml .= '' . $sNewLine; -$sApiUser = 'api-user'; // Your API username -$sApiPassword = 'api-password'; // Your API password -$sMerchantId = '1234'; // Your digit merchant ID -$sChannelId = '5678'; // Your digit channel ID - /* * Send data to REST API with curl */ @@ -51,4 +58,4 @@ else { print_r($sResponse); } -curl_close($oCurl); \ No newline at end of file +curl_close($oCurl); diff --git a/php/sendStocks.php b/php/sendStocks.php index bdabb2f..7384a1c 100644 --- a/php/sendStocks.php +++ b/php/sendStocks.php @@ -2,43 +2,45 @@ /** * This example script prepares and sends information on products stocks to the Tradebyte REST API. * - * @author Marcos Doellerer + * @author Marcos Doellerer */ -$sNewLine = "\n"; +/* + * API-Credentials - modify to your personal access credentials + * + * @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ + */ +$sApiUser = 'api-user'; // Your API username +$sApiPassword = 'api-password'; // Your API password +$sMerchantId = '1234'; // Your digit merchant ID +$sChannelId = '5678'; // Your digit channel ID + +/* + * Example status data + */ +$sNewLine = "\n"; // Values obtained in the shop, for example, to be sent to Tradebyte $aStockInfo['article_number'] = "5552-55-853-6-2"; //Article Number $aStockInfo['stock_value'] = 42; //updated stock - - /** * Preparing Xml structure according to Tradebyte specs */ $sXml = '' . $sNewLine; $sXml .= "" . $sNewLine; $sXml .= " " . $sNewLine; - -$sXml .= "
" . $sNewLine; -$sXml .= " {$aStockInfo['article_number']}" . $sNewLine; -$sXml .= " {$aStockInfo['stock_value']}" . $sNewLine; -$sXml .= "
" . $sNewLine; - -$sXml .= "
" . $sNewLine; -$sXml .= "
" . $sNewLine; - - -$sApiUser = 'api-user'; // Your API username -$sApiPassword = 'api-password'; // Your API password -$sMerchantId = '1234'; // Your digit merchant ID -$sChannelId = '5678'; // Your digit channel ID +$sXml .= "
" . $sNewLine; +$sXml .= " {$aStockInfo['article_number']}" . $sNewLine; +$sXml .= " {$aStockInfo['stock_value']}" . $sNewLine; +$sXml .= "
" . $sNewLine; +$sXml .= " " . $sNewLine; +$sXml .= "" . $sNewLine; /** * Send data to REST API with curl */ $sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/articles/stock"; - $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); From cb45b21e4aafcb4e9a0549d65ce041e65ea7c0e7 Mon Sep 17 00:00:00 2001 From: mdoellerer-fc Date: Tue, 10 Nov 2020 13:21:20 +0100 Subject: [PATCH 04/11] 0067954 - Removing unnecessary tags that were preventing the validation of the messages --- php/sendOrder.php | 3 +-- php/sendOrderMessages.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/php/sendOrder.php b/php/sendOrder.php index 8c5e74e..3b79746 100644 --- a/php/sendOrder.php +++ b/php/sendOrder.php @@ -23,8 +23,7 @@ $sXml .='' . $sNewLine; $sXml .=' ' . $sNewLine; $sXml .=' 2020-10-14' . $sNewLine; -$sXml .=' 5555' . $sNewLine; -$sXml .=' 555555555' . $sNewLine; +$sXml .=' 5555' . $sNewLine; $sXml .=' 1' . $sNewLine; $sXml .=' 1' . $sNewLine; $sXml .=' 297.00' . $sNewLine; diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php index 7eadb02..c39555c 100644 --- a/php/sendOrderMessages.php +++ b/php/sendOrderMessages.php @@ -29,7 +29,6 @@ $sXml .= ' 55test' . $sNewLine; $sXml .= ' test858555/CHANNEL_ORDER_ID>' . $sNewLine; $sXml .= ' kjgded-555' . $sNewLine; -$sXml .= ' 54454' . $sNewLine; $sXml .= ' 1' . $sNewLine; $sXml .= ' DE57373542354235BR' . $sNewLine; $sXml .= ' 2020-10-15T14:45:32' . $sNewLine; From 0a6de6bad048cb76a2718e7510d2d42f5e304743 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:00:23 +0100 Subject: [PATCH 05/11] Update php/sendOrderMessages.php Co-authored-by: Dominik Meyer --- php/sendOrderMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php index c39555c..147f642 100644 --- a/php/sendOrderMessages.php +++ b/php/sendOrderMessages.php @@ -27,7 +27,7 @@ $sXml .= ' 52' . $sNewLine; $sXml .= ' 1302' . $sNewLine; $sXml .= ' 55test' . $sNewLine; -$sXml .= ' test858555/CHANNEL_ORDER_ID>' . $sNewLine; +$sXml .= ' test858555' . $sNewLine; $sXml .= ' kjgded-555' . $sNewLine; $sXml .= ' 1' . $sNewLine; $sXml .= ' DE57373542354235BR' . $sNewLine; From 223e1a431ac98c02eaed5689440f67fcfcbf7c30 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:00:33 +0100 Subject: [PATCH 06/11] Update php/sendOrderMessages.php Co-authored-by: Dominik Meyer --- php/sendOrderMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php index 147f642..3753f70 100644 --- a/php/sendOrderMessages.php +++ b/php/sendOrderMessages.php @@ -26,7 +26,7 @@ $sXml .= ' 42' . $sNewLine; $sXml .= ' 52' . $sNewLine; $sXml .= ' 1302' . $sNewLine; -$sXml .= ' 55test' . $sNewLine; +$sXml .= ' test' . $sNewLine; $sXml .= ' test858555' . $sNewLine; $sXml .= ' kjgded-555' . $sNewLine; $sXml .= ' 1' . $sNewLine; From 1f558c6c4a15eb299e92581cf431374d77c42fa5 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:01:04 +0100 Subject: [PATCH 07/11] Update php/getOrders.php Co-authored-by: Dominik Meyer --- php/getOrders.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/getOrders.php b/php/getOrders.php index d97af31..39e8b47 100644 --- a/php/getOrders.php +++ b/php/getOrders.php @@ -84,7 +84,7 @@ -function sendExportedFlagToTradebyte($arrayOfIds, $sMerchantId, $sApiUser, $sApiPassword){ +function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword){ foreach ($arrayOfIds as $orderId){ $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; @@ -107,4 +107,4 @@ function sendExportedFlagToTradebyte($arrayOfIds, $sMerchantId, $sApiUser, $sApi } curl_close($oCurl); } -} \ No newline at end of file +} From f2d41af0743fdf1e7bb2cc3330f082c42fc09aa0 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:01:12 +0100 Subject: [PATCH 08/11] Update php/getOrderMessages.php Co-authored-by: Dominik Meyer --- php/getOrderMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php index a0aece8..aa2bae4 100644 --- a/php/getOrderMessages.php +++ b/php/getOrderMessages.php @@ -48,7 +48,7 @@ /** * Sending confirmation to Tradebyte */ - $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (string)$oMessage->TB_ORDER_ID . "/processed?channel=" . $sChannelId; + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (int)$oMessage->MESSAGE_ID . "/processed?channel=" . $sChannelId; $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); From 91a2926da6c9256071d074ab5dceea066a0adde8 Mon Sep 17 00:00:00 2001 From: Marcos <67734997+mdoellerer-fc@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:01:22 +0100 Subject: [PATCH 09/11] Update php/getOrderMessages.php Co-authored-by: Dominik Meyer --- php/getOrderMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php index aa2bae4..891f388 100644 --- a/php/getOrderMessages.php +++ b/php/getOrderMessages.php @@ -62,7 +62,7 @@ if ($sResponse === false) { echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); }else{ - echo "'Message received' confirmation for Message id: " . $messageId . " successfully sent." . PHP_EOL; + echo "'Message received' confirmation for Message id: " . $oMessage->MESSAGE_ID . " successfully sent." . PHP_EOL; } curl_close($oCurl); } From f355a0dd98de38c927ab532f6706db8232685cde Mon Sep 17 00:00:00 2001 From: mdoellerer-fc Date: Thu, 26 Nov 2020 11:21:37 +0100 Subject: [PATCH 10/11] 0067954 - Applying psr-12 and other suggestions from TB --- php/getArticlesDelta.php | 6 +-- php/getArticlesFull.php | 4 +- php/getOrderMessages.php | 1 + php/getOrders.php | 11 ++--- php/getStocks.php | 13 +++--- php/sendArticle.php | 83 +++++++++++++++++------------------ php/sendOrder.php | 92 +++++++++++++++++++-------------------- php/sendOrderMessages.php | 6 +-- php/sendStocks.php | 8 ++-- 9 files changed, 111 insertions(+), 113 deletions(-) diff --git a/php/getArticlesDelta.php b/php/getArticlesDelta.php index 83f5182..15a8745 100644 --- a/php/getArticlesDelta.php +++ b/php/getArticlesDelta.php @@ -1,4 +1,5 @@ PRODUCTDATA) { - - if ($oXml->SUPPLIER){ + if ($oXml->SUPPLIER) { echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; } diff --git a/php/getArticlesFull.php b/php/getArticlesFull.php index 0df6812..7cd7bfe 100644 --- a/php/getArticlesFull.php +++ b/php/getArticlesFull.php @@ -1,4 +1,5 @@ PRODUCTDATA) { - - if ($oXml->SUPPLIER){ + if ($oXml->SUPPLIER) { echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; } diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php index 891f388..fbdfaaf 100644 --- a/php/getOrderMessages.php +++ b/php/getOrderMessages.php @@ -1,4 +1,5 @@ ORDER as $oOrder) { @@ -53,7 +53,7 @@ /** * Example of Shipping Information */ - if ($oOrder->SELL_TO){ + if ($oOrder->SELL_TO) { echo "Payment Address: " . $oXml->ORDER->SELL_TO->STREET_NO . PHP_EOL; } /** @@ -69,7 +69,6 @@ echo "Article EAN " . (string)$oOrderItem->EAN . " Quantity: " . (string)$oOrderItem->QUANTITY . " Price: " . (string)$oOrderItem->ITEM_PRICE . PHP_EOL; - } } @@ -77,7 +76,6 @@ * Sending confirmation to Tradebyte */ sendExportedFlagToTradebyte($ordersImported, $sMerchantId, $sApiUser, $sApiPassword); - } else { print_r($sResponse); } @@ -86,7 +84,7 @@ function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword){ - foreach ($arrayOfIds as $orderId){ + foreach ($arrayOfIds as $orderId) { $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; $oCurl = curl_init(); @@ -101,8 +99,7 @@ function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPas $sResponse = curl_exec($oCurl); if ($sResponse === false) { echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); - } - else{ + } else { echo "Export Confirmation for Order: " . $orderId . " successfully sent." . PHP_EOL; } curl_close($oCurl); diff --git a/php/getStocks.php b/php/getStocks.php index ef65e49..ddd285c 100644 --- a/php/getStocks.php +++ b/php/getStocks.php @@ -1,4 +1,5 @@ ARTICLE) { - foreach ($oXml->ARTICLE as $oProduct) { - echo (string)$oProduct->A_NR . ": " . (string)$oProduct->A_STOCK . PHP_EOL; - } + foreach ($oXml->ARTICLE as $oProduct) { + echo (string)$oProduct->A_NR . ": " . (string)$oProduct->A_STOCK . PHP_EOL; + } } else { - print_r($sResponse); + print_r($sResponse); } diff --git a/php/sendArticle.php b/php/sendArticle.php index db78d85..03e41bd 100644 --- a/php/sendArticle.php +++ b/php/sendArticle.php @@ -1,11 +1,11 @@ */ - /* * API-Credentials - modify to your personal access credentials * @@ -21,54 +21,54 @@ */ $sNewLine = "\n"; $sXml = '' . $sNewLine; -$sXml .='' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 1777' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 1' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' Product Test Name' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' Long Description of product and all details' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .='
' . $sNewLine; -$sXml .=' 1777-1' . $sNewLine; -$sXml .=' 1' . $sNewLine; -$sXml .=' 2515911601760' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 058de82247787f5fd54d523f0c823e0' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 79.00' . $sNewLine; -$sXml .=' 99.00' . $sNewLine; -$sXml .=' 99.00' . $sNewLine; -$sXml .=' 3' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' https://i.picsum.photos/id/1000/1000/1000.jpg?hmac=YU8XuX62UAwEXXFELdXRqFZDQJfD9JDwDv13xTWCvL8' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 48' . $sNewLine; -$sXml .='
' . $sNewLine; -$sXml .='
' . $sNewLine; -$sXml .='
' . $sNewLine; -$sXml .='
' . $sNewLine; -$sXml .='
' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 1777' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' Product Test Name' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' Long Description of product and all details' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= ' 1777-1' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 2515911601760' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 058de82247787f5fd54d523f0c823e0' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 79.00' . $sNewLine; +$sXml .= ' 99.00' . $sNewLine; +$sXml .= ' 99.00' . $sNewLine; +$sXml .= ' 3' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' https://i.picsum.photos/id/1000/1000/1000.jpg?hmac=YU8XuX62UAwEXXFELdXRqFZDQJfD9JDwDv13xTWCvL8' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 48' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; /** * Name the file according to specifications */ -$fileName = "TBCAT_".date("YmdHis").".xml"; +$fileName = "TBCAT_" . date("YmdHis") . ".xml"; /* * Send data to REST API with curl */ -$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/sync/in/" . $fileName; +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/sync/in/" . $fileName; $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); @@ -83,8 +83,7 @@ $sResponse = curl_exec($oCurl); if ($sResponse === false) { echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); -} -else { +} else { print_r($sResponse); } curl_close($oCurl); diff --git a/php/sendOrder.php b/php/sendOrder.php index 3b79746..88e6e6f 100644 --- a/php/sendOrder.php +++ b/php/sendOrder.php @@ -1,4 +1,5 @@ ' . $sNewLine; -$sXml .='' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 2020-10-14' . $sNewLine; -$sXml .=' 5555' . $sNewLine; -$sXml .=' 1' . $sNewLine; -$sXml .=' 1' . $sNewLine; -$sXml .=' 297.00' . $sNewLine; -$sXml .=' 2020-10-14T10:47:07' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 55' . $sNewLine; -$sXml .=' Max' . $sNewLine; -$sXml .=' Mustermann' . $sNewLine; -$sXml .=' Max Mustermann' . $sNewLine; -$sXml .=' Bahnhofsplatz 8' . $sNewLine; -$sXml .=' 91522' . $sNewLine; -$sXml .=' Ansbach' . $sNewLine; -$sXml .=' DE' . $sNewLine; -$sXml .=' example@tradebyte.com' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 55' . $sNewLine; -$sXml .=' Max' . $sNewLine; -$sXml .=' Mustermann' . $sNewLine; -$sXml .=' Max Mustermann' . $sNewLine; -$sXml .=' Bahnhofsplatz 8' . $sNewLine; -$sXml .=' 91522' . $sNewLine; -$sXml .=' Ansbach' . $sNewLine; -$sXml .=' DE' . $sNewLine; -$sXml .=' example@tradebyte.com' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' 675443254657' . $sNewLine; -$sXml .=' 555-85-853-6-5' . $sNewLine; -$sXml .=' 3' . $sNewLine; -$sXml .=' Example Product' . $sNewLine; -$sXml .=' 99.000' . $sNewLine; -$sXml .=' 99.000' . $sNewLine; -$sXml .=' 2020-10-14T10:47:07' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .=' ' . $sNewLine; -$sXml .='' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 2020-10-14' . $sNewLine; +$sXml .= ' 5555' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 297.00' . $sNewLine; +$sXml .= ' 2020-10-14T10:47:07' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 55' . $sNewLine; +$sXml .= ' Max' . $sNewLine; +$sXml .= ' Mustermann' . $sNewLine; +$sXml .= ' Max Mustermann' . $sNewLine; +$sXml .= ' Bahnhofsplatz 8' . $sNewLine; +$sXml .= ' 91522' . $sNewLine; +$sXml .= ' Ansbach' . $sNewLine; +$sXml .= ' DE' . $sNewLine; +$sXml .= ' example@tradebyte.com' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 55' . $sNewLine; +$sXml .= ' Max' . $sNewLine; +$sXml .= ' Mustermann' . $sNewLine; +$sXml .= ' Max Mustermann' . $sNewLine; +$sXml .= ' Bahnhofsplatz 8' . $sNewLine; +$sXml .= ' 91522' . $sNewLine; +$sXml .= ' Ansbach' . $sNewLine; +$sXml .= ' DE' . $sNewLine; +$sXml .= ' example@tradebyte.com' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 675443254657' . $sNewLine; +$sXml .= ' 555-85-853-6-5' . $sNewLine; +$sXml .= ' 3' . $sNewLine; +$sXml .= ' Example Product' . $sNewLine; +$sXml .= ' 99.000' . $sNewLine; +$sXml .= ' 99.000' . $sNewLine; +$sXml .= ' 2020-10-14T10:47:07' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= '' . $sNewLine; /* * Send data to REST API with curl */ -$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/orders/?channel=" . $sChannelId; +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/?channel=" . $sChannelId; $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $sUrl); @@ -82,8 +83,7 @@ $sResponse = curl_exec($oCurl); if ($sResponse === false) { echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); -} -else { +} else { print_r($sResponse); } curl_close($oCurl); diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php index 3753f70..74d27c2 100644 --- a/php/sendOrderMessages.php +++ b/php/sendOrderMessages.php @@ -1,4 +1,5 @@ Date: Thu, 26 Nov 2020 12:26:50 +0100 Subject: [PATCH 11/11] 0067954 - Applying psr-12 and other suggestions from TB --- php/getOrderMessages.php | 40 ++++++++++++++++---------------- php/getOrders.php | 50 +++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php index fbdfaaf..8c64d1d 100644 --- a/php/getOrderMessages.php +++ b/php/getOrderMessages.php @@ -46,26 +46,26 @@ echo "Message Type: " . (string)$oMessage->MESSAGE_TYPE . PHP_EOL; echo " Order number in Channel : " . (string)$oMessage->CHANNEL_ORDER_ID . PHP_EOL; - /** - * Sending confirmation to Tradebyte - */ - $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (int)$oMessage->MESSAGE_ID . "/processed?channel=" . $sChannelId; - $oCurl = curl_init(); - curl_setopt($oCurl, CURLOPT_URL, $sUrl); - curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); - curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! - curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($oCurl, CURLOPT_HEADER, 0); - curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); - $sResponse = curl_exec($oCurl); - if ($sResponse === false) { - echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); - }else{ - echo "'Message received' confirmation for Message id: " . $oMessage->MESSAGE_ID . " successfully sent." . PHP_EOL; - } - curl_close($oCurl); + /** + * Sending confirmation to Tradebyte + */ + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (int)$oMessage->MESSAGE_ID . "/processed?channel=" . $sChannelId; + $oCurl = curl_init(); + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); + curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HEADER, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); + $sResponse = curl_exec($oCurl); + if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); + } else { + echo "'Message received' confirmation for Message id: " . $oMessage->MESSAGE_ID . " successfully sent." . PHP_EOL; + } + curl_close($oCurl); } } else { print_r($sResponse); diff --git a/php/getOrders.php b/php/getOrders.php index 6b24787..29e0b9c 100644 --- a/php/getOrders.php +++ b/php/getOrders.php @@ -46,8 +46,8 @@ foreach ($oXml->ORDER as $oOrder) { echo "Order Date " . (string)$oOrder->ORDER_DATA->ORDER_DATE . PHP_EOL; - $ordersImported[] = (string)$oOrder->ORDER_DATA->TB_ID; - echo "Order ID in Tradebyte " . (string)$oOrder->ORDER_DATA->TB_ID . PHP_EOL; + $orderId = (string)$oOrder->ORDER_DATA->TB_ID; + echo "Order ID in Tradebyte " . $orderId . PHP_EOL; echo "Order Number (in channel): " . (string)$oOrder->ORDER_DATA->CHANNEL_NO . PHP_EOL; /** @@ -70,38 +70,36 @@ " Quantity: " . (string)$oOrderItem->QUANTITY . " Price: " . (string)$oOrderItem->ITEM_PRICE . PHP_EOL; } + /** + * Sending confirmation to Tradebyte + */ + sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword); } - - /** - * Sending confirmation to Tradebyte - */ - sendExportedFlagToTradebyte($ordersImported, $sMerchantId, $sApiUser, $sApiPassword); } else { print_r($sResponse); } -function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword){ +function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword) +{ - foreach ($arrayOfIds as $orderId) { - $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; + $sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; - $oCurl = curl_init(); - curl_setopt($oCurl, CURLOPT_URL, $sUrl); - curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); - curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! - curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($oCurl, CURLOPT_HEADER, 0); - curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); - $sResponse = curl_exec($oCurl); - if ($sResponse === false) { - echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); - } else { - echo "Export Confirmation for Order: " . $orderId . " successfully sent." . PHP_EOL; - } - curl_close($oCurl); + $oCurl = curl_init(); + curl_setopt($oCurl, CURLOPT_URL, $sUrl); + curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); + curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HEADER, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); + $sResponse = curl_exec($oCurl); + if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); + } else { + echo "Export Confirmation for Order: " . $orderId . " successfully sent." . PHP_EOL; } + curl_close($oCurl); }