Пример #1
0
 function process($type, $AWSAccessKeyID, $AWSSecretAccessKey)
 {
     $uniqueId = $type . '-ISC-' . microtime(true);
     // prepare the REST request array map
     $request = array('Action' => 'InstallPaymentInstruction', 'PaymentInstruction' => "MyRole == '" . $type . "' orSay 'Roles do not match';", 'CallerReference' => $uniqueId, 'TokenType' => 'Unrestricted');
     $timestamp = gmdate("Y-m-d\\TH:i:s\\Z");
     $SERVICE_VERSION = "2007-01-08";
     $SIGNATURE_VERSION = "1";
     $array1 = array();
     $array1["Timestamp"] = $timestamp;
     $array1["Version"] = $SERVICE_VERSION;
     $array1["SignatureVersion"] = $SIGNATURE_VERSION;
     $array1["AWSAccessKeyId"] = $AWSAccessKeyID;
     $array = $request + $array1;
     $signiture = FPSSignatureHelper::generateSignature($AWSSecretAccessKey, $array);
     $sortedUrl = FPSSignatureHelper::sortedParams($array, true);
     $url = AmazonTokenCreator::$amazonfpsURL . "?" . $sortedUrl . "&Signature=" . urlencode($signiture);
     if (function_exists("curl_exec")) {
         // Use CURL if it's available
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         // Setup the proxy settings if there are any
         $response = curl_exec($ch);
         $xmlresponse = new SimpleXMLElement($response);
     }
     if (!empty($xmlresponse)) {
         //handle HTTP response. Fatal error if did not pass this step
         if ($xmlresponse->Status == 'Success') {
             echo $type . ' ID : ' . $xmlresponse->TokenId . "<br>";
         } else {
             //handle response (basic error handling
             echo "Fatal Error: <br> ";
             echo "Response: " . $xmlresponse->Errors->Error->Message . "<br>";
         }
     }
 }
 static function generateSignature($secret, $paramsArray)
 {
     $sorted_string_to_encode = FPSSignatureHelper::sortedParams($paramsArray, false);
     $signature = FPSSignatureHelper::generate_base64_hmac_sha1($secret, $sorted_string_to_encode);
     return $signature;
 }
Пример #3
0
 public function VerifyOrderPayment()
 {
     $callertoken = $_REQUEST['CallerTokenId'];
     $receipttoken = $_REQUEST['RecipientTokenId'];
     $sendertoken = $_REQUEST['tokenID'];
     $status = $_REQUEST['status'];
     $orderid = $_REQUEST['Order'];
     $key = $_REQUEST['Key'];
     $sessionId = $_REQUEST['SessionId'];
     $amount = $_REQUEST['PaymentAmount'];
     if (empty($status)) {
         return false;
     }
     if (!($status == 'SA' || $status == 'SB' || $status == 'SC')) {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), GetLang('AmazonFpsPaymentError'));
         return false;
     }
     if ($this->GetCombinedOrderId() != $orderid) {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), GetLang('AmazonFpsErrorOrderId'));
         return false;
     }
     if ($this->GetGatewayAmount() != $amount) {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), GetLang('AmazonFpsErrorGatewayAmount'));
         return false;
     }
     if (md5($this->GetValue("accessid") . $orderid . $sessionId . $amount . $callertoken . $receipttoken) != $key) {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), GetLang('AmazonFpsErrorHash'));
         return false;
     }
     $chargeFeeTo = 'Recipient';
     $date = date('Y-m-d') . "T" . date('H:i:s');
     $callerReference = 'Order-' . $orderid . microtime(true);
     $timestamp = gmdate("Y-m-d\\TH:i:s\\Z");
     $parameters = array('Action' => 'Pay', 'CallerTokenId' => $callertoken, 'SenderTokenId' => $sendertoken, 'RecipientTokenId' => $receipttoken, 'TransactionAmount.Amount' => round($amount, 2), 'TransactionAmount.CurrencyCode' => 'USD', 'TransactionDate' => $date, 'ChargeFeeTo' => $chargeFeeTo, 'CallerReference' => $callerReference, 'Timestamp' => $timestamp, 'Version' => '2007-01-08', 'SignatureVersion' => 1, 'AWSAccessKeyId' => $this->GetValue('accessid'));
     require_once 'lib/CBUI/CBUISignatureHelper.class.php';
     require_once 'lib/FPS/FPSSignatureHelper.class.php';
     require_once 'lib/Crypt/HMAC.php';
     $signature = FPSSignatureHelper::generateSignature($this->GetValue('secretkey'), $parameters);
     $sorted_url = FPSSignatureHelper::sortedParams($parameters, true);
     if ($this->GetValue('testmode') == "YES") {
         $url = 'https://fps.sandbox.amazonaws.com/';
     } else {
         $url = 'https://fps.amazonaws.com/';
     }
     if (function_exists("curl_exec")) {
         // Use CURL if it's available
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $sorted_url . "&Signature=" . urlencode($signature));
         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         // Setup the proxy settings if there are any
         if (GetConfig('HTTPProxyServer')) {
             curl_setopt($ch, CURLOPT_PROXY, GetConfig('HTTPProxyServer'));
             if (GetConfig('HTTPProxyPort')) {
                 curl_setopt($ch, CURLOPT_PROXYPORT, GetConfig('HTTPProxyPort'));
             }
         }
         if (GetConfig('HTTPSSLVerifyPeer') == 0) {
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         }
         $result = curl_exec($ch);
         if (curl_errno($ch)) {
             $this->SetError(GetLang($this->_languagePrefix . "SomethingWentWrong") . $this->GetValue('displayname') . ":" . curl_error($ch));
             return false;
         }
     }
     if (!empty($result)) {
         $xml = new SimpleXMLElement($result);
     } else {
         $this->SetError(GetLang($this->_languagePrefix . "SomethingWentWrong") . $this->GetValue('displayname'));
         return false;
     }
     $transaction = GetClass('ISC_TRANSACTION');
     $previousTransaction = $transaction->LoadByTransactionId($sendertoken, $this->GetId());
     // Already processed before, HALT and log error
     if (is_array($previousTransaction) && $previousTransaction['transactionid']) {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('payment', $this->GetName()), sprintf(GetLang('AmazonFpsAlreadyProcessed'), $sendertoken));
         return false;
     }
     $newTransaction = array('providerid' => $this->GetId(), 'transactiondate' => time(), 'transactionid' => $sendertoken, 'orderid' => array_keys($this->GetOrders()), 'message' => '', 'status' => '', 'amount' => $amount, 'extrainfo' => array());
     if ($xml->Status == 'Failure') {
         $this->SetError("Status : " . $xml->Status . ":" . $xml->Errors->Errors->ReasonText);
         $newTransaction['status'] = TRANS_STATUS_FAILED;
         $newTransaction['message'] = (string) $xml->Errors->Errors->ReasonText;
         $transactionId = $transaction->Create($newTransaction);
         return false;
     }
     if ($xml->Status == 'Success') {
         $GLOBALS['ISC_CLASS_LOG']->LogSystemSuccess(array('payment', $this->GetName()), GetLang('AmazonFpsSuccess'));
         $this->SetPaymentStatus(PAYMENT_STATUS_PAID);
         $newTransaction['status'] = TRANS_STATUS_COMPLETED;
         $newTransaction['message'] = 'Success';
         $transactionId = $transaction->Create($newTransaction);
         return true;
     }
     return false;
 }