#smartkiparis

1 messages ยท Page 1 of 1 (latest)

fathom schoonerBOT
slim steeple
#

๐Ÿ‘‹ happy to help

#

you need to retrieve the charge and expand on refunds

#

which is a list of all refunds that have been applied to a charge

marble vigil
#

And it will have a sub array of refunds? So I can access through a loop like
foreach ($charge->refunds as $refund) {}

slim steeple
#

yes

#

it's actually $charge->refunds.data

marble vigil
#

ok, thanks!

slim steeple
#

let me know if you need any more help

marble vigil
#

What is a proper way to make a mock charge object with constructFrom method, that will include a set of fake refunds?

slim steeple
#

you can create a charge and pay it with these card numbers https://stripe.com/docs/testing#refunds to simulate refunds

Use test cards to validate your Stripe integration without moving real money. Test a variety of international scenarios, including successful and declined payments, card errors, disputes, and bank authentication. You can also test non-card payment methods.

marble vigil
#

Oh, no. That's not what I need

slim steeple
#

you need to create the refund yourself

marble vigil
#

In tests I create mock objects with static method for each object

slim steeple
#

are you talking about unit testing?

marble vigil
#

$chargeMock = Charge::constructFrom([
'id' => $chargeId,
'refunds' => [...Refund]
]);

#

I want something like this

#

yep, unit testing. I mock stripe API and create objects that should be returned

slim steeple
#

where is this function coming from?
Charge::constructFrom

marble vigil
#

No, I mock with PHPUnit mock

#

is this the correct way to expand retrieved charge?

slim steeple
#

yes but you would need to pass in refunds in the $expandedFields

marble vigil
#

yes, I understand that

#

thanks