コード例 #1
0
 /**
  * {@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;
     }
 }
コード例 #2
0
ファイル: CaptureAction.php プロジェクト: payum/payum
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     if (null != $model['response_code']) {
         return;
     }
     if (false == $model->validateNotEmpty(array('card_num', 'exp_date'), false)) {
         try {
             $obtainCreditCard = new ObtainCreditCard($request->getToken());
             $obtainCreditCard->setModel($request->getFirstModel());
             $obtainCreditCard->setModel($request->getModel());
             $this->gateway->execute($obtainCreditCard);
             $card = $obtainCreditCard->obtain();
             $model['exp_date'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('m/y'));
             $model['card_num'] = SensitiveValue::ensureSensitive($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));
 }
コード例 #3
0
ファイル: CaptureAction.php プロジェクト: puwenhan/Payum
 /**
  * {@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 {
             $obtainCreditCard = new ObtainCreditCard($request->getToken());
             $obtainCreditCard->setModel($request->getFirstModel());
             $obtainCreditCard->setModel($request->getModel());
             $this->gateway->execute($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()));
 }
コード例 #4
0
ファイル: CaptureAction.php プロジェクト: eamador/Payum
 /**
  * {@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 {
             $obtainCreditCard = new ObtainCreditCard($request->getToken());
             $obtainCreditCard->setModel($request->getFirstModel());
             $obtainCreditCard->setModel($request->getModel());
             $this->gateway->execute($obtainCreditCard);
             $card = $obtainCreditCard->obtain();
             if ($card->getToken()) {
                 $model['ALIAS'] = $card->getToken();
             } else {
                 $model['CARDVALIDITYDATE'] = new SensitiveValue($card->getExpireAt()->format('m-y'));
                 $model['CARDCODE'] = new SensitiveValue($card->getNumber());
                 $model['CARDFULLNAME'] = new SensitiveValue($card->getHolder());
                 $model['CARDCVV'] = 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.');
         }
     }
     //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);
 }