/**
  * Tests and invalid currency value (null)
  */
 public function testNullValueOnCurrency()
 {
     $card = new Card();
     $card->addExpiryDate(SampleXmlValidationUtils::CARD_EXPIRY_DATE)->addNumber(SampleXmlValidationUtils::CARD_NUMBER)->addCardType(new CardType(CardType::VISA))->addCardHolderName(SampleXmlValidationUtils::CARD_HOLDER_NAME)->addCvn(SampleXmlValidationUtils::CARD_CVN_NUMBER)->addCvnPresenceIndicator(SampleXmlValidationUtils::$CARD_CVN_PRESENCE)->addIssueNumber(SampleXmlValidationUtils::CARD_ISSUE_NUMBER);
     $tssInfo = new TssInfo();
     $businessAddress = new Address();
     $businessAddress->addType(SampleXmlValidationUtils::$ADDRESS_TYPE_BUSINESS)->addCode(SampleXmlValidationUtils::ADDRESS_CODE_BUSINESS)->addCountry(SampleXmlValidationUtils::ADDRESS_COUNTRY_BUSINESS);
     $shippingAddress = new Address();
     $shippingAddress->addType(SampleXmlValidationUtils::$ADDRESS_TYPE_SHIPPING)->addCode(SampleXmlValidationUtils::ADDRESS_CODE_SHIPPING)->addCountry(SampleXmlValidationUtils::ADDRESS_COUNTRY_SHIPPING);
     $tssInfo->addCustomerNumber(SampleXmlValidationUtils::CUSTOMER_NUMBER)->addProductId(SampleXmlValidationUtils::PRODUCT_ID)->addVariableReference(SampleXmlValidationUtils::VARIABLE_REFERENCE)->addCustomerIpAddress(SampleXmlValidationUtils::CUSTOMER_IP)->addAddress($businessAddress)->addAddress($shippingAddress);
     $autoSettle = new AutoSettle();
     $autoSettle = $autoSettle->addFlag(SampleXmlValidationUtils::$AUTO_SETTLE_FLAG);
     $mpi = new Mpi();
     $mpi->addCavv(SampleXmlValidationUtils::THREE_D_SECURE_CAVV)->addXid(SampleXmlValidationUtils::THREE_D_SECURE_XID)->addEci(SampleXmlValidationUtils::THREE_D_SECURE_ECI);
     $recurring = new Recurring();
     $recurring->addFlag(SampleXmlValidationUtils::$RECURRING_FLAG)->addSequence(SampleXmlValidationUtils::$RECURRING_SEQUENCE)->addType(SampleXmlValidationUtils::$RECURRING_TYPE);
     $expectedCurrency = null;
     $request = new PaymentRequest();
     $request->addAccount(SampleXmlValidationUtils::ACCOUNT)->addMerchantId(SampleXmlValidationUtils::MERCHANT_ID)->addType(PaymentType::AUTH)->addAmount(SampleXmlValidationUtils::AMOUNT)->addCurrency($expectedCurrency)->addCard($card)->addAutoSettle($autoSettle)->addTimestamp(SampleXmlValidationUtils::TIMESTAMP)->addChannel(SampleXmlValidationUtils::CHANNEL)->addOrderId(SampleXmlValidationUtils::ORDER_ID)->addHash(SampleXmlValidationUtils::REQUEST_HASH)->addComment(SampleXmlValidationUtils::COMMENT1)->addComment(SampleXmlValidationUtils::COMMENT2)->addPaymentsReference(SampleXmlValidationUtils::PASREF)->addAuthCode(SampleXmlValidationUtils::AUTH_CODE)->addRefundHash(SampleXmlValidationUtils::REFUND_HASH)->addFraudFilter(SampleXmlValidationUtils::FRAUD_FILTER)->addRecurring($recurring)->addTssInfo($tssInfo)->addMpi($mpi);
     // convert to XML
     $xml = $request->toXml();
     // Convert from XML back to PaymentRequest
     /* @var PaymentRequest $fromXmlRequest */
     $fromXmlRequest = new PaymentRequest();
     $fromXmlRequest = $fromXmlRequest->fromXml($xml);
     $this->assertEquals($expectedCurrency, $fromXmlRequest->getAmount()->getCurrency());
 }
 /**
  * Tests the hash calculation for an auth payment.
  */
 public function testAuthMobileHashGeneration()
 {
     $request = new PaymentRequest();
     $request->addType(PaymentType::AUTH_MOBILE)->addTimeStamp(SampleXmlValidationUtils::AUTH_MOBILE_TIMESTAMP)->addMerchantId(SampleXmlValidationUtils::AUTH_MOBILE_MERCHANT_ID)->addOrderId(SampleXmlValidationUtils::AUTH_MOBILE_ORDER_ID)->addToken(SampleXmlValidationUtils::AUTH_MOBILE_TOKEN);
     $request->hash(SampleXmlValidationUtils::SECRET);
     $this->assertEquals(SampleXmlValidationUtils::AUTH_MOBILE_REQUEST_HASH, $request->getHash());
 }
 private function mpi_is_empty(PaymentRequest $request)
 {
     return $request->getMpi()->getCavv() == null && $request->getMpi()->getXid() == null && $request->getMpi()->getEci() == null;
 }
 private static function getClassName($xml, MessageType $messageType)
 {
     switch ($messageType) {
         case MessageType::PAYMENT:
             if (self::IsRequest($xml)) {
                 return PaymentRequest::GetClassName();
             }
             return PaymentResponse::GetClassName();
         case MessageType::THREE_D_SECURE:
             if (self::IsRequest($xml)) {
                 return ThreeDSecureRequest::GetClassName();
             }
             return ThreeDSecureResponse::GetClassName();
     }
 }
 /**
  * Tests the hash calculation for a stored card dcc rate payment.
  */
 public function testStoredCardDccRateHashGeneration()
 {
     $request = new PaymentRequest();
     $request->addType(PaymentType::STORED_CARD_DCC_RATE)->addTimeStamp(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_TIMESTAMP)->addMerchantId(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_MERCHANT_ID)->addAmount(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_AMOUNT)->addCurrency(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_CURRENCY)->addOrderId(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_ORDER_ID)->addPayerReference(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_PAYREF);
     $request->hash(SampleXmlValidationUtils::SECRET);
     $this->assertEquals(SampleXmlValidationUtils::STORED_CARD_DCC_RATE_REQUEST_HASH, $request->getHash());
 }
 /**
  * Tests Fake reason code
  */
 public function testPaymentRequestCodeXmlFromCodeFailed()
 {
     $paymentRequest = new PaymentRequest();
     $paymentRequest->addAccount(SampleXmlValidationUtils::HOLD_ACCOUNT);
     $paymentRequest->addMerchantId(SampleXmlValidationUtils::HOLD_MERCHANT_ID);
     $paymentRequest->addTimestamp(SampleXmlValidationUtils::HOLD_TIMESTAMP);
     $paymentRequest->addOrderId(SampleXmlValidationUtils::HOLD_ORDER_ID);
     $paymentRequest->addHash(SampleXmlValidationUtils::HOLD_REQUEST_HASH);
     $paymentRequest->addType(PaymentType::HOLD);
     $paymentRequest->addReasonCode('fake reason');
     $reasons = array(ReasonCode::FRAUD, ReasonCode::FALSE_POSITIVE, ReasonCode::IN_STOCK, ReasonCode::NOT_GIVEN, ReasonCode::OTHER, ReasonCode::OUT_OF_STOCK);
     foreach ($reasons as $reason) {
         //marshal to XML
         $xml = $paymentRequest->toXml();
         //unmarshal back to response
         /* @var PaymentResponse $fromXmlResponse */
         $fromXmlResponse = new PaymentRequest();
         $fromXmlResponse = $fromXmlResponse->fromXML($xml);
         SampleXmlValidationUtils::checkUnmarshalledRequestCodeResponse($fromXmlResponse, $this, $reason, false);
     }
 }