mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-17 09:53:57 +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;
|
], ['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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class StripePaymentGatewayTest extends TestCase
|
|||||||
{
|
{
|
||||||
$paymentGateway = $this->getPaymentGateway();
|
$paymentGateway = $this->getPaymentGateway();
|
||||||
|
|
||||||
// How could we make this API work?
|
$newCharges = $paymentGateway->newChargesDuring(function ($paymentGateway) {
|
||||||
$newCharges = $paymentGateway->newChargesDuring(function () {
|
|
||||||
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
$paymentGateway->charge(2500, $paymentGateway->getValidTestToken());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user