/** * {@inheritDoc} */ public function execute($request) { /** @var $request \Payum\Core\Request\Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = new ArrayObject($request->getModel()); if (null !== $model['EXECCODE']) { return; } $cardFields = array('CARDCODE', 'CARDCVV', 'CARDVALIDITYDATE', 'CARDFULLNAME'); if (false == $model->validateNotEmpty($cardFields, false) && false == $model['ALIAS']) { try { $creditCardRequest = new ObtainCreditCard(); $this->payment->execute($creditCardRequest); $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.'); } $response = $this->api->payment($model->toUnsafeArray()); $model->replace((array) $response->getContentJson()); }
/** * {@inheritDoc} * * @param $request Notify */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $this->payment->execute($httpRequest = new GetHttpRequest()); $details = $httpRequest->query; if (!$this->api->verifyHash($details)) { throw new BadRequestHttpException('Hash cannot be verified.'); } if (empty($details['ORDERID'])) { throw new BadRequestHttpException('Order id cannot be guessed'); } $payment = $this->paymentRepository->findOneBy(array($this->identifier => $details['ORDERID'])); if (null === $payment) { throw new BadRequestHttpException('Payment cannot be retrieved.'); } if ((int) $details['AMOUNT'] !== $payment->getAmount()) { throw new BadRequestHttpException('Request amount cannot be verified against payment amount.'); } // Actually update payment details $details = array_merge($payment->getDetails(), $details); $payment->setDetails($details); $status = new GetStatus($payment); $this->payment->execute($status); $nextState = $status->getValue(); $this->updatePaymentState($payment, $nextState); $this->objectManager->flush(); throw new HttpResponse(new Response('OK', 200)); }
/** * {@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); $model = ArrayObject::ensureArrayObject($request->getModel()); $httpRequest = new GetHttpRequest(); $this->gateway->execute($httpRequest); //we are back from be2bill site so we have to just update model. if (isset($httpRequest->query['EXECCODE'])) { $model->replace($httpRequest->query); } else { throw new HttpPostRedirect($this->api->getOffsiteUrl(), $this->api->prepareOffsitePayment($model->toUnsafeArray())); } }
/** * {@inheritDoc} * * @param $request Notify */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $details = ArrayObject::ensureArrayObject($request->getModel()); $this->gateway->execute($httpRequest = new GetHttpRequest()); if (false == $this->api->verifyHash($httpRequest->query)) { throw new HttpResponse('The notification is invalid. Code 1', 400); } if ($details['AMOUNT'] != $httpRequest->query['AMOUNT']) { throw new HttpResponse('The notification is invalid. Code 2', 400); } $details->replace($httpRequest->query); throw new HttpResponse('OK', 200); }
/** * {@inheritDoc} * * @throws HttpPostRedirect if authorization required. */ public function execute($request) { /** @var $request Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $httpRequest = new GetHttpRequest(); $this->payment->execute($httpRequest); //we are back from be2bill site so we have to just update model. if (isset($httpRequest->query['EXECCODE'])) { $model->replace($httpRequest->query); } else { throw new HttpPostRedirect($this->api->getOnsiteUrl(), $this->api->prepareOnsitePayment($model->toUnsafeArray())); } }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); $httpRequest = new GetHttpRequest(); $this->gateway->execute($httpRequest); //we are back from be2bill site so we have to just update model. if (isset($httpRequest->query['EXECCODE'])) { $model->replace($httpRequest->query); } else { $extradata = $model['EXTRADATA'] ? json_decode($model['EXTRADATA'], true) : []; if (false == isset($extradata['capture_token']) && $request->getToken()) { $extradata['capture_token'] = $request->getToken()->getHash(); } if (false == isset($extradata['notify_token']) && $request->getToken() && $this->tokenFactory) { $notifyToken = $this->tokenFactory->createNotifyToken($request->getToken()->getGatewayName(), $request->getToken()->getDetails()); $extradata['notify_token'] = $notifyToken->getHash(); } $model['EXTRADATA'] = json_encode($extradata); throw new HttpPostRedirect($this->api->getOffsiteUrl(), $this->api->prepareOffsitePayment($model->toUnsafeArray())); } }
/** * @test */ public function shouldReturnTrueIfHashesMatched() { $params = array('foo' => 'fooVal', 'bar' => 'barVal'); $api = new Api(array('identifier' => 'anId', 'password' => 'aPass', 'sandbox' => true), $this->createHttpClientMock(), $this->createHttpMessageFactory()); $params['HASH'] = $api->calculateHash($params); $this->assertTrue($api->verifyHash($params)); }