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 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容