/** * @throws PaymentException * @return PaymentResponseDTO */ public function findDetailsByTransaction(PaymentRequestDTO $paymentRequestDTO) { $giropayRequest = new GiropayTransactionStatusRequest(); $additionalFields = $paymentRequestDTO->getAdditionalFields(); if (!array_key_exists(GiropayConstants::GATEWAY_TRANSACTION_ID, $additionalFields)) { throw new InvalidArgumentException("Missing GATEWAY_TRANSACTION_ID parameter"); } $giropayRequest->setReference($additionalFields[GiropayConstants::GATEWAY_TRANSACTION_ID]); try { $giropayResponse = $this->giropayPaymentService->process($giropayRequest); /** @var GiropayTransactionStatusResponse $giropayResponse */ if (!GiropayResultType::$OK->equals($giropayResponse->getResult())) { throw new PaymentException($giropayResponse->getResult()->getType() . '(' . $giropayResponse->getResult()->getFriendlyType() . ')'); } } catch (\Exception $e) { throw new PaymentException("Could not query status for payment: " . $e->getMessage(), 0, $e); } $responseDTO = new PaymentResponseDTO(PaymentType::$THIRD_PARTY_ACCOUNT, GiropayPaymentGatewayType::$GIROPAY); $responseDTO->successful(GiropayPaymentResultType::$TRANSACTION_SUCCESSFUL->equals($giropayResponse->getPaymentResult())); /* $responseDTO ->responseMap(GiropayConstants::HOSTED_REDIRECT_URL, $giropayResponse->getRedirect()) ->responseMap(GiropayConstants::GATEWAY_TRANSACTION_ID, $giropayResponse->getReference() );*/ return $responseDTO; }
/** * @param Response $httpResponse * @return array * @throws \RuntimeException */ protected function extractDataFromResponse($httpResponse, GiropayResponse $giropayResponse) { $response = new PaymentResponseDTO(PaymentType::$BANK_ACCOUNT, GiropayPaymentGatewayType::$GIROPAY); $response->rawResponse($httpResponse->getBody(true)); try { $data = $httpResponse->json(); if (!array_key_exists("rc", $data) || !is_numeric($data["rc"])) { throw new \RuntimeException("Missing required response parameter rc"); } if (!array_key_exists($data["rc"], GiropayResultType::$TYPES)) { throw new \RuntimeException("Unknown Result Code: " . $data["rc"]); } $result = GiropayResultType::$TYPES[$data["rc"]]; $giropayResponse->setResult($result); if (GiropayResultType::$OK->equals($result) && !$this->verifyHttpResponseHash($httpResponse)) { throw new \RuntimeException("The validation hash was invalid"); } } catch (Guzzle\Common\Exception\RuntimeException $e) { throw new \RuntimeException("Json payload could not be parsed", 0, $e); } return $data; }
/** * @param PaymentRequestDTO $transactionToBeRolledBack * @throws PaymentException * @return PaymentResponseDTO */ public function rollbackAuthorizeAndCapture(PaymentRequestDTO $transactionToBeRolledBack) { $responseDto = new PaymentResponseDTO(PaymentType::$CREDIT_CARD, NullPaymentGatewayType::$NULL_GATEWAY); $responseDto->rawResponse("rollback authorize and capture - successful")->successful(true)->paymentTransactionType(PaymentTransactionType::$VOID)->amount(new Money($transactionToBeRolledBack->getTransactionTotal())); return $responseDto; }
/** * @param Request $request * @throws PaymentException * @return PaymentResponseDTO */ public function translateWebResponse(Request $request) { $responseDTO = new PaymentResponseDTO(PaymentType::$THIRD_PARTY_ACCOUNT, GiropayPaymentGatewayType::$GIROPAY); $responseDTO->rawResponse($this->webResponsePrintService->printRequest($request)); // TODO: Implement requestHostedEndpoint() method. }
/** * @param PaymentRequestDTO $paymentRequestDTO * @throws PaymentException * @return PaymentResponseDTO */ public function requestHostedEndpoint(PaymentRequestDTO $paymentRequestDTO) { $giropayRequest = new GiropayTransactionStartRequest(); /* * * $request->setInfo1Label("Ihre Kundennummer"); * $request->setInfo1Text("0815"); */ if ($paymentRequestDTO->getSepaBankAccount() == null) { throw new InvalidArgumentException(); } $giropayRequest->setMerchantTxId(1234567890); $giropayRequest->setPurpose($paymentRequestDTO->getOrderDescription()); $giropayRequest->setCurrency($paymentRequestDTO->getOrderCurrencyCode()); $giropayRequest->setAmount($paymentRequestDTO->getTransactionTotal()); $giropayRequest->setIban($paymentRequestDTO->getSepaBankAccount()->getSepaBankAccountIBAN()); $giropayRequest->setBic($paymentRequestDTO->getSepaBankAccount()->getSepaBankAccountBIC()); $giropayRequest->setUrlRedirect($this->configuration->getRedirectUrl()); $giropayRequest->setUrlNotify($this->configuration->getNotifyUrl()); try { $giropayResponse = $this->giropayPaymentService->process($giropayRequest); /** @var GiropayTransactionStartResponse $giropayResponse */ if (!GiropayResultType::$OK->equals($giropayResponse->getResult())) { throw new PaymentException($giropayResponse->getResult()->getType() . ' (' . $giropayResponse->getResult()->getFriendlyType() . ')'); } } catch (\Exception $e) { throw new PaymentException("Could not process payment: " . $e->getMessage(), 0, $e); } $responseDTO = new PaymentResponseDTO(PaymentType::$THIRD_PARTY_ACCOUNT, GiropayPaymentGatewayType::$GIROPAY); $responseDTO->responseMap(GiropayConstants::HOSTED_REDIRECT_URL, $giropayResponse->getRedirect())->responseMap(GiropayConstants::GATEWAY_TRANSACTION_ID, $giropayResponse->getReference()); return $responseDTO; }