src/gateways/Gateway.php
private function _buildRequestPaymentSource(Transaction $transaction, Payment $paymentForm, array $request): Source
    {
        // For 3D secure, make sure to set the redirect URL and the metadata flag, so we can catch it later.
        if ($paymentForm->threeDSecure) {
            unset($request['description'], $request['receipt_email']);


            $request['type'] = 'three_d_secure';

            $request['three_d_secure'] = [
                'card' => $paymentForm->token
            ];

            $request['redirect'] = [
                'return_url' => UrlHelper::actionUrl('commerce/payments/complete-payment', ['commerceTransactionId' => $transaction->id, 'commerceTransactionHash' => $transaction->hash])
            ];

            $request['metadata']['three_d_secure_flow'] = true;

            return Source::create($request);
        }

        if ($paymentForm->token) {
            $paymentForm->token = $this->_normalizePaymentToken((string)$paymentForm->token);
            /** @var Source $source */
            $source = Source::retrieve($paymentForm->token);

            // If this required 3D secure, let's set the flag for it  and repeat
            if (!empty($source->card->three_d_secure) && $source->card->three_d_secure == 'required') {
                $paymentForm->threeDSecure = true;

                return $this->_buildRequestPaymentSource($transaction, $paymentForm, $request);
            }

            return $source;
        }

        throw new PaymentException(Craft::t('commerce-stripe', 'Cannot process the payment at this time'));
    }
private function _buildRequestPaymentSource(Transaction $transaction, Payment $paymentForm, array $request): Source
    {
        // For 3D secure, make sure to set the redirect URL and the metadata flag, so we can catch it later.
        if ($paymentForm->threeDSecure) {
            unset($request['description'], $request['receipt_email']);


            $request['type'] = 'three_d_secure';

            $request['three_d_secure'] = [
                'card' => $paymentForm->token
            ];

            $request['redirect'] = [
                'return_url' => UrlHelper::actionUrl('commerce/payments/complete-payment', ['commerceTransactionId' => $transaction->id, 'commerceTransactionHash' => $transaction->hash])
            ];

            $request['metadata']['three_d_secure_flow'] = true;

            return Source::create($request);
        }

        if ($paymentForm->token) {
            $paymentForm->token = $this->_normalizePaymentToken((string)$paymentForm->token);
            /** @var Source $source */
            $source = Source::retrieve($paymentForm->token);

            // If this required 3D secure, let's set the flag for it  and repeat
            if (!empty($source->card->three_d_secure) && $source->card->three_d_secure == 'required') {
                $paymentForm->threeDSecure = true;

                return $this->_buildRequestPaymentSource($transaction, $paymentForm, $request);
            }

            return $source;
        }

        throw new PaymentException(Craft::t('commerce-stripe', 'Cannot process the payment at this time'));
    }
private function _buildRequestPaymentSource ( Transaction $ transaction , Payment $ paymentForm , array $ request ) : Source { // For 3D secure, make sure to set the redirect URL and the metadata flag, so we can catch it later. if ( $ paymentForm -> threeDSecure ) { unset ( $ request [ 'description' ] , $ request [ 'receipt_email' ] ) ; $ request [ 'type' ] = 'three_d_secure' ; $ request [ 'three_d_secure' ] = [ 'card' => $ paymentForm -> token ] ; $ request [ 'redirect' ] = [ 'return_url' => UrlHelper :: actionUrl ( 'commerce/payments/complete-payment' , [ 'commerceTransactionId' => $ transaction -> id , 'commerceTransactionHash' => $ transaction -> hash ] ) ] ; $ request [ 'metadata' ] [ 'three_d_secure_flow' ] = true ; return Source :: create ( $ request ) ; } if ( $ paymentForm -> token ) { $ paymentForm -> token = $ this -> _normalizePaymentToken ( ( string ) $ paymentForm -> token ) ; /** @var Source $source */ $ source = Source :: retrieve ( $ paymentForm -> token ) ; // If this required 3D secure, let's set the flag for it  and repeat if ( ! empty ( $ source -> card -> three_d_secure ) && $ source -> card -> three_d_secure == 'required' ) { $ paymentForm -> threeDSecure = true ; return $ this -> _buildRequestPaymentSource ( $ transaction , $ paymentForm , $ request ) ; } return $ source ; } throw new PaymentException ( Craft :: t ( 'commerce-stripe' , 'Cannot process the payment at this time' ) ) ; }
Build a payment source for request.

@param Transaction $transaction the transaction to be used as base
@param Payment $paymentForm the payment form
@param array $request the request data

@return Source
@throws PaymentException if unexpected payment information encountered
Build a payment source for request .