1: <?php
2:
3: /**
4: * Placeholder for various utility functions. All methods are static and this class cannot be instantiated.
5: */
6: class Syspay_Merchant_Utils
7: {
8: /**
9: * Prevent instantiation
10: */
11: final private function __construct()
12: {
13: }
14:
15: /**
16: * Generate a checksum
17: * @param string $data The data to get the checksum for
18: * @param string $passphrase The passphrase
19: * @return string Checksum
20: */
21: public static function getChecksum($data, $passphrase)
22: {
23: return sha1($data . $passphrase);
24: }
25:
26: /**
27: * Validate data against a given checksum
28: * @param string $data The data to validate
29: * @param string $passphrase The passphrase
30: * @param string $checksum The checksum received along with the data
31: * @return boolean
32: */
33: public static function checkChecksum($data, $passphrase, $checksum)
34: {
35: return self::getChecksum($data, $passphrase) === $checksum;
36: }
37:
38: /**
39: * Convert a timestamp to a DateTime object
40: * @param integer $timestamp Unix timestamp
41: * @return DateTime
42: */
43: public static function tsToDateTime($timestamp)
44: {
45: $datetime = new DateTime('@' . $timestamp);
46: return $datetime;
47: }
48: }
49: