我在Ruby文件中有以下代码
post '/create_charge' do
# Create the charge on Stripe's servers
begin
charge = Stripe::Charge.create(
:amount => params[:amount], # this number should be in cents
:currency => "usd",
:source => params[:source],
:description => "sample"
)
rescue Stripe::StripeError => e
status 402
return log_info("Error creating charge: #{e.message}")
end
status 200
return log_info("Charge successfully created")
end
我的问题是如何在成功充电后传递json值。
非常感谢任何帮助。
非常感谢
答案 0 :(得分:0)
如果您想要返回充电请求的json响应,您可以将费用转入响应主体:
post '/create_charge' do
# Create the charge on Stripe's servers
charge = {}
begin
charge = Stripe::Charge.create(
:amount => params[:amount], # this number should be in cents
:currency => "usd",
:source => params[:source],
:description => "sample"
)
rescue Stripe::StripeError => e
status 402
return log_info("Error creating charge: #{e.message}")
end
status 200
content_type :json
body charge.to_json
return log_info("Charge successfully created")
end