【发布时间】:2014-02-18 19:35:52
【问题描述】:
基本上,我正在尝试从 magento 向第三方 API 发送销售订单,并收到订单是否被接受的通知。 我已经使用 api 用户和密码为其余系统创建了用户和滚动我已经阅读了多个论坛帖子,但似乎无法找到从这里去哪里我有一段代码,我已经得到了第三个 -连接到他们的 API 的 API 是下面的信息
Post example (fixed)
<form method="post" action="http://iconnect.ibacstel.com/submitorder.php">
<input name="api_key" value="Your API Key" />
<input name="api_password" value="Your API Password" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%123 Street Address, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="order_type" value="1" /><!--Delivery=1, Pick up=2, Reservation=3-->
<input name="payment_status" value="6" /><!--Paid=6, Not Paid=7-->
<input name="payment_method" value="Payment Method" />
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="auth_code" value="Payment authorization code" />
<input name="cat_1" value="Category 1" />
<input name="item_1" value="Item Name 1" />
<input name="desc_1" value="Item description 1" />
<input name="qnt_1" value="1" />
<input name="price_1" value="10.50" />
<input name="cat_2" value="" />
<input name="item_2" value="Item Name 2" />
<input name="desc_2" value="Item description 2" />
<input name="qnt_2" value="1" />
<input name="price_2" value="10.50" />
<input name="cat_3" value="Category 2" />
<input name="item_3" value="Item Name 3" />
<input name="desc_3" value="Item description 3" />
<input name="qnt_3" value="1" />
<input name="price_3" value="10.50" />
---------
You can place more items here using above format.
Please note that you don't need to send category name for the items after first item if the category name is same and if you put all same category items consecutively.
---------
<input name="deliverycost" value="3.50" />
<input name="card_fee" value="0.50" />
<input name="extra_fee" value="1.50" />
<input name="total_discount" value="4.50" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
<input name="cust_name" value="Customer Name" />
<input name="cust_address" value="Customer address" />
<input name="cust_phone" value="Phone number" />
<input name="cust_instruction" value="Special instruction" />
<input name="isVarified" value="4" /><!-Verified=4, Not verified=5 -->
<input name="num_prev_order" value="Number of previous order" />
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Post example (free style)
<form method="post" action="http://iconnect.ibacstel.com/submitorderfreestyle.php">
<input name="api_key" value="Your API Key" />
<input name="api_password" value="Your API Password" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%123 Street Address, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="print_data" value="Line 1/rLine 2%%Line 3/-" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="print_only" value="0" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Success response
<response>
<status>OK</status>
<details>
<msg>Order has been stored successfully</msg>
</details>
</response>
Error response
<response>
<status>FAILED</status>
<details>
<error> Authentication failed </error>
<error> Other errors...</error>
</details>
</response>
Update notification format
When printer sends a callback response to API the API sends a notification to the Provided Notify URL with order
In your notification url you will get notification regarding the status of the order, all the information will be submitted via post method which will allow you to grab information easily.
Post variables:
"printer_id" = Printer ID
"order_id" = Order ID
"status" = (1=accepted,2=rejected)
"msg" = message from printer
"delivery_time" = confirmed delivery time from printer
"manual_update" = (1=manual update identifier)
"booking" = (1=manage booking identifier)
Please note that you will not get the notification while you are sending order to API even if the notify URL is same as where you are sending order to API. API will send response later automatically when the order will be accepted/rejected from printer to that Notify URL you provided with order. So we recommend you to use separate URL/file to send order to API and receive notification from API to avoid confusion.
Example in PHP
Lets say you are sending order the URL of your site www.example.com/sendorder.php to API
So you need to write necessary code on sendorder.php to send order information from your site to API. I am not telling you the details here how to send order to API. Please check our example html form above to send order information to API.
Lets say you have used the value of notification URL field www.example.com/receivenotification.php in orders sending form like <input name="notify_url" value="www.example.com/receivenotification.php" /> then iConnect API will send notification to www.example.com/receivenotification.php as soon as API get response from printer when an order will be accepted/rejected after printing. Here is the example code to grab the information from API notification need to be placed on receivenotification.php file.
<?php
$printer_id = $_REQUEST['printer_id'];
$order_id = $_REQUEST['order_id'];
$order_status = $_REQUEST['status'];
$message = $_REQUEST['msg'];
$delivery_time = $_REQUEST['delivery_time'];
if($order_status==1){
//order has been accepted from printer
//do your necessary task for accepted order like update databse, send email to customer to inform him that his order has been accepted and will be delivered on returned delivery time (variable $delivery_time).
}
else{
//order has been rejected from printer
//do your necessary task for rejected order like update databse, send email to customer to inform him that his order has been rejected for the returned reason (variable $message).
}
?>
基本上,我需要知道将这段代码放在哪里,或者我必须修改或创建什么文件才能做到这一点。提前致谢
所以我已经创建了您详细说明的所有文件,并且我已经将我的第 3 方代码放在了您指定的位置,但是,它不起作用,这是我的 thirdparty.php 文件内容,也许您会发现我哪里出错了.
<?php
class Bh_ZeroSubtotalpaymentmethod_Model_Thirdparty {
public function automatic(Varien_Event_Observer $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
foreach($orderIds as $eachOrderId){
$order = Mage::getModel('sales/order')->load($eachOrderId);
<form method="post" action="http://iconnect.ibacstel.com/submitorderfreestyle.php">
<input name="api_key" value="******" />
<input name="api_password" value="************" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%Take, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="print_data" value="Line 1/rLine 2%%Line 3/-" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="print_only" value="0" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Success response
<response>
<status>OK</status>
<details>
<msg>Order has been stored successfully</msg>
</details>
</response>
Error response
<response>
<status>FAILED</status>
<details>
<error> Authentication failed </error>
<error> Other errors...</error>
</details>
</response>
}
return $this;
}
}
这是正确的吗?你也可以看看第三方代码并告诉我天气这将在magento中工作还是我必须将它翻译成不同的语言?谢谢
【问题讨论】:
标签: magento