Skip to content

Commit 72e8f48

Browse files
committed
charge refund
1 parent cb82c7c commit 72e8f48

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/charge.md

+10
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ use Code4mk\LaraStripe\Lib\StripeCharge;
3636
$stripeCharge = new StripeCharge();
3737

3838
$stripeCharge->lists();
39+
```
40+
41+
### Refund Charge
42+
43+
```php
44+
use Code4mk\LaraStripe\Lib\StripeCharge;
45+
46+
$stripeCharge = new StripeCharge();
47+
48+
$stripeCharge->refund('charge_id');
3949
```

src/Lib/StripeCharge.php

+18
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,22 @@ public function lists()
206206
return (object) ['isError' => 'true', 'message' => $e->getMessage(), 'stripe' => $e->getJsonBody()['error']];
207207
}
208208
}
209+
210+
public function refund($chargeId, $amount = null)
211+
{
212+
$refundData = [
213+
'charge' => $chargeId,
214+
];
215+
216+
if ($amount) {
217+
$refundData['amount'] = round($amount, 2) * 100;
218+
}
219+
220+
try {
221+
$refund = $this->stripe->refunds->create($refundData);
222+
return $refund;
223+
} catch (\Exception $e) {
224+
return (object) ['isError' => 'true', 'message' => $e->getMessage(), 'stripe' => $e->getJsonBody()['error']];
225+
}
226+
}
209227
}

0 commit comments

Comments
 (0)