/** * {@inheritdoc} */ public function execute($request) { /** @var $request Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if (null != $model['response_code']) { return; } if (false == $model->validateNotEmpty(array('card_num', 'exp_date'), false)) { try { $this->payment->execute($obtainCreditCard = new ObtainCreditCard()); $card = $obtainCreditCard->obtain(); $model['exp_date'] = new SensitiveValue($card->getExpireAt()->format('m/y')); $model['card_num'] = new SensitiveValue($card->getNumber()); } 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.'); } } $api = clone $this->api; $api->ignore_not_x_fields = true; $api->setFields(array_filter($model->toUnsafeArray())); $response = $api->authorizeAndCapture(); $model->replace(get_object_vars($response)); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($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'] = $card->getNumber(); $model['CVV2'] = $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.'); } } $buzzRequest = new Request(); $buzzRequest->setFields($model->toUnsafeArray()); $response = $this->api->doPayment($buzzRequest); $model->replace($response); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $details = ArrayObject::ensureArrayObject($request->getModel()); if ($details['_status']) { return; } if (false == $details['clientIp']) { $this->payment->execute($httpRequest = new GetHttpRequest); $details['clientIp'] = $httpRequest->clientIp; } if (isset($details['_completeCaptureRequired'])) { $response = $this->gateway->completePurchase($details->toUnsafeArray())->send(); unset($details['_completeCaptureRequired']); } else { if (false == $details->validateNotEmpty(array('card'), false) && false == $details->validateNotEmpty(array('cardReference'), false)) { try { $this->payment->execute($creditCardRequest = new ObtainCreditCard); $card = $creditCardRequest->obtain(); $details['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($details->toUnsafeArray())->send(); } if ($response->isRedirect()) { $details['_completeCaptureRequired'] = 1; if ($response->getRedirectMethod() == 'POST') { throw new HttpPostRedirect($response->getRedirectUrl(), $response->getRedirectData()); } else { throw new HttpRedirect($response->getRedirectUrl()); } } $details['_reference'] = $response->getTransactionReference(); $details['_status'] = $response->isSuccessful() ? 'captured' : 'failed'; $details['_status_code'] = $response->getCode(); $details['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage(); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request ObtainToken */ RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); if ($model['card']) { throw new LogicException('Payment already has token set'); } $obtainCreditCard = new ObtainCreditCard($request->getToken()); $obtainCreditCard->setModel($request->getFirstModel()); $obtainCreditCard->setModel($request->getModel()); $this->gateway->execute($obtainCreditCard); $card = $obtainCreditCard->obtain(); $local = $model->getArray('local'); $createTokenForCreditCard = new CreateTokenForCreditCard($card); $createTokenForCreditCard->setToken((array) $local->getArray('token')); $this->gateway->execute($createTokenForCreditCard); $token = ArrayObject::ensureArrayObject($createTokenForCreditCard->getToken()); $local['token'] = $token->toUnsafeArray(); $model['local'] = (array) $local; if ($token['id']) { $model['card'] = $token['id']; } else { $model['status'] = Constants::STATUS_FAILED; } }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $model = new ArrayObject($request->getModel()); if (null !== $model['EXECCODE']) { return; } if (false == $model['CLIENTUSERAGENT']) { $this->gateway->execute($httpRequest = new GetHttpRequest()); $model['CLIENTUSERAGENT'] = $httpRequest->userAgent; } if (false == $model['CLIENTIP']) { $this->gateway->execute($httpRequest = new GetHttpRequest()); $model['CLIENTIP'] = $httpRequest->clientIp; } $cardFields = array('CARDCODE', 'CARDCVV', 'CARDVALIDITYDATE', 'CARDFULLNAME'); if (false == $model->validateNotEmpty($cardFields, false) && false == $model['ALIAS']) { try { $this->gateway->execute($creditCardRequest = new ObtainCreditCard()); $card = $creditCardRequest->obtain(); $model['CARDVALIDITYDATE'] = new SensitiveValue($card->getExpireAt()->format('m-y')); $model['CARDCODE'] = $card->getNumber(); $model['CARDFULLNAME'] = $card->getHolder(); $model['CARDCVV'] = $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.'); } } //instruction must have an alias set (e.g oneclick payment) or credit card info. if (false == ($model['ALIAS'] || $model->validateNotEmpty($cardFields, false))) { throw new LogicException('Either credit card fields or its alias has to be set.'); } $result = $this->api->payment($model->toUnsafeArray()); $model->replace((array) $result); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $details = ArrayObject::ensureArrayObject($request->getModel()); if ($details['_status']) { return; } if (false == isset($details['_completeCaptureRequired'])) { if (false == $details->validateNotEmpty(array('card'), false) && false == $details->validateNotEmpty(array('cardReference'), false)) { try { $this->gateway->execute($creditCardRequest = new ObtainCreditCard()); $card = $creditCardRequest->obtain(); $details['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.'); } } } parent::execute($request); }
/** * @test * * @expectedException \Payum\Core\Exception\LogicException * @expectedExceptionMessage Credit card could not be obtained. It has to be set before obtain. */ public function throwIfObtainCalledBeforeCreditCardSet() { $request = new ObtainCreditCard(); $request->obtain(); }