| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\Gateways\Stripe\Traits; |
| 4 |
|
| 5 |
use Give\Donations\Models\Donation; |
| 6 |
use Give\Framework\PaymentGateways\Commands\PaymentCommand; |
| 7 |
use Give\Framework\PaymentGateways\Commands\PaymentComplete; |
| 8 |
use Give\Framework\PaymentGateways\Commands\PaymentProcessing; |
| 9 |
use Give\Framework\PaymentGateways\Commands\RedirectOffsite; |
| 10 |
use Give\PaymentGateways\Gateways\Stripe\Exceptions\PaymentIntentException; |
| 11 |
use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentIntent; |
| 12 |
|
| 13 |
trait HandlePaymentIntentStatus |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @since 2.27.1 Update PaymentIntentException message. |
| 17 |
* @since 2.21.0 Update second argument type to Donation model |
| 18 |
* @since 2.19.7 fix param order and only pass donationId |
| 19 |
* |
| 20 |
* @return PaymentCommand|RedirectOffsite |
| 21 |
* @throws PaymentIntentException |
| 22 |
*/ |
| 23 |
public function handlePaymentIntentStatus(PaymentIntent $paymentIntent, Donation $donation) |
| 24 |
{ |
| 25 |
switch ($paymentIntent->status()) { |
| 26 |
case 'requires_action': |
| 27 |
$donation->gatewayTransactionId = $paymentIntent->id(); |
| 28 |
$donation->save(); |
| 29 |
return new RedirectOffsite($paymentIntent->nextActionRedirectUrl()); |
| 30 |
case 'succeeded': |
| 31 |
return new PaymentComplete($paymentIntent->id()); |
| 32 |
case 'processing': |
| 33 |
return new PaymentProcessing($paymentIntent->id()); |
| 34 |
default: |
| 35 |
throw new PaymentIntentException( |
| 36 |
sprintf(__('Unhandled payment intent status: %s', 'give'), $paymentIntent->status())); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|