Inheritance: extends Serializer
    function testConstructWithObject()
    {
        Config::setIdSeparator(false);
        $address = new Address(array('first_name' => 'Hans', 'last_name' => 'Müller', 'address1' => 'Domstr. 12', 'city' => 'München', 'zip_code' => '80234', 'country' => 'DE'));
        $this->assertEqual('Hans', $address->first_name);
        $this->assertEqual('DE', $address->country);
        $data = array('type' => 'MobilePayment', 'amount' => 3000, 'currency' => 'CHF', 'usage' => 'the usage', 'transaction_id' => 'test-1234', 'notification_url' => 'https://my-server.com/hypercharge/notification.php', 'billing_address' => $address);
        $r = new PaymentRequest($data);
        $r->validate();
        $this->assertIsA($r->billing_address, 'Hypercharge\\Address');
        $this->assertEqual($r->billing_address->first_name, 'Hans');
        $serializer = new XmlSerializer();
        $str = $serializer->toXml($r);
        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>
<payment>
  <type>MobilePayment</type>
  <amount>3000</amount>
  <currency>CHF</currency>
  <usage>the usage</usage>
  <transaction_id>test-1234</transaction_id>
  <notification_url>https://my-server.com/hypercharge/notification.php</notification_url>
  <billing_address>
    <first_name>Hans</first_name>
    <last_name>Müller</last_name>
    <address1>Domstr. 12</address1>
    <city>München</city>
    <zip_code>80234</zip_code>
    <country>DE</country>
  </billing_address>
</payment>
', $str);
    }
Ejemplo n.º 2
0
 /**
  * @param Hypercharge\IUrl $url
  * @param Hypercharge\IRequest $request
  * @return Hypercharge\IResponse
  * @throws Hypercharge\Error
  */
 public function call(IUrl $url, IRequest $request)
 {
     $curl = Config::getFactory()->createHttpsClient(Config::getUser(), Config::getPassword());
     $serializer = new XmlSerializer();
     $responseStr = $curl->xmlPost($url->get(), $serializer->toXml($request));
     $responseDom = new \SimpleXMLElement($responseStr);
     return $request->createResponse(XmlSerializer::dom2hash($responseDom));
 }
    function testSerialize()
    {
        $c = new SimplePaymentReturningRequest('cancel', '345');
        $serializer = new XmlSerializer();
        $str = $serializer->toXml($c);
        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>
<cancel>
  <unique_id>345</unique_id>
</cancel>
', $str);
    }
