#Beninate-refund
1 messages · Page 1 of 1 (latest)
not Connect just regular Payments
The most common cause for this error is making the refund call from an account that is different from the one that made the charge
Do you have the request ID from when you got this error? (req_!23)
um, lemme see if i can grab that
hmm im not sure how to access that.
this comes from calling:
Stripe::Refund.create({
amount: 1000,
payment_intent: 'test_pi_1',
})
this is setup in a test as follows:
describe 'POST #refund' do
let!(:championship) { FactoryBot.create(:championship, host: host) }
let!(:payment_intent) { Stripe::PaymentIntent.create({ amount: 2000, currency: 'gbp', payment_method_types: ['card'] }) }
let!(:order) { FactoryBot.create(:order, payment_id: payment_intent.id) }
let!(:order_item) { FactoryBot.create(:order_item, host: host) }
before do
sign_in(user)
post :refund, params: { host_id: host.id, id: order_item.id }
end
it { expect(response).to have_http_status(:found) }
end
using stripe-ruby-mock for mocking the objects: https://github.com/stripe-ruby-mock/stripe-ruby-mock
Can you get the request ID for a time you made this call? https://stripe.com/docs/api/request_ids
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Will also be in your dashboard https://dashboard.stripe.com/test/logs
req_eTwcEuIEccPOtn
interesting that the payment_intent id does not match what im passing in....... 🧐
standby...
hm ok. so i fixed the problem of the ids not matching properly, but still getting the same error. however, i dont seem to be able to get a request id...
requests aren't showing up in the dashboard and when i try to manually output it, i think it's breaking before it can do that
if you're using stripe-ruby-mock, do you even expect to be sending requests to the real api?
heh, no i suspect not
any thoughts...? 😬
just to recap, my understanding is:
you're creating a mocked PI, hooking that up to an order item in your own system, then going to refund the order, which ought to refund the mocked PI.
you're not seeing an API request for creating the mocked PI (as expected), but refunding the PI does create a real API request, and is not going through the mock.
you seem to be using rack-test, which does the post to your system as an in-memory test, so I'd expect setting up a mock in your tests to carry over to the mock in your code, but clearly that's not happening. are you maybe re-initializing or configuring the stripe-ruby connection somewhere in the code under test, or otherwise between the point where you set up the mock & the point where the real api request is being made?
that's all correct
so for this whole test file, i've got this at the top:
before { StripeMock.start }
after { StripeMock.stop }
which should be mocking everything
and i haven't had issues with any other Stripe mocks
probably what I would recommend is dropping a binding.pry into the place just before you do the refund, and confirming whether stripe mock is set up at that point
probably the canonical way to check that is to see what Stripe::StripeClient.method(:execute_request) is pointed at
since that's what https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/f291ba4e33cf72a6c7c4daab5b47b44b7511eca1/lib/stripe_mock/api/instance.rb#L10 overrides
if that is indeed the problem, then probably the next thing to do is to confirm that stripe mock is set up correctly at the point where the test starts running, by using the same check
and then working towards the middle to figure out where it's getting unset
(I have to run for now, will be back in ~1h)
no worries, still digesting. thx
last minute meeting cancelation, so I'm around after all
thanks, unfortunately i got pulled off on something else myself for a while so i may not be able to look at this for some time
thx for your help tho
np!
oops, instance_method, sorry
ok. that outputs:
"#<UnboundMethod: Stripe::StripeClient#execute_request(*args, **keyword_args) /Users/tonybeninate/.rvm/gems/ruby-2.7.4@thesimgrid/gems/stripe-ruby-mock-3.1.0.rc3/lib/stripe_mock/api/instance.rb:10>"
which i think is correct?
yeah, ok - that looks right to me
hmm
is stripe-mock in livemode, maybe?
(stripe-mock confusingly defines livemode as talking to the actual api, not running in livemode)
what do you get for StripeMock.instance_variable_get(:@state)?
"local"
it almost feels like im on a legacy version of the gem, but a) im on the latest version and b) refund api doesn't seem to have changed in a long time
where is it going off the rails that it talks to the actual api?
byebug has a step command https://gist.github.com/elrayle/e88693f74d4f02803d54d75150e3bfad
step advances execution to the next line of code, stepping into a function call if necessary
im embarassingly unfamiliar with stepping through this way (though it seems super useful). So far this is the only relevant area ive ended up
sorry, I stepped away for a bit