/** * 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()) { if (is_null($data)) { return null; } $data = new SafeArrayAccess($data); $phoneNumbers = new PhoneNumbers(); $phoneNumbers->setHomePhoneNumber($data['home']); $phoneNumbers->setWorkPhoneNumber($data['work']); $phoneNumbers->setFaxPhoneNumber($data['fax']); $phoneNumbers->setMobilePhoneNumber($data['mobile']); return $phoneNumbers; }
/** * Tests conversion of {@link PaymentRequest} to and from XML using setters for Payer. */ public function testPaymentRequestXmlPayerSetters() { $request = new PaymentRequest(); $request->setAccount(SampleXmlValidationUtils::PAYER_NEW_ACCOUNT); $request->setMerchantId(SampleXmlValidationUtils::PAYER_NEW_MERCHANT_ID); $request->setType(PaymentType::PAYER_NEW); $payer = new Payer(); $payer->setType(SampleXmlValidationUtils::PAYER_NEW_PAYER_TYPE); $payer->setRef(SampleXmlValidationUtils::PAYER_NEW_PAYER_REF); $payer->setTitle(SampleXmlValidationUtils::PAYER_NEW_PAYER_TITLE); $payer->setFirstName(SampleXmlValidationUtils::PAYER_NEW_PAYER_FIRSTNAME); $payer->setSurname(SampleXmlValidationUtils::PAYER_NEW_PAYER_SURNAME); $payer->setCompany(SampleXmlValidationUtils::PAYER_NEW_PAYER_COMPANY); $payer->setEmail(SampleXmlValidationUtils::PAYER_NEW_PAYER_EMAIL); $address = new PayerAddress(); $address->setLine1(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_LINE_1); $address->setLine2(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_LINE_2); $address->setLine3(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_LINE_3); $address->setCity(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_CITY); $address->setCounty(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_COUNTY); $address->setPostcode(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_POSTCODE); $country = new Country(); $country->setCode(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_COUNTRY_CODE); $country->setName(SampleXmlValidationUtils::PAYER_NEW_PAYER_ADDRESS_COUNTRY_NAME); $address->setCountry($country); $payer->setAddress($address); $payer->addComment(SampleXmlValidationUtils::PAYER_NEW_PAYER_COMMENT_1); $payer->addComment(SampleXmlValidationUtils::PAYER_NEW_PAYER_COMMENT_2); $phoneNumbers = new PhoneNumbers(); $phoneNumbers->setHomePhoneNumber(SampleXmlValidationUtils::PAYER_NEW_PAYER_HOME_NUMBER); $phoneNumbers->setWorkPhoneNumber(SampleXmlValidationUtils::PAYER_NEW_PAYER_WORK_NUMBER); $phoneNumbers->setFaxPhoneNumber(SampleXmlValidationUtils::PAYER_NEW_PAYER_FAX_NUMBER); $phoneNumbers->setMobilePhoneNumber(SampleXmlValidationUtils::PAYER_NEW_PAYER_MOBILE_NUMBER); $payer->setPhoneNumbers($phoneNumbers); $request->setPayer($payer); $request->setTimeStamp(SampleXmlValidationUtils::PAYER_NEW_TIMESTAMP); $request->setOrderId(SampleXmlValidationUtils::PAYER_NEW_ORDER_ID); $request->setHash(SampleXmlValidationUtils::PAYER_NEW_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::checkUnmarshalledPayerNewPaymentRequest($fromXmlRequest, $this); }