Created
February 5, 2014 05:11
-
-
Save ilikenwf/8817731 to your computer and use it in GitHub Desktop.
Codeigniter Amazon MWS Payments Login With Amazon / Login and Pay With Amazon API Method Caller - Their SDK Sucks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//amazon's api is a real pain in the rear | |
private function _amazonRequest($action, $params){ | |
$base = array( | |
'Action' => $action, | |
'Timestamp' => date("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()), | |
'AWSAccessKeyId' => $this->amazon['accessKey'], | |
'SignatureVersion' => 2, | |
'SignatureMethod' => 'HmacSHA256', | |
'SellerId' => $this->amazon['sellerId'], | |
'Version' => '2013-01-01' | |
); | |
$params = array_merge($base, $params); | |
$url_parts = array(); | |
foreach(array_keys($params) as $key) | |
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key])); | |
sort($url_parts); | |
// Construct the string to sign | |
$url_string = implode("&", $url_parts); | |
$string_to_sign = "GET\nmws.amazonservices.com\n/OffAmazonPayments_Sandbox/2013-01-01\n" . $url_string; | |
// Sign the request | |
$signature = hash_hmac("sha256", $string_to_sign, $this->amazon['secretKey'], TRUE); | |
// Base64 encode the signature and make it URL safe | |
$signature = urlencode(base64_encode($signature)); | |
return simplexml_load_file($this->amazon['sandbox'].'?'.$url_string."&Signature=".$signature); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment