Skip to content

EPF old documentation: CRESS migration, notes on Amazon gateway

David Rozas edited this page Feb 12, 2015 · 1 revision

CRESS migration - Pending backend tasks

This is currently just a draft. List of tasks to be performed after the theming, and before the migration to the University of Surrey testing server

  • Payment gateway for books (check code sent by Nigel)
  • Performance settings
  • SEO enhancements: sitempaps, google webmaster tools
  • Statistics: google_analytics
  • Social Networks?

book-order-gateway.php

<?php /* allows user to choose a bookseller to order the book from

Accessed through a link on the review page that looks like this:

/admin/book-order-gateway.php?title=Not+by+Genes+Alone%3A+How+Culture+Transformed+Human+Evolution&amp;author=Richerson%2C+Peter+J.+and+Boyd%2C+Robert&amp;pb=0226712842

NG 31 March 2007

*/

`// get POSTed values`
`$title = getvar('title');`
`$author = getvar('author');`
`$pbisbn = str_replace('-', '', getvar('pb'));`
`$hbisbn = str_replace('-', '', getvar('hb'));`

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Book Order Gateway</title> <style type="text/css"> #amazon td.cell { padding: 8px 38px 8px 38px; text-align: center; } </style>

`</head>`

<body bgcolor="#FFFFFF"> <a href="../JASSS.html"><img src="../templates/cressabsoluteflush/images/red/header.png" width="100%" border="0" alt="CRESS Header"></a><p> <p> <hr> <p> <p> <p> <!--All above here is the standard JASSS header -->

<h1>Ordering a book</h1> <p>CRESS receives a small commission for each book purchased using these links.<p> <?php

`echo "<hr><p align=center><b>$author <i>$title</i>.</b></p><hr>";`

?>

<p> <center> <table border=0 id="amazon">

`<tr>`
	`<td class="cell"><img src="../images/stories/cress/BookCovers/UNKG0001.GIF" alt="UK flag" width="64" height="33">`
	`<br>Amazon UK`
	`</td>`
	`<td class="cell"><img src="../images/stories/cress/BookCovers/UNST0001.GIF" alt="US flag" width="60" height="33">`
	`<br>Amazon US`
	`</td>`
	`<td class="cell"><img src="../images/stories/cress/BookCovers/FRAN0001.GIF" alt="FR flag" width="48" height="33">`
	`<br>Amazon FR`
	`</td>`
	`<td class="cell"><img src="../images/stories/cress/BookCovers/GERM0001.GIF" alt="DE flag" width="53" height="33">`
	`<br>Amazon DE`
	`</td>`
`</tr>`

<?php // convert from ISBN to Amazon's ASIN $isbn = ($pbisbn ? $pbisbn : $hbisbn); /* ECS version 4: */ $AWSId = '1SQYG8D9Q5X4J14P3902'; $AWSSecretKey = 'nv9aApLhgQ5cQam6CLAcd+i0W+VFQ/K5ZRdk7kgM'; $AssociateTag = "jourofartis0b-21"; $params = array("Operation" => 'ItemLookup', "IdType" => 'ISBN', "SearchIndex" => 'Books', "ItemId" => "$isbn", "ResponseGroup" => 'Medium'); $xml = aws_signed_request("com", $params, $AssociateTag, $AWSId, $AWSSecretKey); // echo "<pre>"; print_r($xml); echo "</pre>";

`$asin = $xml->Items->Item->ASIN;`

`$sites = array('UK' => array('url' => "http://rcm-uk.amazon.co.uk/e/cm", 'region' => 2, 'id' => "jourofartis0b-21"),`
				`'USA' => array('url' => "http://rcm.amazon.com/e/cm", 'region' => 1, 'id' => "journofartifs-20"),`
				`'France' => array('url' => "http://rcm-fr.amazon.fr/e/cm", 'region' => 8, 'id' => "jourofartisoc-21"),`
				`'Germany' => array('url' => "http://rcm-de.amazon.de/e/cm", 'region' => 3, 'id' => "jourofartis07-21"),`

// 'Canada' => array('url' => "http://rcm-ca.amazon.ca/e/cm", 'region' => 15, 'id' => "epress00-20"), // 'Japan' => array('url' => 'http://rcm-uk.amazon.co.uk/e/cm', 'id' => "simulation-21"), // 'China' => array('url' => 'http://rcm-uk.amazon.co.uk/e/cm', 'id' => "simulation-21") );

`echo "<tr>";`
`foreach ($sites as $country => $sitedata) {`
	`$url = $sitedata['url'];`
	`$region = $sitedata['region'];`
	`$id = $sitedata['id'];`
	`echo "<td class=\"cell\">`

<iframe src=\"$url?t=$id&o=$region&p=8&l=as1&asins=$asin&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"> </iframe> </td>"; } ?> </tr> </table> </center> </body> </html>

<?php

function getvar($id) { if (isset($_GET[$id]) and $_GET[$id]) return $_GET[$id]; if (isset($_GET["amp;$id"]) and $_GET["amp;$id"]) return $_GET["amp;$id"]; return ""; }

function aws_signed_request($region, $params, $AssociateTag, $public_key, $private_key) { /* Copyright (c) 2009 Ulrich Mierendorff

`Permission is hereby granted, free of charge, to any person obtaining a`
`copy of this software and associated documentation files (the "Software"),`
`to deal in the Software without restriction, including without limitation`
`the rights to use, copy, modify, merge, publish, distribute, sublicense,`
`and/or sell copies of the Software, and to permit persons to whom the`
`Software is furnished to do so, subject to the following conditions:`

`The above copyright notice and this permission notice shall be included in`
`all copies or substantial portions of the Software.`

`THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR`
`IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,`
`FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL`
`THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER`
`LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING`
`FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER`
`DEALINGS IN THE SOFTWARE.`
`*/`

`/*`
`Parameters:`
    `$region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)`
    `$params - an array of parameters, eg. array("Operation"=>"ItemLookup",`
                    `"ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")`
    `$public_key - your "Access Key ID"`
    `$private_key - your "Secret Access Key"`
`*/`

`// some paramters`
`$method = "GET";`
`$host = "ecs.amazonaws.".$region;`
`$uri = "/onca/xml";`

`// additional parameters`
`$params["Service"] = "AWSECommerceService";`
`$params["AssociateTag"] = $AssociateTag;`
`$params["AWSAccessKeyId"] = $public_key;`
`// GMT timestamp`
`$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");`
`// API version`
`$params["Version"] = "2009-03-31";`

`// sort the parameters`
`ksort($params);`

`// create the canonicalized query`
`$canonicalized_query = array();`
`foreach ($params as $param=>$value)`
`{`
    `$param = str_replace("%7E", "~", rawurlencode($param));`
    `$value = str_replace("%7E", "~", rawurlencode($value));`
    `$canonicalized_query[] = $param."=".$value;`
`}`
`$canonicalized_query = implode("&", $canonicalized_query);`

`// create the string to sign`
`$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;`

`// calculate HMAC with SHA256 and base64-encoding`
`$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));`

`// encode the signature for the request`
`$signature = str_replace("%7E", "~", rawurlencode($signature));`

`// create request`
`$request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;`

// print_r($request);

`// do request`
`$response = @file_get_contents($request);`

`if ($response === False)`
`{`
    `return False;`
`}`
`else`
`{`
    `// parse XML`
    `$pxml = simplexml_load_string($response);`
    `if ($pxml === False)`
    `{`
        `return False; // no xml`
    `}`
    `else`
    `{`
        `return $pxml;`
    `}`
`}`

} ?>

Clone this wiki locally