/**
  * Set TransactionReference and/or CardReference based on previous transaction response
  *
  * @param GenericPostResponse $response Previous transaction response
  * @param int|bool $fillMode Whether to set TransactionReference, CardReference, Amount, Currency and/or Description
  * @return $this
  */
 public function fill(GenericPostResponse $response, $fillMode = true)
 {
     if (true === $fillMode) {
         $fillMode = $this->defaultFillMode;
     }
     if ($fillMode & self::FILL_MODE_TRANSACTION_REFERENCE) {
         $transactionReference = $response->getTransactionReference();
         if ($transactionReference) {
             $this->setTransactionReference($transactionReference);
         }
     }
     if ($fillMode & self::FILL_MODE_CARD_REFERENCE) {
         $cardReference = $response->getCardReference();
         if ($cardReference) {
             $this->setCardReference($cardReference);
         }
     }
     if ($fillMode & self::FILL_MODE_AMOUNT) {
         $amount = $response->getPresentationAmount();
         if ('0.00' === $amount) {
             $amount = null;
         }
         if ($amount) {
             $this->setAmount($amount);
         }
     }
     if ($fillMode & self::FILL_MODE_CURRENCY) {
         $currency = $response->getPresentationCurrency();
         if ($currency) {
             $this->setCurrency($currency);
         }
     }
     if ($fillMode & self::FILL_MODE_DESCRIPTION) {
         $description = $response->getPresentationUsage();
         if ($description) {
             $this->setDescription($description);
         }
     }
     return $this;
 }
 public function testPurchaseSuccessResponse()
 {
     $data = ['PROCESSING_RISK_SCORE' => '0', 'P3_VALIDATION' => 'ACK', 'IDENTIFICATION_SHOPPERID' => 'Test shopper', 'CLEARING_DESCRIPTOR' => 'some clearing descriptor', 'TRANSACTION_CHANNEL' => 'some transaction channel', 'PROCESSING_REASON_CODE' => '00', 'PROCESSING_CODE' => 'CC.DB.90.00', 'FRONTEND_REQUEST_CANCELLED' => 'false', 'PROCESSING_REASON' => 'Successful Processing', 'FRONTEND_MODE' => 'DEFAULT', 'CLEARING_FXSOURCE' => 'INTERN', 'CLEARING_AMOUNT' => '1.10', 'PROCESSING_RESULT' => 'ACK', 'NAME_SALUTATION' => 'NONE', 'PRESENTATION_USAGE' => 'Test purchase', 'IDENTIFICATION_INVOICEID' => 'Some invoice ID', 'POST_VALIDATION' => 'ACK', 'CLEARING_CURRENCY' => 'EUR', 'FRONTEND_SESSION_ID' => '', 'PROCESSING_STATUS_CODE' => '90', 'PRESENTATION_CURRENCY' => 'EUR', 'PAYMENT_CODE' => 'CC.DB', 'PROCESSING_RETURN_CODE' => '000.100.110', 'CONTACT_IP' => '192.0.2.1', 'PROCESSING_STATUS' => 'NEW', 'SECURITY_HASH' => 'some security hash', 'FRONTEND_CC_LOGO' => 'link to image', 'PRESENTATION_AMOUNT' => '1.10', 'IDENTIFICATION_UNIQUEID' => 'some identification unique ID', 'IDENTIFICATION_TRANSACTIONID' => 'some identification transaction ID', 'IDENTIFICATION_SHORTID' => 'some identification short ID', 'CLEARING_FXRATE' => '1.0', 'ACCOUNT_REGISTRATION' => 'someaccountregistration', 'PROCESSING_TIMESTAMP' => '2015-06-30 15:31:45', 'PAYMENT_MEMO' => 'Test payment using token', 'ADDRESS_COUNTRY' => 'DE', 'RESPONSE_VERSION' => '1.0', 'TRANSACTION_MODE' => 'INTEGRATOR_TEST', 'TRANSACTION_RESPONSE' => 'SYNC', 'PROCESSING_RETURN' => "Request successfully processed in 'Merchant in Integrator Test Mode'", 'CLEARING_FXDATE' => '2015-06-30 15:31:45'];
     $response = new GenericPostResponse($this->getMockRequest(), $data, 200);
     $this->assertTrue($response->isSuccessful());
     $this->assertFalse($response->isRedirect());
     $this->assertFalse($response->isTransparentRedirect());
     $this->assertFalse($response->isTransactionToken());
     $this->assertFalse($response->isCancelled());
     $this->assertFalse($response->isWaiting());
     $this->assertFalse($response->haveWidget());
     $this->assertNull($response->getWidget());
     $this->assertSame('90', $response->getCode());
     $this->assertSame("Successful Processing : Request successfully processed in 'Merchant in Integrator Test Mode'", $response->getMessage());
     $this->assertSame('eyJhciI6InNvbWVhY2NvdW50cmVnaXN0cmF0aW9uIiwicGMiOiJDQy5EQiJ9', $response->getCardReference());
     $this->assertSame('some identification unique ID', $response->getTransactionReference());
     $this->assertSame('some identification unique ID', $response->getIdentificationUniqueId());
     $this->assertSame('some identification transaction ID', $response->getTransactionId());
     $this->assertSame('some identification transaction ID', $response->getIdentificationTransactionId());
     $this->assertSame('someaccountregistration', $response->getAccountRegistration());
     $this->assertSame('some identification short ID', $response->getIdentificationShortId());
     $this->assertSame('Test shopper', $response->getIdentificationShopperId());
     $this->assertSame('1.10', $response->getPresentationAmount());
     $this->assertSame('EUR', $response->getPresentationCurrency());
     $this->assertSame('Test purchase', $response->getPresentationUsage());
     $this->assertSame('Successful Processing', $response->getProcessingReason());
     $this->assertSame("Request successfully processed in 'Merchant in Integrator Test Mode'", $response->getProcessingReturn());
     $this->assertSame('ACK', $response->getProcessingResult());
     $this->assertSame('CC.DB.90.00', $response->getProcessingCode());
     $this->assertSame('00', $response->getProcessingReasonCode());
     $this->assertSame('90', $response->getProcessingStatusCode());
     $this->assertSame('90', $response->acquireProcessingStatusCode());
     $this->assertSame('000.100.110', $response->getProcessingReturnCode());
     $this->assertSame('CC.DB', $response->getPaymentCode());
     $this->assertSame('SYNC', $response->getTransactionResponse());
     $this->assertSame('ACK', $response->getPostValidationErrorCode());
 }