165 - Splitting Payments with Stripe

This commit is contained in:
Adam Wathan
2018-01-26 13:40:58 -05:00
parent 7442baa5c5
commit def3e0b6b2
3 changed files with 32 additions and 9 deletions

View File

@@ -15,18 +15,23 @@ class StripePaymentGateway implements PaymentGateway
$this->apiKey = $apiKey;
}
public function charge($amount, $token)
public function charge($amount, $token, $destinationAccountId)
{
try {
$stripeCharge = \Stripe\Charge::create([
'amount' => $amount,
'source' => $token,
'currency' => 'usd',
'destination' => [
'account' => $destinationAccountId,
'amount' => $amount * .9,
]
], ['api_key' => $this->apiKey]);
return new Charge([
'amount' => $stripeCharge['amount'],
'card_last_four' => $stripeCharge['source']['last4'],
'destination' => $destinationAccountId,
]);
} catch (InvalidRequest $e) {
throw new PaymentFailedException;