mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-07 09:50:23 +00:00
63 - Capturing Charges with Callbacks
This commit is contained in:
@@ -38,4 +38,27 @@ class StripePaymentGateway implements PaymentGateway
|
||||
]
|
||||
], ['api_key' => $this->apiKey])->id;
|
||||
}
|
||||
|
||||
public function newChargesDuring($callback)
|
||||
{
|
||||
$latestCharge = $this->lastCharge();
|
||||
$callback($this);
|
||||
return $this->newChargesSince($latestCharge)->pluck('amount');
|
||||
}
|
||||
|
||||
private function lastCharge()
|
||||
{
|
||||
return array_first(\Stripe\Charge::all([
|
||||
'limit' => 1
|
||||
], ['api_key' => $this->apiKey])['data']);
|
||||
}
|
||||
|
||||
private function newChargesSince($charge = null)
|
||||
{
|
||||
$newCharges = \Stripe\Charge::all([
|
||||
'ending_before' => $charge ? $charge->id : null,
|
||||
], ['api_key' => $this->apiKey])['data'];
|
||||
|
||||
return collect($newCharges);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user