【问题标题】:Shopify API: Refunds not showing in ShopifyShopify API:退款未在 Shopify 中显示
【发布时间】:2020-07-04 17:10:35
【问题描述】:

我正在处理我的应用针对特定缺货产品的退款。发布退款的 API 调用似乎仍然存在,但当我检查订单时,Shopify 中没有显示任何内容。

我有一个名为“refund_line_items”的数组中要退款的订单项,我从该数组中映射各个项目以进行调用。

这是我的代码:

refund_calculation = ShopifyAPI::Refund.calculate({
  currency: "USD",
  notify: false,
  note: "Out of stock",
  shipping: { 
    "full_refund": false 
  },  
  refund_line_items: refund_line_items.map { |li|
    {
      line_item_id: li.id,
      quantity: li.quantity,
      restock_type: 'no_restock',
    }
  },
}, { 
    params: { order_id: shopify_order.id },
})

order_refund = ShopifyAPI::Refund.new({
  currency: "USD",
  notify: false,
  note: "Out of stock",
  shipping: { 
    "full_refund": false 
  },
  refund_line_items: refund_line_items.map { |li|
    {
      line_item_id: li.id,
      quantity: li.quantity,
      restock_type: 'no_restock'
    }
  },
  transactions: refund_calculation.transactions.map { |tr|
    {
      kind: "refund",
      gateway: tr.gateway,
      parent_id: tr.parent_id,
      amount: tr.amount
    }
  },
}, {
  params: { order_id: shopify_order.id }
})

这是退款后 API 调用之一的输出:

#<ShopifyAPI::Refund:0x0000561b935e4700
 @attributes=
  {"currency"=>"USD",
   "notify"=>false,
   "note"=>"Out of stock",
   "shipping"=>
    #<ShopifyAPI::Refund::Shipping:0x0000561b935e40c0
     @attributes={"full_refund"=>false},
     @persisted={:params=>{:order_id=>2528875905114}},
     @prefix_options={}>,
   "refund_line_items"=>
    [#<ShopifyAPI::Refund::RefundLineItem:0x0000561b935ef830
      @attributes=
       {"line_item_id"=>5596452192346,
        "quantity"=>1,
        "restock_type"=>"no_restock"},
      @persisted={:params=>{:order_id=>2528875905114}},
      @prefix_options={}>],
   "transactions"=>
    [#<ShopifyAPI::Transaction:0x0000561b935ef038
      @attributes=
       {"kind"=>"refund",
        "gateway"=>"shopify_payments",
        "parent_id"=>3161136562266,
        "amount"=>"11.72"},
      @persisted={:params=>{:order_id=>2528875905114}},
      @prefix_options={}>]},
 @persisted={:params=>{:order_id=>2528875905114}},
 @prefix_options={}>

从这个输出看来,退款似乎是持久的,但经过检查,它实际上并没有持久。我在这里做错了什么?谢谢。

【问题讨论】:

    标签: ruby-on-rails shopify-app shopify-api


    【解决方案1】:

    我发现了问题。

    我必须将订单 ID 指定为 prefix_option 并明确保存记录。

    像这样:

    # Create refund on Shopify
    order_refund = ShopifyAPI::Refund.new({
      currency: "USD",
      notify: false,
      note: "Out of stock",
      shipping: { 
        "full_refund": false 
      },
      refund_line_items: refund_line_items.map { |li|
        {
          line_item_id: li.id,
          quantity: li.quantity,
          restock_type: 'cancel'
        }
      },
      transactions: refund_calculation.transactions.map { |tr|
        {
          kind: "refund",
          gateway: tr.gateway,
          parent_id: tr.parent_id,
          amount: tr.amount
        }
      },
    }, {
      params: { order_id: shopify_order.id }
    })
    order_refund.prefix_options = { order_id: shopify_order.id }
    order_refund.save
    

    【讨论】:

      猜你喜欢
      • 2021-10-22
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多