Ejemplo n.º 4
0
 function toXml($all, \DOMNode $parent)
 {
     if (!sizeof($all)) {
         return;
     }
     foreach ($all as $m) {
         XmlSerializer::addChild($parent, 'payment_method', $m);
     }
 }
 /**
  * @param array $all array of string
  * @param DOMNode $parent the xml node receiving items of $all <transaction_type>ITEM</transaction_type>
  * @return void
  */
 function toXml($all, \DOMNode $parent)
 {
     if (!sizeof($all)) {
         return;
     }
     foreach ($all as $t) {
         XmlSerializer::addChild($parent, 'transaction_type', $t);
     }
 }
    function testToXmlWithNull()
    {
        $data = null;
        $t = new PaymentMethods();
        $parent = XmlSerializer::createDocument('payment_methods');
        $t->toXml($data, $parent);
        $this->assertEqual($parent->ownerDocument->saveXml(), '<?xml version="1.0" encoding="UTF-8"?>
<payment_methods/>
');
    }
    function testToXmlWithNull()
    {
        $data = null;
        $t = new TransactionTypes();
        $parent = XmlSerializer::createDocument('transaction_types');
        $t->toXml($data, $parent);
        $this->assertEqual($parent->ownerDocument->saveXml(), '<?xml version="1.0" encoding="UTF-8"?>
<transaction_types/>
');
    }
Ejemplo n.º 8
0
    function testSerializeXmlShouldHandleNull()
    {
        $o = new SerializableImpl(array('leer' => null));
        $root = XmlSerializer::createDocument('r');
        XmlSerializer::_toXml($o, $root);
        $str = $root->ownerDocument->saveXML();
        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>
<r>
  <leer/>
</r>
', $str);
    }
    function test_toXmlRecursiveSorted()
    {
        $a = new Address($this->fixture('address.json'));
        $a->foo = new MpiParams(array('x' => '1', 'a' => '2', 'k' => '3'));
        XmlSerializer::$sort = true;
        $root = XmlSerializer::createDocument('r');
        XmlSerializer::_toXml($a, $root);
        $str = $root->ownerDocument->saveXML();
        $this->assertEqual($str, '<?xml version="1.0" encoding="UTF-8"?>
<r>
  <address1>Kurfürstendamm 123</address1>
  <city>Berlin</city>
  <country>DE</country>
  <first_name>Hans</first_name>
  <foo>
    <a>2</a>
    <k>3</k>
    <x>1</x>
  </foo>
  <last_name>Johanson</last_name>
  <zip_code>10624</zip_code>
</r>
');
    }
Ejemplo n.º 10
0
 /**
  * Creates the headers and body of HTTP upload request that will be used to
  * upload batch operations to.
  *
  * @param array $operations operations to be uploaded to the upload URL
  * @return array an associative array containing the headers and body of HTTP
  *     upload request
  */
 private function PrepareUploadRequest(array $operations)
 {
     $headers = array('Content-Type' => self::$UPLOAD_URL_HEADER_CONTENT_TYPE);
     $batchJobOpsMutate = new BatchJobOpsMutate();
     $batchJobOpsMutate->operations = $operations;
     // Get body of this HTTP upload request.
     $serializer = new XmlSerializer();
     $xml = $serializer->ConvertObjectToXml($batchJobOpsMutate, 'ns1:mutate', true);
     return array('headers' => $headers, 'body' => $xml);
 }
Ejemplo n.º 11
0
 /**
  * Creates the HTTP headers and body for incremental upload request that will
  * be used to upload batch operations to. Content-Length and Content-Range
  * are required for incremental upload.
  *
  * @param array $operations operations to be uploaded to the upload URL
  * @param bool $isLastRequest if this is last upload request
  * @return array an associative array containing the HTTP headers, body, and
  *     content length of incremental upload request
  */
 private function PrepareIncrementalUploadRequest(array $operations, $isLastRequest)
 {
     $headers = array('Content-Type' => self::$UPLOAD_URL_HEADER_CONTENT_TYPE);
     $batchJobOpsMutate = new BatchJobOpsMutate();
     $batchJobOpsMutate->operations = $operations;
     // Get body of this HTTP upload request.
     $serializer = new XmlSerializer();
     $content = $this->PostProcessContent($serializer->ConvertObjectToXml($batchJobOpsMutate, 'ns1:mutate', true), $this->totalContentBytes == 0, $isLastRequest);
     $contentLength = mb_strlen($content, '8bit');
     $headers['Content-Length'] = $contentLength;
     // On the last request, specify the total number of bytes.
     // e.g., bytes 500-999/1000
     $lowerBound = $this->totalContentBytes;
     $upperBound = $this->totalContentBytes + $contentLength - 1;
     $totalBytes = $isLastRequest ? strval($upperBound + 1) : '*';
     $contentRange = sprintf('bytes %d-%d/%s', $lowerBound, $upperBound, $totalBytes);
     $headers['Content-Range'] = $contentRange;
     return array('headers' => $headers, 'body' => $content, 'length' => $contentLength);
 }
 /**
  * @covers XmlSerializer::ConvertObjectToXml
  * @covers XmlSerializer::ConvertObjectToElement
  * @covers XmlSerializer::ConvertObjectToNodeValue
  */
 public function testConvertObjectToXmlMutateRequest()
 {
     $serializer = new XmlSerializer();
     $result = $serializer->ConvertObjectToXml(XmlTestHelper::$MUTATE_REQUEST_OBJECT, 'ns1:mutate', true);
     $this->assertEquals(XmlTestHelper::$NAMESPACED_MUTATE_REQUEST_XML, $result);
 }
 /**
  * In order hypercharge knows the notification has been received and processed successfully by your server
  * you have to respond with an ack message.
  * <pre>
  *  die($notifiction->ack())
  * </pre>
  *
  * If you do not do so, hypercharge will send the notification again later (up to 10 times at increasing intervals).
  * This also applies to accidentally polluting the output with php error-, warning- or notice-messages (invalid xml).
  *
  *
  * fyi: ack() returns an xml string e.g.
  *
  * <?xml version="1.0" encoding="UTF-8"?>
  * <notification_echo>
  *   <unique_id>26aa150ee68b1b2d6758a0e6c44fce4c</unique_id>
  * </notification_echo>
  *
  * @return string xml
  */
 function ack()
 {
     $root = XmlSerializer::createDocument('notification_echo');
     XmlSerializer::addChild($root, 'unique_id', $this->payment_unique_id);
     return $root->ownerDocument->saveXml();
 }
 function parseResponseFixture($xmlFile)
 {
     $dom = new \SimpleXMLElement($this->fixture($xmlFile));
     return XmlSerializer::dom2hash($dom);
 }
 function testGetTransaction()
 {
     XmlSerializer::$sort = false;
     // prepare post, request, response fixtures
     $postData = $this->schemaNotification('transaction_notification.json');
     $channel_token = $postData['channel_token'];
     $uid = $postData['unique_id'];
     $requestXml = $this->schemaRequest('reconcile.xml');
     $requestXml = preg_replace('/<unique_id>[^<]+<\\/unique_id>/', "<unique_id>{$uid}</unique_id>", $requestXml);
     $responseXml = $this->schemaResponse('reconcile.xml');
     $responseXml = preg_replace('/<unique_id>[^<]+<\\/unique_id>/', "<unique_id>{$uid}</unique_id>", $responseXml);
     $this->curlMock()->shouldReceive('xmlPost')->with("https://test.hypercharge.net/reconcile/{$channel_token}", $requestXml)->once()->andReturn($responseXml);
     // actually test the notification
     $tn = new TransactionNotification($postData);
     $this->assertTrue($tn->hasTransaction());
     $trx = $tn->getTransaction();
     $this->assertIsA($trx, 'Hypercharge\\Transaction');
     $this->assertTrue($trx->isApproved());
     $this->assertEqual($trx->unique_id, $uid);
 }
Ejemplo n.º 16
0
 /**
  * @private
  * @param string $action
  * @param string $channelToken
  * @param string $unique_id
  * @return Hypercharge\Transaction
  */
 static function request($action, $channelToken, $unique_id)
 {
     $url = new TransactionUrl(Config::ENV_SANDBOX, $channelToken, $action);
     $url = $url->get() . '/' . $unique_id;
     $curl = new Curl(Config::getUser(), Config::getPassword());
     $responseStr = $curl->xmlPost($url, '');
     $responseDom = new \SimpleXMLElement($responseStr);
     // dummy
     $request = new TransactionRequest(array('transaction_type' => 'sale'));
     return $request->createResponse(XmlSerializer::dom2hash($responseDom));
 }
Ejemplo n.º 17
0
 /**
  * Generates the parameters to use for the download request.
  * @param mixed $reportDefinition the report definition, as an ID or object
  * @return array the parameters
  */
 private static function GetParams($reportDefinition)
 {
     $params = array();
     if (is_numeric($reportDefinition)) {
         $params['__rd'] = $reportDefinition;
     } else {
         if (is_object($reportDefinition) || is_array($reportDefinition)) {
             $serializer = new XmlSerializer();
             $params['__rdxml'] = $serializer->ConvertObjectToXml($reportDefinition, 'reportDefinition', false);
         } else {
             throw new ReportDownloadException('Invalid report definition type: ' . $reportDefinition);
         }
     }
     return $params;
 }
Ejemplo n.º 18
0
<?php

function callback_trim($buffer)
{
    return trim($buffer);
}
ob_start("callback_trim");
include 'const.php';
include 'autoload.php';
$db = new MySQL('system/dbsettings.php');
$db->Connect();
$language = new Language();
$datatype = new DataType($_GET['datatype']);
$serializer = new XmlSerializer();
if (isset($_GET['apikey']) && $datatype->allowShare($_GET['apikey'])) {
    if ($_GET['action'] == "export") {
        $list = $datatype->getAll();
        $serializer->serialize($list, $datatype);
    }
    //At this time to unsafe
    /*else if($_GET['action'] == "import" && $_GET['url'] != ""){
            $serializer->importFromUrl($_GET['url']);
      }*/
} else {
    $serializer->raiseError("1", "Access denied.");
}
ob_flush();
 function setUp()
 {
     $this->serializer = new XmlSerializer(new XmlMapping());
     XmlSerializer::$sort = false;
 }
Ejemplo n.º 20
0
if ($clean) {
    Freezer::clean('cache', 'nodes');
    Freezer::clean('cache', 'resources');
    if ($kwargs['outfile']) {
        if (isset($kwargs['serialize']['json'])) {
            JsonSerializer::clean('cache', 'json', $kwargs['outfile']);
        }
        if (isset($kwargs['serialize']['xml'])) {
            XmlSerializer::clean('cache', 'xml', $kwargs['outfile']);
        }
    } else {
        if (isset($kwargs['serialize']['json'])) {
            JsonSerializer::clean('cache', 'json');
        }
        if (isset($kwargs['serialize']['xml'])) {
            XmlSerializer::clean('cache', 'xml');
        }
    }
}
$files = dojo_get_files($args);
$nodes = new Freezer('cache', 'nodes');
$resources = new Freezer('cache', 'resources');
print "=== PARSING FILES ===\n";
flush();
foreach ($files as $set) {
    list($namespace, $file) = $set;
    if (!$namespaces[$namespace]) {
        $namespaces[$namespace] = true;
    }
    $ctime = dojo_get_file_time($namespace, $file);
    if ($ctime == $resources->open($namespace . '%' . $file, null)) {
Ejemplo n.º 21
0
                }
            }
            if (!$has_children) {
                unset($roots[$id]);
            }
        }
    }
}
print "=== SERIALIZING OBJECTS ===\n";
// Aggregate and save
if ($outfile) {
    $json = new JsonSerializer('cache', 'json', $outfile);
    $xml = new XmlSerializer('cache', 'xml', $outfile);
} else {
    $json = new JsonSerializer('cache', 'json');
    $xml = new XmlSerializer('cache', 'xml');
}
foreach ($roots as $id => $root) {
    if (!$id) {
        // Minor bug
        continue;
    }
    $node = $nodes->open($id, null);
    $parts = explode('.', $id);
    foreach ($ids as $child_id) {
        $child_parts = explode('.', $child_id);
        if (count($child_parts) == count($parts) + 1 && strpos($child_id, "{$id}.") === 0 && !array_key_exists($child_id, $roots)) {
            $node['#children'][array_pop($child_parts)] = $nodes->open($child_id, null);
        }
    }
    print "{$id}\t\t" . memory_get_usage() . "\n";