【问题标题】:Post sales order to 3rd party api with reply通过回复将销售订单发布到 3rd 方 api
【发布时间】: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


    【解决方案1】:

    Magento 有一个有趣的功能 Event-observer 并使用观察者触发和运行一些代码。 例如,nagento 事件列表http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/ 下订单后的前端运行一些 使用

    创建扩展

    在app/code/local/Bh/ZeroSubtotalpaymentmethod/etc下创建config.xml

               <?xml version="1.0" ?>
        <config>
            <modules>
                <Bh_ZeroSubtotalpaymentmethod>
                    <version>1.0.1</version>
                </Bh_ZeroSubtotalpaymentmethod>
            </modules>
            <global>
                <models>
                    <zerosubtotalpaymentmethod>
                    <class>Bh_ZeroSubtotalpaymentmethod_Model</class>
                    </zerosubtotalpaymentmethod>
                                </models>
    
            </global>
            <frontend>
                <events>
    
                    <checkout_onepage_controller_success_action>
                        <observers>
                            <create_thridparty_order>
                                <class>zerosubtotalpaymentmethod/thirdparty</class>
                                <method>automatic</method>
                            </create_thridparty_order>
                        </observers>
                    </checkout_onepage_controller_success_action>
    
                </events>
            </frontend>
        <adminhtml>
                <events>
    
                    <checkout_submit_all_after>
                        <observers>
                            <create_thridparty_order>
                                <class>zerosubtotalpaymentmethod/thirdparty</class>
                                <method>automatic</method>
                            </create_thridparty_order>
                        </observers>
                    </checkout_submit_all_after>
    
                </events>
            </adminhtml>
    </config>
    

    ****然后在app/code/local/Bh/ZeroSubtotalpaymentmethod/Model/**下创建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);
            //right our third party code
            client = new Zend_Http_Client();
            $client->setUri('http://iconnect.ibacstel.com/submitorderfreestyle.php');
            $client->>setParameterPost(array(
            'api_key' => 'yourapi',
            'apikey' => 'xxxx',
            'message' => $message,
            'order_id' => $order_id,
            ...//more params
            ));
            $response = $client->request('POST');
            // Yet another way of preforming a POST request
            $client->setMethod(Zend_Http_Client::POST);
    
            if (!$response->isSuccessful()) {
                Mage::log($response);
            }
        }
        return $this;
    }
    
    }
    

    Also.create 在 Bh_ZeroSubtotalpaymentmethod.xml 下 应用程序/etc/modules/

    <?xml version="1.0" ?>
    <config>
    <modules>
        <Bh_ZeroSubtotalpaymentmethod>
            <active>true</active>
            <codePool>local</codePool>
        </Bh_ZeroSubtotalpaymentmethod>
    </modules>
    </config>
    

    【讨论】:

    • 您好,谢谢您的回复,所以我必须创建这两个文件,但是我在哪里放置 magento api 的其余 api 详细信息,我说得对吗(//对我们的第三个派对代码)是我放置我之前发布的代码的地方吗?谢谢
    • 好吧坦克,我现在正在测试这些,会告诉你结果。您是否碰巧知道通知 url URL 到您希望从打印机收到订单接受/拒绝通知的位置。非常感谢我几周来一直在帮助我
    • 您好,我已经创建了文件并编辑了我的原始帖子并将我的thirdparty.php 文件放在那里,所以你可以看到它,我似乎仍然无法弄清楚我的其余用户和滚动进入等式,您能否指出我如何允许第 3 方 api 回复 magento 以判断订单是否被接受或拒绝的正确方向
    • 有人能给我一些指导,告诉我如何实际完成这项工作。谢谢
    • 即使在我们使用 Express Paypal 结账时也可以使用。 (Y) +1 人!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 2018-08-02
    • 2017-07-22
    • 2014-11-29
    • 2019-04-01
    相关资源
    最近更新 更多