/**
  * Denormalizes data back into an object of the given class.
  *
  * @param mixed $data data to restore
  * @param string $class the expected class to instantiate
  * @param string $format format the given data was extracted from
  * @param array $context options available to the denormalizer
  *
  * @return object
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     $request = new PaymentRequest();
     $array = new SafeArrayAccess($data);
     $request->addTimestamp($array['@timestamp'])->addType($array['@type'])->addMerchantId($array['merchantid'])->addAccount($array['account'])->addChannel($array['channel'])->addOrderId($array['orderid'])->addHash($array['sha1hash'])->addPaymentsReference($array['pasref'])->addAuthCode($array['authcode'])->addRefundHash($array['refundhash'])->addFraudFilter($array['fraudfilter'])->addMobile($array['mobile'])->addToken($array['token']);
     $autoSettle = $this->denormaliseAutoSettle($array);
     if ($autoSettle != null) {
         $request->addAutoSettle($autoSettle);
     }
     $card = $this->denormaliseCard($array);
     if ($card != null) {
         $request->addCard($card);
     }
     $recurring = $this->denormaliseRecurring($array);
     if ($recurring != null) {
         $request->addRecurring($recurring);
     }
     $tssInfo = $this->denormaliseTssInfo($array);
     if ($tssInfo != null) {
         $request->addTssInfo($tssInfo);
     }
     $mpi = $this->denormaliseMpi($array);
     if ($mpi != null) {
         $request->addMpi($mpi);
     }
     $request->setAmount($this->denormaliseAmount($array));
     $request->setComments($this->denormaliseComments($array));
     return $request;
 }
 /**
  * Tests conversion of {@link PaymentRequest} to and from XML using setters.
  */
 public function testPaymentRequestXmlSetters()
 {
     $card = new Card();
     $card->setExpiryDate(SampleXmlValidationUtils::CARD_EXPIRY_DATE);
     $card->setNumber(SampleXmlValidationUtils::CARD_NUMBER);
     $card->setType(SampleXmlValidationUtils::$CARD_TYPE->getType());
     $card->setCardHolderName(SampleXmlValidationUtils::CARD_HOLDER_NAME);
     $card->setIssueNumber(SampleXmlValidationUtils::CARD_ISSUE_NUMBER);
     $cvn = new Cvn();
     $cvn->setNumber(SampleXmlValidationUtils::CARD_CVN_NUMBER);
     $cvn->setPresenceIndicator(SampleXmlValidationUtils::$CARD_CVN_PRESENCE->getIndicator());
     $card->setCvn($cvn);
     $request = new PaymentRequest();
     $request->setAccount(SampleXmlValidationUtils::ACCOUNT);
     $request->setMerchantId(SampleXmlValidationUtils::MERCHANT_ID);
     $request->setType(PaymentType::AUTH);
     $amount = new Amount();
     $amount->setAmount(SampleXmlValidationUtils::AMOUNT);
     $amount->setCurrency(SampleXmlValidationUtils::CURRENCY);
     $request->setAmount($amount);
     $autoSettle = new AutoSettle();
     $autoSettle->setFlag(SampleXmlValidationUtils::$AUTO_SETTLE_FLAG->getFlag());
     $request->setAutoSettle($autoSettle);
     $request->setCard($card);
     $request->setTimeStamp(SampleXmlValidationUtils::TIMESTAMP);
     $request->setChannel(SampleXmlValidationUtils::CHANNEL);
     $request->setOrderId(SampleXmlValidationUtils::ORDER_ID);
     $request->setHash(SampleXmlValidationUtils::REQUEST_HASH);
     $comments = new CommentCollection();
     $comment = new Comment();
     $comment->setId(1);
     $comment->setComment(SampleXmlValidationUtils::COMMENT1);
     $comments->add($comment);
     $comment = new Comment();
     $comment->setId(2);
     $comment->setComment(SampleXmlValidationUtils::COMMENT2);
     $comments->add($comment);
     $request->setComments($comments);
     $request->setPaymentsReference(SampleXmlValidationUtils::PASREF);
     $request->setAuthCode(SampleXmlValidationUtils::AUTH_CODE);
     $request->setRefundHash(SampleXmlValidationUtils::REFUND_HASH);
     $request->setFraudFilter(SampleXmlValidationUtils::FRAUD_FILTER);
     $recurring = new Recurring();
     $recurring->setFlag(SampleXmlValidationUtils::$RECURRING_FLAG->getRecurringFlag());
     $recurring->setSequence(SampleXmlValidationUtils::$RECURRING_SEQUENCE->getSequence());
     $recurring->setType(SampleXmlValidationUtils::$RECURRING_TYPE->getType());
     $request->setRecurring($recurring);
     $tssInfo = new TssInfo();
     $tssInfo->setCustomerNumber(SampleXmlValidationUtils::CUSTOMER_NUMBER);
     $tssInfo->setProductId(SampleXmlValidationUtils::PRODUCT_ID);
     $tssInfo->setVariableReference(SampleXmlValidationUtils::VARIABLE_REFERENCE);
     $tssInfo->setCustomerIpAddress(SampleXmlValidationUtils::CUSTOMER_IP);
     $addresses = array();
     $address = new Address();
     $address->setType(SampleXmlValidationUtils::$ADDRESS_TYPE_BUSINESS->getAddressType());
     $address->setCode(SampleXmlValidationUtils::ADDRESS_CODE_BUSINESS);
     $address->setCountry(SampleXmlValidationUtils::ADDRESS_COUNTRY_BUSINESS);
     $addresses[] = $address;
     $address = new Address();
     $address->setType(SampleXmlValidationUtils::$ADDRESS_TYPE_SHIPPING->getAddressType());
     $address->setCode(SampleXmlValidationUtils::ADDRESS_CODE_SHIPPING);
     $address->setCountry(SampleXmlValidationUtils::ADDRESS_COUNTRY_SHIPPING);
     $addresses[] = $address;
     $tssInfo->setAddresses($addresses);
     $request->setTssInfo($tssInfo);
     $mpi = new Mpi();
     $mpi->setCavv(SampleXmlValidationUtils::THREE_D_SECURE_CAVV);
     $mpi->setXid(SampleXmlValidationUtils::THREE_D_SECURE_XID);
     $mpi->setEci(SampleXmlValidationUtils::THREE_D_SECURE_ECI);
     $request->setMpi($mpi);
     //convert to XML
     $xml = $request->toXml();
     //Convert from XML back to PaymentRequest
     /* @var PaymentRequest $fromXmlRequest */
     $fromXmlRequest = new PaymentRequest();
     $fromXmlRequest = $fromXmlRequest->fromXml($xml);
     SampleXmlValidationUtils::checkUnmarshalledPaymentRequest($fromXmlRequest, $this);
 }
 /**
  * Tests conversion of {@link PaymentRequest} to and from XML using setters for Paymentdata.
  */
 public function testPaymentRequestXmlPaymentDataSetters()
 {
     $cvnNumber = new CvnNumber();
     $cvnNumber->setNumber(SampleXmlValidationUtils::RECEIPT_IN_CVN);
     $paymentData = new PaymentData();
     $paymentData->setCvnNumber($cvnNumber);
     $request = new PaymentRequest();
     $request->setAccount(SampleXmlValidationUtils::RECEIPT_IN_ACCOUNT);
     $request->setMerchantId(SampleXmlValidationUtils::RECEIPT_IN_MERCHANT_ID);
     $request->setType(PaymentType::RECEIPT_IN);
     $request->setPaymentData($paymentData);
     $amount = new Amount();
     $amount->setAmount(SampleXmlValidationUtils::RECEIPT_IN_AMOUNT);
     $amount->setCurrency(SampleXmlValidationUtils::RECEIPT_IN_CURRENCY);
     $request->setAmount($amount);
     $request->setPayerRef(SampleXmlValidationUtils::RECEIPT_IN_PAYER);
     $request->setPaymentMethod(SampleXmlValidationUtils::RECEIPT_IN_PAYMENT_METHOD);
     $autoSettle = new AutoSettle();
     $autoSettle->setFlag(SampleXmlValidationUtils::$RECEIPT_IN_AUTO_SETTLE_FLAG->getFlag());
     $request->setAutoSettle($autoSettle);
     $request->setTimeStamp(SampleXmlValidationUtils::RECEIPT_IN_TIMESTAMP);
     $request->setOrderId(SampleXmlValidationUtils::RECEIPT_IN_ORDER_ID);
     $request->setHash(SampleXmlValidationUtils::RECEIPT_IN_REQUEST_HASH);
     // convert to XML
     $xml = $request->toXml();
     // Convert from XML back to PaymentRequest
     /* @var PaymentRequest $fromXmlRequest */
     $fromXmlRequest = new PaymentRequest();
     $fromXmlRequest = $fromXmlRequest->fromXml($xml);
     SampleXmlValidationUtils::checkUnmarshalledReceiptInPaymentRequest($fromXmlRequest, $this);
 }