<commit_before><?php
namespace Payum\OmnipayBridge\Action;

use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\LogicException;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\PaymentAwareInterface;
use Payum\Core\PaymentInterface;
use Payum\Core\Request\Capture;
use Payum\Core\Request\ObtainCreditCard;
use Payum\Core\Security\SensitiveValue;

class CaptureAction extends BaseApiAwareAction implements PaymentAwareInterface
{
    /**
     * @var PaymentInterface
     */
    protected $payment;

    /**
     * {@inheritDoc}
     */
    public function setPayment(PaymentInterface $payment)
    {
        $this->payment = $payment;
    }

    /**
     * {@inheritDoc}
     */
    public function execute($request)
    {
        if (!$this->supports($request)) {
            throw RequestNotSupportedException::createActionNotSupported($this, $request);
        }

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if ($model['_status']) {
            return;
        }

        if (false == $model->validateNotEmpty(array('card'), false)) {
            try {
                $creditCardRequest = new ObtainCreditCard;
                $this->payment->execute($creditCardRequest);
                $card = $creditCardRequest->obtain();

                $firstName = $lastName = '';
                list($firstName, $lastName) = explode(' ', $card->getHolder(), 1);

                $model['card'] = new SensitiveValue(array(
                    'number' => $card->getNumber(),
                    'cvv' => $card->getSecurityCode(),
                    'expiryMonth' => $card->getExpireAt()->format('m'),
                    'expiryYear' => $card->getExpireAt()->format('y'),
                    'firstName' => $firstName,
                    'lastName' => $lastName,
                ));
            } catch (RequestNotSupportedException $e) {
                throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.');
            }
        }

        $response = $this->gateway->purchase($model->toUnsafeArray())->send();

        $model['_reference']      = $response->getTransactionReference();
        $model['_status']         = $response->isSuccessful() ? 'success' : 'failed';
        $model['_status_code']    = $response->getCode();
        $model['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage();
    }
<commit_msg>[omnipay] fix undefined offset 1 error. set holder name as first name always.<commit_after><?php
namespace Payum\OmnipayBridge\Action;

use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\LogicException;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\PaymentAwareInterface;
use Payum\Core\PaymentInterface;
use Payum\Core\Request\Capture;
use Payum\Core\Request\ObtainCreditCard;
use Payum\Core\Security\SensitiveValue;

class CaptureAction extends BaseApiAwareAction implements PaymentAwareInterface
{
    /**
     * @var PaymentInterface
     */
    protected $payment;

    /**
     * {@inheritDoc}
     */
    public function setPayment(PaymentInterface $payment)
    {
        $this->payment = $payment;
    }

    /**
     * {@inheritDoc}
     */
    public function execute($request)
    {
        if (!$this->supports($request)) {
            throw RequestNotSupportedException::createActionNotSupported($this, $request);
        }

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if ($model['_status']) {
            return;
        }

        if (false == $model->validateNotEmpty(array('card'), false)) {
            try {
                $creditCardRequest = new ObtainCreditCard;
                $this->payment->execute($creditCardRequest);
                $card = $creditCardRequest->obtain();

                $model['card'] = new SensitiveValue(array(
                    'number' => $card->getNumber(),
                    'cvv' => $card->getSecurityCode(),
                    'expiryMonth' => $card->getExpireAt()->format('m'),
                    'expiryYear' => $card->getExpireAt()->format('y'),
                    'firstName' => $card->getHolder(),
                    'lastName' => '',
                ));
            } catch (RequestNotSupportedException $e) {
                throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.');
            }
        }

        $response = $this->gateway->purchase($model->toUnsafeArray())->send();

        $model['_reference']      = $response->getTransactionReference();
        $model['_status']         = $response->isSuccessful() ? 'success' : 'failed';
        $model['_status_code']    = $response->getCode();
        $model['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage();
    }

{'fraction_non_alphanumeric': 0.14059967585089142, 'fraction_numerical': 0.0004051863857374392, 'mean_word_length': 2.4237170596393898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1078619', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1315, 'n_words': 244}