我正在尝试模拟与Stripe一起使用的API进程。在应用程序中,正在使用一个按钮来调用Charge API。我没有在任何在线资源中看到这一点,这些资源都指向使用Plan API。除了正在寻找必需的product字段之外,其他所有都可以正常运行。 Mocking Stripe with Rspec之类的其他教程完全不包含product参数。我还尝试使用Stripe的API Reference中的值和其他硬编码值来模拟它,但是它说产品不存在。我曾尝试在plan =
语句之一或全部中使用此方法
context "stripe processor" do
let(:stripe_helper) { StripeMock.create_test_helper }
it "creates a stripe plan" do
plan = stripe_helper.create_plan(:id => 'my_plan', :amount => 1500)
# The above line replaces the following:
plan = Stripe::Plan.create(
:id => 'my_plan',
:name => 'StripeMock Default Plan ID',
:amount => 1500,
:currency => 'usd',
:interval => 'month'
)
expect(plan.id).to eq('my_plan')
expect(plan.amount).to eq(1500)
end
end
请注意,我正在使用stripe-ruby-mock gem。谢谢任何有想法的人。谢谢。
[在较新的API版本中,product
参数指的是产品ID,该产品在创建计划之前必须存在。参见this api revision。对于测试,您需要在创建计划之前确保给定的产品ID存在,否则您将收到看到的错误消息。
[您可能会同时使用stripe-ruby-mock
模拟产品和计划,但是看起来gem是在更改这些API之前构建的,可能需要修改才能在这里正常工作。