Ruby 在条纹中创建电荷后重新启动
我在Ruby文件中有以下代码Ruby 在条纹中创建电荷后重新启动,ruby,stripe-payments,stripe.js,Ruby,Stripe Payments,Stripe.js,我在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 => param
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
我的问题是在成功创建charge之后如何传递json值
非常感谢您的帮助
非常感谢如果您想返回收费请求的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
你有没有尝试过收费的.to_json或.as_json?否则请尝试JSON.parse(charge.data)您好谢谢您的回复您能告诉我我们应该如何处理JS文件吗:)好的,如果您使用jQuery,您可以使用$.post(“endpoint”,{},function(data){var response=jQuery.parseJSON(data);console.log(response)})你也可以参考,谢谢,但我的响应是空的,我部署了我的条带费用代码在heroku中。你能在浏览器网络选项卡中检查它是否返回响应数据吗?