# give/4.15.0/src/PaymentGateways/Gateways/Stripe/Traits/HandlePaymentIntentStatus.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.15.0. 40 lines.

- Page: https://pluginprobe.com/plugins/give/4.15.0/code/src/PaymentGateways/Gateways/Stripe/Traits/HandlePaymentIntentStatus.php
- Raw: https://pluginprobe.com/plugins/give/4.15.0/raw/src/PaymentGateways/Gateways/Stripe/Traits/HandlePaymentIntentStatus.php
- Modified: 2023-05-18T23:16:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.15.0/code/src/PaymentGateways/Gateways/Stripe/Traits/HandlePaymentIntentStatus.php#L10-L20`.

```php
<?php

namespace Give\PaymentGateways\Gateways\Stripe\Traits;

use Give\Donations\Models\Donation;
use Give\Framework\PaymentGateways\Commands\PaymentCommand;
use Give\Framework\PaymentGateways\Commands\PaymentComplete;
use Give\Framework\PaymentGateways\Commands\PaymentProcessing;
use Give\Framework\PaymentGateways\Commands\RedirectOffsite;
use Give\PaymentGateways\Gateways\Stripe\Exceptions\PaymentIntentException;
use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentIntent;

trait HandlePaymentIntentStatus
{
    /**
     * @since 2.27.1 Update PaymentIntentException message.
     * @since 2.21.0 Update second argument type to Donation model
     * @since 2.19.7 fix param order and only pass donationId
     *
     * @return PaymentCommand|RedirectOffsite
     * @throws PaymentIntentException
     */
    public function handlePaymentIntentStatus(PaymentIntent $paymentIntent, Donation $donation)
    {
        switch ($paymentIntent->status()) {
            case 'requires_action':
                $donation->gatewayTransactionId = $paymentIntent->id();
                $donation->save();
                return new RedirectOffsite($paymentIntent->nextActionRedirectUrl());
            case 'succeeded':
                return new PaymentComplete($paymentIntent->id());
            case 'processing':
                return new PaymentProcessing($paymentIntent->id());
            default:
                throw new PaymentIntentException(
                    sprintf(__('Unhandled payment intent status: %s', 'give'), $paymentIntent->status()));
        }
    }
}

```
