#Beninate-refund

1 messages · Page 1 of 1 (latest)

high cradle
#

Is this a connect charge/refund?

rotund sparrow
#

not Connect just regular Payments

high cradle
#

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)

rotund sparrow
#

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
high cradle
rotund sparrow
#

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

regal marsh
#

if you're using stripe-ruby-mock, do you even expect to be sending requests to the real api?

rotund sparrow
#

heh, no i suspect not

rotund sparrow
#

any thoughts...? 😬

regal marsh
#

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?

rotund sparrow
#

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

regal marsh
#

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

#

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)

rotund sparrow
#

no worries, still digesting. thx

regal marsh
#

last minute meeting cancelation, so I'm around after all

rotund sparrow
#

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

regal marsh
#

np!

rotund sparrow
regal marsh
#

oops, instance_method, sorry

rotund sparrow
#

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?

regal marsh
#

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)?

rotund sparrow
#

"local"

regal marsh
#

huuuuuh

#

could you try stepping into the create call?

rotund sparrow
#

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

regal marsh
#

where is it going off the rails that it talks to the actual api?

rotund sparrow
#

lemme see here

#

hm... not sure how "step" through the create call tbh

regal marsh
#

step advances execution to the next line of code, stepping into a function call if necessary

rotund sparrow
#

im embarassingly unfamiliar with stepping through this way (though it seems super useful). So far this is the only relevant area ive ended up

regal marsh
#

sorry, I stepped away for a bit