/**
* {@inheritDoc}
*/
public function execute($request)
{
/** @var $request Capture */
RequestNotSupportedException::assertSupports($this, $request);
$model = new ArrayObject($request->getModel());
if (is_numeric($model['RESULT'])) {
return;
}
$cardFields = array('ACCT', 'CVV2', 'EXPDATE');
if (false == $model->validateNotEmpty($cardFields, false)) {
try {
$this->payment->execute($obtainCreditCard = new ObtainCreditCard());
$card = $obtainCreditCard->obtain();
$model['EXPDATE'] = new SensitiveValue($card->getExpireAt()->format('my'));
$model['ACCT'] = new SensitiveValue($card->getNumber());
$model['CVV2'] = new SensitiveValue($card->getSecurityCode());
} 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.');
}
}
$model->replace($this->api->doSale($model->toUnsafeArray()));
}