src/AmazonPaymentBundle/lib/amazon/OffAmazonPaymentsNotifications/Impl/SnsMessageValidator.php
private function _constructSignatureFromSnsMessage(Message $snsMessage)
    {
        if (strcmp($snsMessage->getMandatoryField("Type"), "Notification") != 0) {
            throw new OffAmazonPaymentsNotifications_InvalidMessageException(
                "Error with signature verification - unable to verify " .
                $snsMessage->getMandatoryField("Type") . " message"
            );
        }
        
        // get the list of fields that we are interested in
        $fields = array(
            "Timestamp" => true,
            "Message" => true,
            "MessageId" => true,
            "Subject" => false,
            "TopicArn" => true,
            "Type" => true
        );
        
        // sort the fields into byte order based on the key name(A-Za-z)
        ksort($fields);
        
        // extract the key value pairs and sort in byte order
        $signatureFields = array();
        foreach ($fields as $fieldName => $mandatoryField) {
            if ($mandatoryField) {
                $value = $snsMessage->getMandatoryField($fieldName);
            } else {
                $value = $snsMessage->getField($fieldName);
            }
            
            if (!is_null($value)) {
                array_push($signatureFields, $fieldName);
                array_push($signatureFields, $value);
            }
        }
        
        // create the signature string - key / value in byte order
        // delimited by newline character + ending with a new line character
        return implode("\n", $signatureFields) . "\n";
    }
private function _constructSignatureFromSnsMessage(Message $snsMessage)
    {
        if (strcmp($snsMessage->getMandatoryField("Type"), "Notification") != 0) {
            throw new OffAmazonPaymentsNotifications_InvalidMessageException(
                "Error with signature verification - unable to verify " .
                $snsMessage->getMandatoryField("Type") . " message"
            );
        }
        
        // get the list of fields that we are interested in
        $fields = array(
            "Timestamp" => true,
            "Message" => true,
            "MessageId" => true,
            "Subject" => false,
            "TopicArn" => true,
            "Type" => true
        );
        
        // sort the fields into byte order based on the key name(A-Za-z)
        ksort($fields);
        
        // extract the key value pairs and sort in byte order
        $signatureFields = array();
        foreach ($fields as $fieldName => $mandatoryField) {
            if ($mandatoryField) {
                $value = $snsMessage->getMandatoryField($fieldName);
            } else {
                $value = $snsMessage->getField($fieldName);
            }
            
            if (!is_null($value)) {
                array_push($signatureFields, $fieldName);
                array_push($signatureFields, $value);
            }
        }
        
        // create the signature string - key / value in byte order
        // delimited by newline character + ending with a new line character
        return implode("\n", $signatureFields) . "\n";
    }
private function _constructSignatureFromSnsMessage ( Message $ snsMessage ) { if ( strcmp ( $ snsMessage -> getMandatoryField ( "Type" ) , "Notification" ) != 0 ) { throw new OffAmazonPaymentsNotifications_InvalidMessageException ( "Error with signature verification - unable to verify " . $ snsMessage -> getMandatoryField ( "Type" ) . " message" ) ; } // get the list of fields that we are interested in $ fields = array ( "Timestamp" => true , "Message" => true , "MessageId" => true , "Subject" => false , "TopicArn" => true , "Type" => true ) ; // sort the fields into byte order based on the key name(A-Za-z) ksort ( $ fields ) ; // extract the key value pairs and sort in byte order $ signatureFields = array ( ) ; foreach ( $ fields as $ fieldName => $ mandatoryField ) { if ( $ mandatoryField ) { $ value = $ snsMessage -> getMandatoryField ( $ fieldName ) ; } else { $ value = $ snsMessage -> getField ( $ fieldName ) ; } if ( ! is_null ( $ value ) ) { array_push ( $ signatureFields , $ fieldName ) ; array_push ( $ signatureFields , $ value ) ; } } // create the signature string - key / value in byte order // delimited by newline character + ending with a new line character return implode ( "\n" , $ signatureFields ) . "\n" ; }
Recreate the signature based on the field values for the
sns message

@param Message $snsMessage sns message

@throws OffAmazonPaymentsNotifications_InvalidMessageException if the
validation
fails

@return string signature string
Recreate the signature based on the field values for the sns message