我正在尝试使用后勤api的webhook根据其Webhook请求更改我的Order
状态。 API Create Order
的请求工作正常,但是当我Cancel Order
仅从服务器到API服务器的成功请求时,Order
的状态仍然没有改变。我不确定webhook是否正常工作
Webhook请求标头Content-Type
是application/json
。
身体像
{
"OrderCode": "DC5D4NFUH",
"CurrentStatus": "Picking" //other status: delivered, cancel
}
//order.rb model
enum status: {
in_progress: 0,
shipping: 1,
complete: 2,
cancel: 3
}
//routes.rb
post 'orders/api_webhook', to: 'orders#api_webhook'
//orders_controller.rb
class OrdersController < ApplicationController
skip_before_action :verify_authenticity_token
def api_webhook
event = JSON.parse(request.body.read)
if event['OrderCode']
@payment = Payment.find_by(order_code: event['OrderCode'])
case event['CurrentStatus']
when "Picking"
@payment.status = 1
when "Delivered"
@payment.status = 2
when "Cancel"
@payment.status = 3
end
@payment.save
end
end
end