Woocommerce api集成帖不在流明中工作

时间:2018-04-24 13:04:19

标签: woocommerce lumen

我目前正在开发一个需要与woocommerce api集成的项目。我正在使用流明中的路由器编写端点。我已经成功完成了get方法。对于帖子http,响应是抛出不允许的方法。

以下是我的示例邮政编码:

$router->post('/post_order', function () {
    //$name = $request->input('name');


    $woocommerce = new Client(
        env('WOOCOMMERCE_URL'),
        env('WOOCOMMERCE_CONSUMER_KEY'),
        env('WOOCOMMERCE_CONSUMER_SECRET'),
        [
            'wp_api' => true,
            'version' => 'wc/v2',
        ]
    );

    $data = [
        'payment_method' => 'bacs',
        'payment_method_title' => 'Direct Bank Transfer',
        'set_paid' => true,
        'billing' => [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'address_1' => '969 Market',
            'address_2' => '',
            'city' => 'San Francisco',
            'state' => 'CA',
            'postcode' => '94103',
            'country' => 'US',
            'email' => 'john.doe@example.com',
            'phone' => '(555) 555-5555'
        ],
        'shipping' => [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'address_1' => '969 Market',
            'address_2' => '',
            'city' => 'San Francisco',
            'state' => 'CA',
            'postcode' => '94103',
            'country' => 'US'
        ],
        'line_items' => [
            [
                'product_id' => 93,
                'quantity' => 2
            ],
            [
                'product_id' => 22,
                'variation_id' => 23,
                'quantity' => 1
            ]
        ],
        'shipping_lines' => [
            [
                'method_id' => 'flat_rate',
                'method_title' => 'Flat Rate',
                'total' => 10
            ]
        ]
    ];


    $order = $woocommerce->post('orders', $data);

    return response()->json($order);
});

0 个答案:

没有答案