【问题标题】:Checkout API Shopify- Not adding any post dataCheckout API Shopify - 不添加任何帖子数据
【发布时间】:2019-12-24 06:12:55
【问题描述】:

我正在尝试使用 Checkout API 创建结帐,我的应用是一个销售渠道,并且具有“writing_checkouts”的访问权限。 该产品在销售渠道上列出,但是当我尝试创建结帐时,200 中的请求响应返回一个完整的结帐对象,但没有添加诸如电子邮件、line_items 或送货地址之类的字段。 下面是示例代码:

     $field = array(
      "checkout"=>array(
        "email"=> "john.smith@example.com",
        "line_items"=> array(array(
          "variant_id"=> 31520093667373,
          "quantity"=> 1
        )),
        "shipping_address"=> array(
          "first_name"=> "John",
          "last_name"=> "Smith",
          "address1"=> "126 York St.",
          "city"=> "Ottawa",
          "province_code"=> "ON",
          "country_code"=> "CA",
          "phone"=> "(123)456-7890",
          "zip"=> "K1N 5T5"
        )
      )
    );
    $data = json_encode($field);
    $url=$shopUrl.'/checkouts.json';
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_HTTPHEADER => array(
            "Authorization: Basic Og==",
            "accept: application/json",
            "content-type: application/graphql",
            "X-Shopify-Access-Token: ********************************",
        ),
        CURLOPT_POSTFIELDS=> $postFields
    ));    
    $response = curl_exec($curl);
    $err = curl_error($curl);    
    curl_close($curl);
    if ($err) {
        echo $err;
    } else {
        echo $response;
    }

这是我得到的回应:

{"checkout":
{"completed_at":null,
"created_at":"2019-12-24T00:02:15-05:00", 
"currency":"PKR",
"presentment_currency":"PKR",
"customer_id":null,
"email":null,
"name":"#11978400727085","note":"",
"order_id":null,
"order_status_url":null,
"subtotal_price":"0.00",
"token":"*******************************",
"total_price":"0.00",
"total_tax":"0.00",
"total_tip_received":"0.00",
"total_line_items_price":"0.00",
"updated_at":"2019-12-24T00:02:15-05:00",
"user_id":null,
"line_items":[],
"gift_cards":[],
"tax_lines":[],
"shipping_line":null,
"shipping_rate":null,
"shipping_address":null,
"credit_card":null,
"billing_address":null,
"applied_discount":null}
}

【问题讨论】:

  • 嗨@Sardar,我也遇到了同样的问题你解决了吗?谢谢

标签: php shopify checkout shopify-app


【解决方案1】:

如果有人在这里寻找答案,我遇到了同样的问题并进行了以下更改:

  • 在 OAuth 中添加 read_orders 范围
  • 在 OAuth 中添加 read_checkouts 和 write_checkouts 范围
  • 使用 “content-type: application/json” 而不是“content-type: application/graphql”

【讨论】:

    【解决方案2】:

    订单项不是数组的数组。它们是一组对象,或者换句话说,是一组散列项。尝试发送一个对象数组,它可能会更好。在 JSON 术语中...您会看到 [{},{},...] 而您似乎正在执行 [[],[],...] ,这很接近但并不完全相同。

    也许我遗漏了一些东西,PHP 的术语是问题所在,但我认为数组数组是错误的。

    【讨论】:

    • 感谢您的回复,这是 shopify 结帐文档中未列出的范围问题。 $data = json_encode($field);这会将我的订单项转换为 PHP 中的 json 数据数组。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 2016-11-21
    相关资源
    最近更新 更多