/**
  * @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;
 }
 /**
  * @param ClientInterface $client
  * @param GiropayTransactionStartRequest $giropayRequest
  * @return RequestInterface
  */
 protected function buildTransactionStartRequest(ClientInterface $client, GiropayTransactionStartRequest $giropayRequest)
 {
     $requestArray = array();
     $requestArray['merchantId'] = $this->getMerchantId();
     $requestArray['projectId'] = $this->getProjectId();
     if ($giropayRequest->getMerchantTxId() == "") {
         throw new InvalidArgumentException("Field merchantTxId is required");
     }
     $requestArray['merchantTxId'] = $giropayRequest->getMerchantTxId();
     if ($giropayRequest->getAmount() == "") {
         throw new InvalidArgumentException("Field amount is required");
     }
     $requestArray['amount'] = $giropayRequest->getAmount();
     if ($giropayRequest->getCurrency() == "") {
         throw new InvalidArgumentException("Field currency is required");
     }
     $requestArray['currency'] = $giropayRequest->getCurrency();
     if ($giropayRequest->getPurpose() == "") {
         throw new InvalidArgumentException("Field purpose is required");
     }
     $requestArray['purpose'] = $giropayRequest->getPurpose();
     if ($giropayRequest->getBic() == "") {
         throw new InvalidArgumentException("Field bic is required");
     }
     $requestArray['bic'] = $giropayRequest->getBic();
     if ($giropayRequest->getIban() != "") {
         $requestArray['iban'] = $giropayRequest->getIban();
     }
     if ($giropayRequest->getInfo1Label() != "" || $giropayRequest->getInfo1Text() != "") {
         $requestArray['info1Label'] = $giropayRequest->getInfo1Label();
         $requestArray['info1Text'] = $giropayRequest->getInfo1Text();
     }
     if ($giropayRequest->getInfo2Label() != "" || $giropayRequest->getInfo2Text() != "") {
         $requestArray['info2Label'] = $giropayRequest->getInfo2Label();
         $requestArray['info2Text'] = $giropayRequest->getInfo2Text();
     }
     if ($giropayRequest->getInfo3Label() != "" || $giropayRequest->getInfo3Text() != "") {
         $requestArray['info3Label'] = $giropayRequest->getInfo3Label();
         $requestArray['info3Text'] = $giropayRequest->getInfo3Text();
     }
     if ($giropayRequest->getInfo4Label() != "" || $giropayRequest->getInfo4Text() != "") {
         $requestArray['info4Label'] = $giropayRequest->getInfo4Label();
         $requestArray['info4Text'] = $giropayRequest->getInfo4Text();
     }
     if ($giropayRequest->getInfo5Label() != "" || $giropayRequest->getInfo5Text() != "") {
         $requestArray['info5Label'] = $giropayRequest->getInfo5Label();
         $requestArray['info5Text'] = $giropayRequest->getInfo5Text();
     }
     $requestArray['urlRedirect'] = $giropayRequest->getUrlRedirect();
     $requestArray['urlNotify'] = $giropayRequest->getUrlNotify();
     //this works because the hash list in PHP has a sort order (we get the values out in the order we added them)
     $sortedValuesString = implode('', array_values($requestArray));
     $requestArray['hash'] = $this->getHMACMD5Hash($this->getSecret(), $sortedValuesString);
     $request = $client->createRequest("POST", "https://payment.girosolution.de/girocheckout/api/v2/transaction/start", ['body' => $requestArray]);
     return $request;
 }
 public function testTransactionStartRequest()
 {
     $request = new GiropayTransactionStartRequest();
     $request->setMerchantTxId(1234567890);
     $request->setAmount(100);
     $request->setCurrency("EUR");
     $request->setPurpose("Beispieltransaktion");
     $request->setBic("TESTDETT421");
     $request->setInfo1Label("Ihre Kundennummer");
     $request->setInfo1Text("0815");
     $request->setUrlRedirect("http://mydomain.de/examples/redirect.php");
     $request->setUrlNotify("http://mydomain.de/examples/notify_log.php");
     $httpRequest = $this->requestGenerator->buildRequest($this->client, $request);
     $this->assertEquals('POST', $httpRequest->getMethod());
     $this->assertEquals("https://payment.girosolution.de/girocheckout/api/v2/transaction/start", $httpRequest->getUrl());
     $this->assertEquals($httpRequest->getBody()->getField('hash'), "78ef7a9b6b145708a0bcc1f7d4acdfdf");
 }