dongshi1188 2017-04-25 06:09
浏览 46
已采纳

无法创建订单Woocommerce休息Api php

I tried the following code and tried to post values from android to place an order but every time i test it on chrome it give http 500 error, and Android gives volly server error. Dont know where i am messing up, serious help would be appriciated. Thank You Ask me if you need to take a look at the android Code, but i think that doesnot matter here because i am giving hard coded values in $data.

<?php

require_once( 'lib/woocommerce-api.php' );

$pageNum=1;
$pageNum=$_GET['page_num'];

$options = array(
'debug'           => true,
'return_as_array' => false,
'validate_url'    => false,
'timeout'         => 30,
'ssl_verify'      => false,
);

try {

$client = new WC_API_Client( 'https://www.move2mart.com/', 'ck_0afa3a49305683160fe34189553a660053bd4e6239', 'cs_7dc38a7b52c3fdd34qw61e34090be636ae3364b196', $options );

//$data=array();
$data=[
'payment_method' => 'cod',
'payment_method_title' => 'Cash on Delivery',
'set_paid' => false,
'billing' => [
    'first_name' => 'John',
    'last_name' => 'Doe',
    'address_1' => '969 Market',
    'city' => 'Karachi',
    'email' => 'princeali@testing.com',
    'phone' => '03123121995'
], 'line_items' => [

    [
        'product_id' => 779,
        'quantity' => 1
    ]
]
];  

print_r($client->post('orders', $data));

if($_POST !=null) {
}

else{
  echo "Null POST Request";
}   
} catch ( WC_API_Client_Exception $e ) {

   echo $e->getMessage() . PHP_EOL;
   echo $e->getCode() . PHP_EOL;

   if ( $e instanceof WC_API_Client_HTTP_Exception ) {
      print_r( $e->get_request() );
      print_r( $e->get_response() );
   }
}
  • 写回答

2条回答 默认 最新

  • dp815292 2017-04-25 06:24
    关注
    $orderData = array(    
        "order" => array(
            "billing_address" => array(
                array(
                    "first_name" => "",
                    "last_name" => "",
                    "company" => "",
                    "address_1" => "",
                    "address_2" => "",
                    "city" => "",
                    "state" => "",
                    "postcode" => "",
                    "country" => "",
                    "email" => "",
                    "phone" => "",
                )
            ),
            "shipping_address" => array(
                array(
                    "first_name" => "",
                    "last_name" => "",
                    "company" => "",
                    "address_1" => "",
                    "address_2" => "",
                    "city" => "",
                    "state" => "",
                    "postcode" => "",
                    "country" => "",
                )
            ),
            "customer_id" => 1,
            "line_items" => array( 
                array(
                    "product_id" => 1, 
                    "quantity" => 1
                ) 
            )
        )
    );
    
    $client->orders->create($orderData);
    

    Would you please try above code?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效