我正在尝试像这样模拟 Stripe:
stub_request(:post, "https://api.stripe.com/v1/tokens").with(
:body => {"card" => {"number" => "4242424242424242", "exp_month"=> "12", "exp_year" => "2018", "cvc" => "123"}}
).
to_return(:status => 200, :headers => {}, :body => {
"id" => "tok_14CgP22eZvKYlo2CkgJ6ymLE",
"livemode" => false,
"created" => 1404517660,
"used" => false,
"object" => "token",
"type" => "card",
"card" => {
"id" => "card_14CgP22eZvKYlo2CcdUNvicW",
"object" => "card",
"last4" => "4242",
"brand" => "Visa",
"funding" => "credit",
"exp_month" => 12,
"exp_year" => 2018,
"fingerprint" => "Xt5EWLLDS7FJjR1c",
"country" => "US"
}
})
no implicit conversion of Hash into String
我打电话时遇到错误:
token = Stripe::Token.create(:card => {
:number => params["number"],
:exp_month => params["expiry_month"],
:exp_year => params["expiry_year"],
:cvc => params["cvc"]})
body
这是因为 in中的哈希to_return
,但我不知道如何避免该错误。
如果我添加.to_s
到哈希中,我会得到:
来自 API 的无效响应对象:"{\"id\"=>\"tok_14CgP22eZvKYlo2CkgJ6ymLE\", \"livemode\"=>false, \"created\"=>1404517660, \"used\"=>false, \" object\"=>\"token\", \"type\"=>\"card\", \"card\"=>{\"id\"=>\"card_14CgP22eZvKYlo2CcdUNvicW\", \"object\" =>\"card\", \"last4\"=>\"4242\", \"brand\"=>\"Visa\", \"funding\"=>\"credit\", \"exp_month \"=>12, \"exp_year\"=>2018, \"fingerprint\"=>\"Xt5EWLLDS7FJjR1c\", \"country\"=>\"US\"}}"(HTTP 响应代码为 200)
如果我.to_json
在末尾添加 a ,则Stripe::Token
通过,stack error too deep
但当我尝试以token
任何方式使用结果时出现错误。
你有什么建议吗?