@@ -120,10 +120,10 @@ |
||
120 | 120 | public function getFormattedMessage() |
121 | 121 | { |
122 | 122 | $message = ""; |
123 | - $message .= "[HTTP " . $this->httpStatus->getStatus() . "] - " . $this->getHttpMessage() . "\n"; |
|
123 | + $message .= "[HTTP ".$this->httpStatus->getStatus()."] - ".$this->getHttpMessage()."\n"; |
|
124 | 124 | foreach ($this->errors as $key => $value) { |
125 | 125 | if ($value instanceof PagSeguroError) { |
126 | - $message .= "$key [" . $value->getCode() . "] - " . $value->getMessage(); |
|
126 | + $message .= "$key [".$value->getCode()."] - ".$value->getMessage(); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | return $message; |
@@ -30,110 +30,110 @@ |
||
30 | 30 | class PagSeguroServiceException extends Exception |
31 | 31 | { |
32 | 32 | |
33 | - /*** |
|
33 | + /*** |
|
34 | 34 | * @var PagSeguroHttpStatus |
35 | 35 | */ |
36 | - private $httpStatus; |
|
37 | - /*** |
|
36 | + private $httpStatus; |
|
37 | + /*** |
|
38 | 38 | * @var |
39 | 39 | */ |
40 | - private $httpMessage; |
|
41 | - /*** |
|
40 | + private $httpMessage; |
|
41 | + /*** |
|
42 | 42 | * @var array |
43 | 43 | */ |
44 | - private $errors = array(); |
|
44 | + private $errors = array(); |
|
45 | 45 | |
46 | - /*** |
|
46 | + /*** |
|
47 | 47 | * @param PagSeguroHttpStatus $httpStatus |
48 | 48 | * @param array $errors |
49 | 49 | */ |
50 | - public function __construct(PagSeguroHttpStatus $httpStatus, array $errors = null) |
|
51 | - { |
|
52 | - $this->httpStatus = $httpStatus; |
|
53 | - if ($errors) { |
|
54 | - $this->errors = $errors; |
|
55 | - } |
|
56 | - //$this->httpMessage = $this->getFormattedMessage(); |
|
57 | - parent::__construct($this->getOneLineMessage()); |
|
58 | - } |
|
50 | + public function __construct(PagSeguroHttpStatus $httpStatus, array $errors = null) |
|
51 | + { |
|
52 | + $this->httpStatus = $httpStatus; |
|
53 | + if ($errors) { |
|
54 | + $this->errors = $errors; |
|
55 | + } |
|
56 | + //$this->httpMessage = $this->getFormattedMessage(); |
|
57 | + parent::__construct($this->getOneLineMessage()); |
|
58 | + } |
|
59 | 59 | |
60 | - /*** |
|
60 | + /*** |
|
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function getErrors() |
|
64 | - { |
|
65 | - return $this->errors; |
|
66 | - } |
|
63 | + public function getErrors() |
|
64 | + { |
|
65 | + return $this->errors; |
|
66 | + } |
|
67 | 67 | |
68 | - /*** |
|
68 | + /*** |
|
69 | 69 | * @param array $errors |
70 | 70 | */ |
71 | - public function setErrors(array $errors) |
|
72 | - { |
|
73 | - $this->errors = $errors; |
|
74 | - } |
|
71 | + public function setErrors(array $errors) |
|
72 | + { |
|
73 | + $this->errors = $errors; |
|
74 | + } |
|
75 | 75 | |
76 | - /*** |
|
76 | + /*** |
|
77 | 77 | * @return PagSeguroHttpStatus |
78 | 78 | */ |
79 | - public function getHttpStatus() |
|
80 | - { |
|
81 | - return $this->httpStatus; |
|
82 | - } |
|
79 | + public function getHttpStatus() |
|
80 | + { |
|
81 | + return $this->httpStatus; |
|
82 | + } |
|
83 | 83 | |
84 | - /*** |
|
84 | + /*** |
|
85 | 85 | * @param PagSeguroHttpStatus $httpStatus |
86 | 86 | */ |
87 | - public function setHttpStatus(PagSeguroHttpStatus $httpStatus) |
|
88 | - { |
|
89 | - $this->httpStatus = $httpStatus; |
|
90 | - } |
|
87 | + public function setHttpStatus(PagSeguroHttpStatus $httpStatus) |
|
88 | + { |
|
89 | + $this->httpStatus = $httpStatus; |
|
90 | + } |
|
91 | 91 | |
92 | - /*** |
|
92 | + /*** |
|
93 | 93 | * @return string |
94 | 94 | */ |
95 | - private function getHttpMessage() |
|
96 | - { |
|
95 | + private function getHttpMessage() |
|
96 | + { |
|
97 | 97 | |
98 | - switch ($type = $this->httpStatus->getType()) { |
|
98 | + switch ($type = $this->httpStatus->getType()) { |
|
99 | 99 | |
100 | - case 'BAD_REQUEST': |
|
101 | - case 'UNAUTHORIZED': |
|
102 | - case 'FORBIDDEN': |
|
103 | - case 'NOT_FOUND': |
|
104 | - case 'INTERNAL_SERVER_ERROR': |
|
105 | - case 'BAD_GATEWAY': |
|
106 | - $message = $type; |
|
107 | - break; |
|
100 | + case 'BAD_REQUEST': |
|
101 | + case 'UNAUTHORIZED': |
|
102 | + case 'FORBIDDEN': |
|
103 | + case 'NOT_FOUND': |
|
104 | + case 'INTERNAL_SERVER_ERROR': |
|
105 | + case 'BAD_GATEWAY': |
|
106 | + $message = $type; |
|
107 | + break; |
|
108 | 108 | |
109 | - default: |
|
110 | - $message = "UNDEFINED"; |
|
111 | - break; |
|
109 | + default: |
|
110 | + $message = "UNDEFINED"; |
|
111 | + break; |
|
112 | 112 | |
113 | - } |
|
114 | - return $message; |
|
115 | - } |
|
113 | + } |
|
114 | + return $message; |
|
115 | + } |
|
116 | 116 | |
117 | - /*** |
|
117 | + /*** |
|
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function getFormattedMessage() |
|
121 | - { |
|
122 | - $message = ""; |
|
123 | - $message .= "[HTTP " . $this->httpStatus->getStatus() . "] - " . $this->getHttpMessage() . "\n"; |
|
124 | - foreach ($this->errors as $key => $value) { |
|
125 | - if ($value instanceof PagSeguroError) { |
|
126 | - $message .= "$key [" . $value->getCode() . "] - " . $value->getMessage(); |
|
127 | - } |
|
128 | - } |
|
129 | - return $message; |
|
130 | - } |
|
120 | + public function getFormattedMessage() |
|
121 | + { |
|
122 | + $message = ""; |
|
123 | + $message .= "[HTTP " . $this->httpStatus->getStatus() . "] - " . $this->getHttpMessage() . "\n"; |
|
124 | + foreach ($this->errors as $key => $value) { |
|
125 | + if ($value instanceof PagSeguroError) { |
|
126 | + $message .= "$key [" . $value->getCode() . "] - " . $value->getMessage(); |
|
127 | + } |
|
128 | + } |
|
129 | + return $message; |
|
130 | + } |
|
131 | 131 | |
132 | - /*** |
|
132 | + /*** |
|
133 | 133 | * @return mixed |
134 | 134 | */ |
135 | - public function getOneLineMessage() |
|
136 | - { |
|
137 | - return str_replace("\n", " ", $this->getFormattedMessage()); |
|
138 | - } |
|
135 | + public function getOneLineMessage() |
|
136 | + { |
|
137 | + return str_replace("\n", " ", $this->getFormattedMessage()); |
|
138 | + } |
|
139 | 139 | } |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | public static function truncateValue($string, $limit, $endchars = '...') |
109 | 109 | { |
110 | 110 | |
111 | - if (!is_array($string) && !is_object($string)) { |
|
111 | + if ( ! is_array($string) && ! is_object($string)) { |
|
112 | 112 | |
113 | 113 | $stringLength = strlen($string); |
114 | 114 | $endcharsLength = strlen($endchars); |
115 | 115 | |
116 | 116 | if ($stringLength > (int) $limit) { |
117 | 117 | $cut = (int) ($limit - $endcharsLength); |
118 | - $string = substr($string, 0, $cut) . $endchars; |
|
118 | + $string = substr($string, 0, $cut).$endchars; |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | return $string; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function isEmpty($value) |
143 | 143 | { |
144 | - return (!isset($value) || trim($value) == ""); |
|
144 | + return ( ! isset($value) || trim($value) == ""); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /*** |
@@ -27,148 +27,148 @@ |
||
27 | 27 | class PagSeguroHelper |
28 | 28 | { |
29 | 29 | |
30 | - /*** |
|
30 | + /*** |
|
31 | 31 | * @param $date |
32 | 32 | * @return bool|string |
33 | 33 | */ |
34 | - public static function formatDate($date) |
|
35 | - { |
|
36 | - $format = DateTime::ATOM; |
|
37 | - if ($date instanceof DateTime) { |
|
38 | - $d = $date->format($format); |
|
39 | - } elseif (is_numeric($date)) { |
|
40 | - $d = date($format, $date); |
|
41 | - } else { |
|
42 | - $d = (string) $date; |
|
43 | - } |
|
44 | - return $d; |
|
45 | - } |
|
46 | - |
|
47 | - /*** |
|
34 | + public static function formatDate($date) |
|
35 | + { |
|
36 | + $format = DateTime::ATOM; |
|
37 | + if ($date instanceof DateTime) { |
|
38 | + $d = $date->format($format); |
|
39 | + } elseif (is_numeric($date)) { |
|
40 | + $d = date($format, $date); |
|
41 | + } else { |
|
42 | + $d = (string) $date; |
|
43 | + } |
|
44 | + return $d; |
|
45 | + } |
|
46 | + |
|
47 | + /*** |
|
48 | 48 | * @param $value |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public static function decimalFormat($value) |
|
52 | - { |
|
53 | - if (is_float($value)) { |
|
54 | - $value = (float) $value; |
|
55 | - $value = floor($value * 100) / 100; |
|
56 | - $value = (string) number_format($value, 2, '.', ''); |
|
57 | - } |
|
58 | - return $value; |
|
59 | - } |
|
60 | - |
|
61 | - /*** |
|
51 | + public static function decimalFormat($value) |
|
52 | + { |
|
53 | + if (is_float($value)) { |
|
54 | + $value = (float) $value; |
|
55 | + $value = floor($value * 100) / 100; |
|
56 | + $value = (string) number_format($value, 2, '.', ''); |
|
57 | + } |
|
58 | + return $value; |
|
59 | + } |
|
60 | + |
|
61 | + /*** |
|
62 | 62 | * @param $date |
63 | 63 | * @param $days |
64 | 64 | * @return bool|string |
65 | 65 | */ |
66 | - public static function subDays($date, $days) |
|
67 | - { |
|
68 | - $d = self::formatDate($date); |
|
69 | - $d = date_parse($d); |
|
70 | - $d = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'] - $days, $d['year']); |
|
71 | - return self::formatDate($d); |
|
72 | - } |
|
73 | - |
|
74 | - /*** |
|
66 | + public static function subDays($date, $days) |
|
67 | + { |
|
68 | + $d = self::formatDate($date); |
|
69 | + $d = date_parse($d); |
|
70 | + $d = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'] - $days, $d['year']); |
|
71 | + return self::formatDate($d); |
|
72 | + } |
|
73 | + |
|
74 | + /*** |
|
75 | 75 | * @param $var |
76 | 76 | * @param null $dump |
77 | 77 | */ |
78 | - public static function printError($var, $dump = null) |
|
79 | - { |
|
80 | - if (is_array($var) || is_object($var)) { |
|
81 | - echo "<pre>"; |
|
82 | - if ($dump) { |
|
83 | - var_dump($var); |
|
84 | - } else { |
|
85 | - print_r($var); |
|
86 | - } |
|
87 | - echo "</pre>"; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - /*** |
|
78 | + public static function printError($var, $dump = null) |
|
79 | + { |
|
80 | + if (is_array($var) || is_object($var)) { |
|
81 | + echo "<pre>"; |
|
82 | + if ($dump) { |
|
83 | + var_dump($var); |
|
84 | + } else { |
|
85 | + print_r($var); |
|
86 | + } |
|
87 | + echo "</pre>"; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + /*** |
|
92 | 92 | * Remove left, right and inside extra spaces in string |
93 | 93 | * @param string $string |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public static function removeStringExtraSpaces($string) |
|
97 | - { |
|
98 | - return trim(preg_replace("/( +)/", " ", $string)); |
|
99 | - } |
|
96 | + public static function removeStringExtraSpaces($string) |
|
97 | + { |
|
98 | + return trim(preg_replace("/( +)/", " ", $string)); |
|
99 | + } |
|
100 | 100 | |
101 | - /*** |
|
101 | + /*** |
|
102 | 102 | * Perform truncate of string value |
103 | 103 | * @param string $string |
104 | 104 | * @param int $limit |
105 | 105 | * @param mixed $endchars |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public static function truncateValue($string, $limit, $endchars = '...') |
|
109 | - { |
|
108 | + public static function truncateValue($string, $limit, $endchars = '...') |
|
109 | + { |
|
110 | 110 | |
111 | - if (!is_array($string) && !is_object($string)) { |
|
111 | + if (!is_array($string) && !is_object($string)) { |
|
112 | 112 | |
113 | - $stringLength = strlen($string); |
|
114 | - $endcharsLength = strlen($endchars); |
|
113 | + $stringLength = strlen($string); |
|
114 | + $endcharsLength = strlen($endchars); |
|
115 | 115 | |
116 | - if ($stringLength > (int) $limit) { |
|
117 | - $cut = (int) ($limit - $endcharsLength); |
|
118 | - $string = substr($string, 0, $cut) . $endchars; |
|
119 | - } |
|
120 | - } |
|
121 | - return $string; |
|
122 | - } |
|
116 | + if ($stringLength > (int) $limit) { |
|
117 | + $cut = (int) ($limit - $endcharsLength); |
|
118 | + $string = substr($string, 0, $cut) . $endchars; |
|
119 | + } |
|
120 | + } |
|
121 | + return $string; |
|
122 | + } |
|
123 | 123 | |
124 | - /*** |
|
124 | + /*** |
|
125 | 125 | * Return formatted string to send in PagSeguro request |
126 | 126 | * @param string $string |
127 | 127 | * @param int $limit |
128 | 128 | * @param mixed $endchars |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public static function formatString($string, $limit, $endchars = '...') |
|
132 | - { |
|
133 | - $string = PagSeguroHelper::removeStringExtraSpaces($string); |
|
134 | - return PagSeguroHelper::truncateValue($string, $limit, $endchars); |
|
135 | - } |
|
131 | + public static function formatString($string, $limit, $endchars = '...') |
|
132 | + { |
|
133 | + $string = PagSeguroHelper::removeStringExtraSpaces($string); |
|
134 | + return PagSeguroHelper::truncateValue($string, $limit, $endchars); |
|
135 | + } |
|
136 | 136 | |
137 | - /*** |
|
137 | + /*** |
|
138 | 138 | * Check if var is empty |
139 | 139 | * @param string $value |
140 | 140 | * @return boolean |
141 | 141 | */ |
142 | - public static function isEmpty($value) |
|
143 | - { |
|
144 | - return (!isset($value) || trim($value) == ""); |
|
145 | - } |
|
142 | + public static function isEmpty($value) |
|
143 | + { |
|
144 | + return (!isset($value) || trim($value) == ""); |
|
145 | + } |
|
146 | 146 | |
147 | - /*** |
|
147 | + /*** |
|
148 | 148 | * Check if notification post is empty |
149 | 149 | * @param array $notification_data |
150 | 150 | * @return boolean |
151 | 151 | */ |
152 | - public static function isNotificationEmpty(array $notification_data) |
|
153 | - { |
|
154 | - $isEmpty = true; |
|
152 | + public static function isNotificationEmpty(array $notification_data) |
|
153 | + { |
|
154 | + $isEmpty = true; |
|
155 | 155 | |
156 | - if (isset($notification_data['notificationCode']) && isset($notification_data['notificationType'])) { |
|
157 | - $isEmpty = (PagSeguroHelper::isEmpty($notification_data['notificationCode']) || |
|
158 | - PagSeguroHelper::isEmpty($notification_data['notificationType']) |
|
159 | - ); |
|
160 | - } |
|
156 | + if (isset($notification_data['notificationCode']) && isset($notification_data['notificationType'])) { |
|
157 | + $isEmpty = (PagSeguroHelper::isEmpty($notification_data['notificationCode']) || |
|
158 | + PagSeguroHelper::isEmpty($notification_data['notificationType']) |
|
159 | + ); |
|
160 | + } |
|
161 | 161 | |
162 | - return $isEmpty; |
|
163 | - } |
|
162 | + return $isEmpty; |
|
163 | + } |
|
164 | 164 | |
165 | - /*** |
|
165 | + /*** |
|
166 | 166 | * Remove all non digit character from string |
167 | 167 | * @param string $value |
168 | 168 | * @return string |
169 | 169 | */ |
170 | - public static function getOnlyNumbers($value) |
|
171 | - { |
|
172 | - return preg_replace('/\D/', '', $value); |
|
173 | - } |
|
170 | + public static function getOnlyNumbers($value) |
|
171 | + { |
|
172 | + return preg_replace('/\D/', '', $value); |
|
173 | + } |
|
174 | 174 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | public static function init() |
53 | 53 | { |
54 | - if (!function_exists('spl_autoload_register')) { |
|
54 | + if ( ! function_exists('spl_autoload_register')) { |
|
55 | 55 | throw new Exception("PagSeguroLibrary: Standard PHP Library (SPL) is required."); |
56 | 56 | } |
57 | 57 | if (self::$loader == null) { |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | private function addClass($class) |
64 | 64 | { |
65 | 65 | foreach (self::$dirs as $key => $dir) { |
66 | - $file = PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . |
|
67 | - $dir . DIRECTORY_SEPARATOR . $class . '.class.php'; |
|
66 | + $file = PagSeguroLibrary::getPath().DIRECTORY_SEPARATOR. |
|
67 | + $dir.DIRECTORY_SEPARATOR.$class.'.class.php'; |
|
68 | 68 | if (file_exists($file) && is_file($file)) { |
69 | 69 | |
70 | 70 | require_once $file; |
@@ -27,48 +27,48 @@ |
||
27 | 27 | class PagSeguroAutoloader |
28 | 28 | { |
29 | 29 | |
30 | - public static $loader; |
|
30 | + public static $loader; |
|
31 | 31 | |
32 | - private static $dirs = array( |
|
33 | - 'config', |
|
34 | - 'resources', |
|
35 | - 'log', |
|
36 | - 'domain', |
|
37 | - 'exception', |
|
38 | - 'parser', |
|
39 | - 'service', |
|
40 | - 'utils', |
|
41 | - 'helper' |
|
42 | - ); |
|
32 | + private static $dirs = array( |
|
33 | + 'config', |
|
34 | + 'resources', |
|
35 | + 'log', |
|
36 | + 'domain', |
|
37 | + 'exception', |
|
38 | + 'parser', |
|
39 | + 'service', |
|
40 | + 'utils', |
|
41 | + 'helper' |
|
42 | + ); |
|
43 | 43 | |
44 | - private function __construct() |
|
45 | - { |
|
46 | - if (function_exists('__autoload')) { |
|
47 | - spl_autoload_register('__autoload'); |
|
48 | - } |
|
49 | - spl_autoload_register(array($this, 'addClass')); |
|
50 | - } |
|
44 | + private function __construct() |
|
45 | + { |
|
46 | + if (function_exists('__autoload')) { |
|
47 | + spl_autoload_register('__autoload'); |
|
48 | + } |
|
49 | + spl_autoload_register(array($this, 'addClass')); |
|
50 | + } |
|
51 | 51 | |
52 | - public static function init() |
|
53 | - { |
|
54 | - if (!function_exists('spl_autoload_register')) { |
|
55 | - throw new Exception("PagSeguroLibrary: Standard PHP Library (SPL) is required."); |
|
56 | - } |
|
57 | - if (self::$loader == null) { |
|
58 | - self::$loader = new PagSeguroAutoloader(); |
|
59 | - } |
|
60 | - return self::$loader; |
|
61 | - } |
|
52 | + public static function init() |
|
53 | + { |
|
54 | + if (!function_exists('spl_autoload_register')) { |
|
55 | + throw new Exception("PagSeguroLibrary: Standard PHP Library (SPL) is required."); |
|
56 | + } |
|
57 | + if (self::$loader == null) { |
|
58 | + self::$loader = new PagSeguroAutoloader(); |
|
59 | + } |
|
60 | + return self::$loader; |
|
61 | + } |
|
62 | 62 | |
63 | - private function addClass($class) |
|
64 | - { |
|
65 | - foreach (self::$dirs as $key => $dir) { |
|
66 | - $file = PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . |
|
67 | - $dir . DIRECTORY_SEPARATOR . $class . '.class.php'; |
|
68 | - if (file_exists($file) && is_file($file)) { |
|
63 | + private function addClass($class) |
|
64 | + { |
|
65 | + foreach (self::$dirs as $key => $dir) { |
|
66 | + $file = PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . |
|
67 | + $dir . DIRECTORY_SEPARATOR . $class . '.class.php'; |
|
68 | + if (file_exists($file) && is_file($file)) { |
|
69 | 69 | |
70 | - require_once $file; |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
70 | + require_once $file; |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | 74 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | if (self::$active) { |
52 | 52 | $logFile = PagSeguroConfig::getLogFileLocation(); |
53 | 53 | |
54 | - if (!empty($logFile)) { |
|
54 | + if ( ! empty($logFile)) { |
|
55 | 55 | self::createFile($logFile); |
56 | 56 | } else { |
57 | 57 | self::createFile(); |
@@ -66,26 +66,26 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function createFile($logFile = false) |
68 | 68 | { |
69 | - if (!self::$active) { |
|
69 | + if ( ! self::$active) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | $defaultPath = PagSeguroLibrary::getPath(); |
73 | 73 | $defaultName = 'PagSeguro.log'; |
74 | 74 | self::$fileLocation = $logFile |
75 | 75 | ? $logFile |
76 | - : $defaultPath . DIRECTORY_SEPARATOR . $defaultName; |
|
76 | + : $defaultPath.DIRECTORY_SEPARATOR.$defaultName; |
|
77 | 77 | |
78 | 78 | try { |
79 | 79 | $f = fopen(self::$fileLocation, "a"); |
80 | 80 | |
81 | - if (!$f) { |
|
81 | + if ( ! $f) { |
|
82 | 82 | throw new Exception('Unable to open the input file'); |
83 | 83 | } |
84 | 84 | |
85 | 85 | fclose($f); |
86 | 86 | return true; |
87 | 87 | } catch (Exception $e) { |
88 | - echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
88 | + echo $e->getMessage()." - Can't create log file. Permission denied. File location: ". |
|
89 | 89 | self::$fileLocation; |
90 | 90 | return false; |
91 | 91 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | private static function logMessage($message, $type = null) |
139 | 139 | { |
140 | - if (!self::$active) { |
|
140 | + if ( ! self::$active) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | |
146 | 146 | $file = fopen(self::$fileLocation, "a"); |
147 | 147 | |
148 | - if (!$file) { |
|
148 | + if ( ! $file) { |
|
149 | 149 | throw new Exception('Unable to open the input file'); |
150 | 150 | } |
151 | 151 | |
152 | - $date_message = "{" . @date("Y/m/d H:i:s", time()) . "}"; |
|
152 | + $date_message = "{".@date("Y/m/d H:i:s", time())."}"; |
|
153 | 153 | |
154 | 154 | switch ($type) { |
155 | 155 | case 'info': |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | fclose($file); |
172 | 172 | |
173 | 173 | } catch (Exception $e) { |
174 | - echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
174 | + echo $e->getMessage()." - Can't create log file. Permission denied. File location: ". |
|
175 | 175 | self::$fileLocation; |
176 | 176 | } |
177 | 177 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public static function getHtml($negativeOffset = null, $reverse = null) |
188 | 188 | { |
189 | - if (!self::$active) { |
|
189 | + if ( ! self::$active) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | if (file_exists(self::$fileLocation) && $file = file(self::$fileLocation)) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | } |
199 | 199 | $content = ""; |
200 | 200 | foreach ($file as $key => $value) { |
201 | - $html = ("<p>" . str_replace("\n", "<br>", $value) . "</p>"); |
|
201 | + $html = ("<p>".str_replace("\n", "<br>", $value)."</p>"); |
|
202 | 202 | $html = str_replace("[", "<strong>", $html); |
203 | 203 | $html = str_replace("]", "</strong>", $html); |
204 | 204 | $html = str_replace("{", "<span>", $html); |
@@ -27,185 +27,185 @@ |
||
27 | 27 | class LogPagSeguro |
28 | 28 | { |
29 | 29 | |
30 | - private static $log; |
|
31 | - private static $active; |
|
32 | - private static $fileLocation; |
|
33 | - |
|
34 | - private function __construct() |
|
35 | - { |
|
36 | - self::reLoad(); |
|
37 | - } |
|
38 | - |
|
39 | - public static function init() |
|
40 | - { |
|
41 | - if (self::$log == null) { |
|
42 | - self::$log = new LogPagSeguro(); |
|
43 | - } |
|
44 | - return self::$log; |
|
45 | - } |
|
46 | - |
|
47 | - public static function reLoad() |
|
48 | - { |
|
49 | - |
|
50 | - self::$active = PagSeguroConfig::logIsActive(); |
|
51 | - if (self::$active) { |
|
52 | - $logFile = PagSeguroConfig::getLogFileLocation(); |
|
53 | - |
|
54 | - if (!empty($logFile)) { |
|
55 | - self::createFile($logFile); |
|
56 | - } else { |
|
57 | - self::createFile(); |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /*** |
|
30 | + private static $log; |
|
31 | + private static $active; |
|
32 | + private static $fileLocation; |
|
33 | + |
|
34 | + private function __construct() |
|
35 | + { |
|
36 | + self::reLoad(); |
|
37 | + } |
|
38 | + |
|
39 | + public static function init() |
|
40 | + { |
|
41 | + if (self::$log == null) { |
|
42 | + self::$log = new LogPagSeguro(); |
|
43 | + } |
|
44 | + return self::$log; |
|
45 | + } |
|
46 | + |
|
47 | + public static function reLoad() |
|
48 | + { |
|
49 | + |
|
50 | + self::$active = PagSeguroConfig::logIsActive(); |
|
51 | + if (self::$active) { |
|
52 | + $logFile = PagSeguroConfig::getLogFileLocation(); |
|
53 | + |
|
54 | + if (!empty($logFile)) { |
|
55 | + self::createFile($logFile); |
|
56 | + } else { |
|
57 | + self::createFile(); |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /*** |
|
63 | 63 | * Creates the log file |
64 | 64 | * @throws Exception |
65 | 65 | * @return boolean |
66 | 66 | */ |
67 | - public static function createFile($logFile = false) |
|
68 | - { |
|
69 | - if (!self::$active) { |
|
70 | - return false; |
|
71 | - } |
|
72 | - $defaultPath = PagSeguroLibrary::getPath(); |
|
73 | - $defaultName = 'PagSeguro.log'; |
|
74 | - self::$fileLocation = $logFile |
|
75 | - ? $logFile |
|
76 | - : $defaultPath . DIRECTORY_SEPARATOR . $defaultName; |
|
77 | - |
|
78 | - try { |
|
79 | - $f = fopen(self::$fileLocation, "a"); |
|
80 | - |
|
81 | - if (!$f) { |
|
82 | - throw new Exception('Unable to open the input file'); |
|
83 | - } |
|
84 | - |
|
85 | - fclose($f); |
|
86 | - return true; |
|
87 | - } catch (Exception $e) { |
|
88 | - echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
89 | - self::$fileLocation; |
|
90 | - return false; |
|
91 | - } |
|
92 | - |
|
93 | - } |
|
94 | - |
|
95 | - /*** |
|
67 | + public static function createFile($logFile = false) |
|
68 | + { |
|
69 | + if (!self::$active) { |
|
70 | + return false; |
|
71 | + } |
|
72 | + $defaultPath = PagSeguroLibrary::getPath(); |
|
73 | + $defaultName = 'PagSeguro.log'; |
|
74 | + self::$fileLocation = $logFile |
|
75 | + ? $logFile |
|
76 | + : $defaultPath . DIRECTORY_SEPARATOR . $defaultName; |
|
77 | + |
|
78 | + try { |
|
79 | + $f = fopen(self::$fileLocation, "a"); |
|
80 | + |
|
81 | + if (!$f) { |
|
82 | + throw new Exception('Unable to open the input file'); |
|
83 | + } |
|
84 | + |
|
85 | + fclose($f); |
|
86 | + return true; |
|
87 | + } catch (Exception $e) { |
|
88 | + echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
89 | + self::$fileLocation; |
|
90 | + return false; |
|
91 | + } |
|
92 | + |
|
93 | + } |
|
94 | + |
|
95 | + /*** |
|
96 | 96 | * Prints a info message in the log file |
97 | 97 | * @param String $message |
98 | 98 | */ |
99 | - public static function info($message) |
|
100 | - { |
|
101 | - self::logMessage($message, 'info'); |
|
102 | - } |
|
99 | + public static function info($message) |
|
100 | + { |
|
101 | + self::logMessage($message, 'info'); |
|
102 | + } |
|
103 | 103 | |
104 | - /*** |
|
104 | + /*** |
|
105 | 105 | * Prints a warning message in the log file |
106 | 106 | * @param String $message |
107 | 107 | */ |
108 | - public static function warning($message) |
|
109 | - { |
|
110 | - self::logMessage($message, 'warning'); |
|
111 | - } |
|
108 | + public static function warning($message) |
|
109 | + { |
|
110 | + self::logMessage($message, 'warning'); |
|
111 | + } |
|
112 | 112 | |
113 | - /*** |
|
113 | + /*** |
|
114 | 114 | * Prints an error message in the log file |
115 | 115 | * @param String $message |
116 | 116 | */ |
117 | - public static function error($message) |
|
118 | - { |
|
119 | - self::logMessage($message, 'error'); |
|
120 | - } |
|
117 | + public static function error($message) |
|
118 | + { |
|
119 | + self::logMessage($message, 'error'); |
|
120 | + } |
|
121 | 121 | |
122 | - /*** |
|
122 | + /*** |
|
123 | 123 | * Prints a debug message in the log file |
124 | 124 | * @param String $message |
125 | 125 | */ |
126 | - public static function debug($message) |
|
127 | - { |
|
128 | - self::logMessage($message, 'debug'); |
|
129 | - } |
|
126 | + public static function debug($message) |
|
127 | + { |
|
128 | + self::logMessage($message, 'debug'); |
|
129 | + } |
|
130 | 130 | |
131 | - /*** |
|
131 | + /*** |
|
132 | 132 | * Logs a message |
133 | 133 | * @param String $message |
134 | 134 | * @param String $type |
135 | 135 | * @throws Exception |
136 | 136 | * @return void|boolean |
137 | 137 | */ |
138 | - private static function logMessage($message, $type = null) |
|
139 | - { |
|
140 | - if (!self::$active) { |
|
141 | - return; |
|
142 | - } |
|
143 | - |
|
144 | - try { |
|
145 | - |
|
146 | - $file = fopen(self::$fileLocation, "a"); |
|
147 | - |
|
148 | - if (!$file) { |
|
149 | - throw new Exception('Unable to open the input file'); |
|
150 | - } |
|
151 | - |
|
152 | - $date_message = "{" . @date("Y/m/d H:i:s", time()) . "}"; |
|
153 | - |
|
154 | - switch ($type) { |
|
155 | - case 'info': |
|
156 | - $type_message = "[Info]"; |
|
157 | - break; |
|
158 | - case 'warning': |
|
159 | - $type_message = "[Warning]"; |
|
160 | - break; |
|
161 | - case 'error': |
|
162 | - $type_message = "[Error]"; |
|
163 | - break; |
|
164 | - case 'debug': |
|
165 | - default: |
|
166 | - $type_message = "[Debug]"; |
|
167 | - break; |
|
168 | - } |
|
169 | - $str = "$date_message $type_message $message"; |
|
170 | - fwrite($file, "$str \r\n"); |
|
171 | - fclose($file); |
|
172 | - |
|
173 | - } catch (Exception $e) { |
|
174 | - echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
175 | - self::$fileLocation; |
|
176 | - } |
|
177 | - |
|
178 | - } |
|
179 | - |
|
180 | - /*** |
|
138 | + private static function logMessage($message, $type = null) |
|
139 | + { |
|
140 | + if (!self::$active) { |
|
141 | + return; |
|
142 | + } |
|
143 | + |
|
144 | + try { |
|
145 | + |
|
146 | + $file = fopen(self::$fileLocation, "a"); |
|
147 | + |
|
148 | + if (!$file) { |
|
149 | + throw new Exception('Unable to open the input file'); |
|
150 | + } |
|
151 | + |
|
152 | + $date_message = "{" . @date("Y/m/d H:i:s", time()) . "}"; |
|
153 | + |
|
154 | + switch ($type) { |
|
155 | + case 'info': |
|
156 | + $type_message = "[Info]"; |
|
157 | + break; |
|
158 | + case 'warning': |
|
159 | + $type_message = "[Warning]"; |
|
160 | + break; |
|
161 | + case 'error': |
|
162 | + $type_message = "[Error]"; |
|
163 | + break; |
|
164 | + case 'debug': |
|
165 | + default: |
|
166 | + $type_message = "[Debug]"; |
|
167 | + break; |
|
168 | + } |
|
169 | + $str = "$date_message $type_message $message"; |
|
170 | + fwrite($file, "$str \r\n"); |
|
171 | + fclose($file); |
|
172 | + |
|
173 | + } catch (Exception $e) { |
|
174 | + echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . |
|
175 | + self::$fileLocation; |
|
176 | + } |
|
177 | + |
|
178 | + } |
|
179 | + |
|
180 | + /*** |
|
181 | 181 | * Retrieves the log messages |
182 | 182 | * @param integer $negativeOffset |
183 | 183 | * @param boolean|string $reverse |
184 | 184 | * |
185 | 185 | * @return boolean|string |
186 | 186 | */ |
187 | - public static function getHtml($negativeOffset = null, $reverse = null) |
|
188 | - { |
|
189 | - if (!self::$active) { |
|
190 | - return false; |
|
191 | - } |
|
192 | - if (file_exists(self::$fileLocation) && $file = file(self::$fileLocation)) { |
|
193 | - if ($negativeOffset !== null) { |
|
194 | - $file = array_slice($file, (-$negativeOffset), null, true); |
|
195 | - } |
|
196 | - if ($reverse) { |
|
197 | - $file = array_reverse($file, true); |
|
198 | - } |
|
199 | - $content = ""; |
|
200 | - foreach ($file as $key => $value) { |
|
201 | - $html = ("<p>" . str_replace("\n", "<br>", $value) . "</p>"); |
|
202 | - $html = str_replace("[", "<strong>", $html); |
|
203 | - $html = str_replace("]", "</strong>", $html); |
|
204 | - $html = str_replace("{", "<span>", $html); |
|
205 | - $html = str_replace("}", "</span>", $html); |
|
206 | - $content .= $html; |
|
207 | - } |
|
208 | - } |
|
209 | - return isset($content) ? $content : false; |
|
210 | - } |
|
187 | + public static function getHtml($negativeOffset = null, $reverse = null) |
|
188 | + { |
|
189 | + if (!self::$active) { |
|
190 | + return false; |
|
191 | + } |
|
192 | + if (file_exists(self::$fileLocation) && $file = file(self::$fileLocation)) { |
|
193 | + if ($negativeOffset !== null) { |
|
194 | + $file = array_slice($file, (-$negativeOffset), null, true); |
|
195 | + } |
|
196 | + if ($reverse) { |
|
197 | + $file = array_reverse($file, true); |
|
198 | + } |
|
199 | + $content = ""; |
|
200 | + foreach ($file as $key => $value) { |
|
201 | + $html = ("<p>" . str_replace("\n", "<br>", $value) . "</p>"); |
|
202 | + $html = str_replace("[", "<strong>", $html); |
|
203 | + $html = str_replace("]", "</strong>", $html); |
|
204 | + $html = str_replace("{", "<span>", $html); |
|
205 | + $html = str_replace("}", "</span>", $html); |
|
206 | + $content .= $html; |
|
207 | + } |
|
208 | + } |
|
209 | + return isset($content) ? $content : false; |
|
210 | + } |
|
211 | 211 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $arr = self::decode($str_json); |
41 | 41 | } |
42 | 42 | |
43 | - if (!isset($arr->errors)) { |
|
43 | + if ( ! isset($arr->errors)) { |
|
44 | 44 | $brand = key($arr->installments); |
45 | 45 | |
46 | 46 | foreach ($arr->installments->$brand as $key => $installment) { |
@@ -27,55 +27,55 @@ |
||
27 | 27 | class PagSeguroInstallmentParser extends PagSeguroServiceParser |
28 | 28 | { |
29 | 29 | |
30 | - /*** |
|
30 | + /*** |
|
31 | 31 | * @param $installment HttpGet Installments |
32 | 32 | * @return mixed |
33 | 33 | */ |
34 | - public static function readInstallments($str_json) |
|
35 | - { |
|
34 | + public static function readInstallments($str_json) |
|
35 | + { |
|
36 | 36 | |
37 | - if (self::decode(preg_replace('/[^a-z_\:\{}\ \"\.\,\-0-9]/i', '', $str_json))) { |
|
38 | - $arr = self::decode(preg_replace('/[^a-z_\:\{}\ \"\.\,\-0-9]/i', '', $str_json)); |
|
39 | - } else { |
|
40 | - $arr = self::decode($str_json); |
|
41 | - } |
|
37 | + if (self::decode(preg_replace('/[^a-z_\:\{}\ \"\.\,\-0-9]/i', '', $str_json))) { |
|
38 | + $arr = self::decode(preg_replace('/[^a-z_\:\{}\ \"\.\,\-0-9]/i', '', $str_json)); |
|
39 | + } else { |
|
40 | + $arr = self::decode($str_json); |
|
41 | + } |
|
42 | 42 | |
43 | - if (!isset($arr->errors)) { |
|
44 | - $brand = key($arr->installments); |
|
43 | + if (!isset($arr->errors)) { |
|
44 | + $brand = key($arr->installments); |
|
45 | 45 | |
46 | - foreach ($arr->installments->$brand as $key => $installment) { |
|
46 | + foreach ($arr->installments->$brand as $key => $installment) { |
|
47 | 47 | |
48 | - $installment->cardBrand = $brand; |
|
48 | + $installment->cardBrand = $brand; |
|
49 | 49 | |
50 | - $installments[] = new PagSeguroInstallments($installment); |
|
51 | - } |
|
50 | + $installments[] = new PagSeguroInstallments($installment); |
|
51 | + } |
|
52 | 52 | |
53 | - return $installments; |
|
54 | - } else { |
|
55 | - return self::readError($arr->errors); |
|
56 | - } |
|
57 | - } |
|
53 | + return $installments; |
|
54 | + } else { |
|
55 | + return self::readError($arr->errors); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /*** |
|
59 | + /*** |
|
60 | 60 | * @param $error Installment error |
61 | 61 | * @return object() |
62 | 62 | */ |
63 | - private static function readError($error) |
|
64 | - { |
|
65 | - $err = new stdClass(); |
|
66 | - $err->message = key($error); |
|
67 | - $err->status = true; |
|
63 | + private static function readError($error) |
|
64 | + { |
|
65 | + $err = new stdClass(); |
|
66 | + $err->message = key($error); |
|
67 | + $err->status = true; |
|
68 | 68 | |
69 | - return $err; |
|
70 | - } |
|
69 | + return $err; |
|
70 | + } |
|
71 | 71 | |
72 | - /*** |
|
72 | + /*** |
|
73 | 73 | * @param $installments Installments |
74 | 74 | * @return object installments |
75 | 75 | */ |
76 | - private static function decode($installments) |
|
77 | - { |
|
78 | - return json_decode($installments); |
|
79 | - } |
|
76 | + private static function decode($installments) |
|
77 | + { |
|
78 | + return json_decode($installments); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -27,26 +27,26 @@ |
||
27 | 27 | class PagSeguroServiceParser |
28 | 28 | { |
29 | 29 | |
30 | - /*** |
|
30 | + /*** |
|
31 | 31 | * @param $str_xml |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - public static function readErrors($str_xml) |
|
35 | - { |
|
36 | - $parser = new PagSeguroXmlParser($str_xml); |
|
37 | - $data = $parser->getResult('errors'); |
|
38 | - $errors = array(); |
|
39 | - if (isset($data['error']) && is_array($data['error'])) { |
|
40 | - if (isset($data['error']['code']) && isset($data['error']['message'])) { |
|
41 | - array_push($errors, new PagSeguroError($data['error']['code'], $data['error']['message'])); |
|
42 | - } else { |
|
43 | - foreach ($data['error'] as $key => $value) { |
|
44 | - if (isset($value['code']) && isset($value['message'])) { |
|
45 | - array_push($errors, new PagSeguroError($value['code'], $value['message'])); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
50 | - return $errors; |
|
51 | - } |
|
34 | + public static function readErrors($str_xml) |
|
35 | + { |
|
36 | + $parser = new PagSeguroXmlParser($str_xml); |
|
37 | + $data = $parser->getResult('errors'); |
|
38 | + $errors = array(); |
|
39 | + if (isset($data['error']) && is_array($data['error'])) { |
|
40 | + if (isset($data['error']['code']) && isset($data['error']['message'])) { |
|
41 | + array_push($errors, new PagSeguroError($data['error']['code'], $data['error']['message'])); |
|
42 | + } else { |
|
43 | + foreach ($data['error'] as $key => $value) { |
|
44 | + if (isset($value['code']) && isset($value['message'])) { |
|
45 | + array_push($errors, new PagSeguroError($value['code'], $value['message'])); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | + return $errors; |
|
51 | + } |
|
52 | 52 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | private function __construct() |
32 | 32 | { |
33 | 33 | define('ALLOW_PAGSEGURO_RESOURCES', true); |
34 | - require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . |
|
34 | + require_once PagSeguroLibrary::getPath().DIRECTORY_SEPARATOR."resources".DIRECTORY_SEPARATOR. |
|
35 | 35 | "PagSeguroResources.php"; |
36 | 36 | $varName = self::VAR_NAME; |
37 | 37 | if (isset($$varName)) { |
@@ -24,132 +24,132 @@ |
||
24 | 24 | class PagSeguroResources |
25 | 25 | { |
26 | 26 | |
27 | - private static $resources; |
|
28 | - private static $data; |
|
29 | - const VAR_NAME = 'PagSeguroResources'; |
|
27 | + private static $resources; |
|
28 | + private static $data; |
|
29 | + const VAR_NAME = 'PagSeguroResources'; |
|
30 | 30 | |
31 | - private function __construct() |
|
32 | - { |
|
33 | - define('ALLOW_PAGSEGURO_RESOURCES', true); |
|
34 | - require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . |
|
35 | - "PagSeguroResources.php"; |
|
36 | - $varName = self::VAR_NAME; |
|
37 | - if (isset($$varName)) { |
|
38 | - self::$data = $$varName; |
|
39 | - unset($$varName); |
|
40 | - } else { |
|
41 | - throw new Exception("Resources is undefined."); |
|
42 | - } |
|
43 | - } |
|
31 | + private function __construct() |
|
32 | + { |
|
33 | + define('ALLOW_PAGSEGURO_RESOURCES', true); |
|
34 | + require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . |
|
35 | + "PagSeguroResources.php"; |
|
36 | + $varName = self::VAR_NAME; |
|
37 | + if (isset($$varName)) { |
|
38 | + self::$data = $$varName; |
|
39 | + unset($$varName); |
|
40 | + } else { |
|
41 | + throw new Exception("Resources is undefined."); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - public static function init() |
|
46 | - { |
|
47 | - if (self::$resources == null) { |
|
48 | - self::$resources = new PagSeguroResources(); |
|
49 | - } |
|
50 | - return self::$resources; |
|
51 | - } |
|
45 | + public static function init() |
|
46 | + { |
|
47 | + if (self::$resources == null) { |
|
48 | + self::$resources = new PagSeguroResources(); |
|
49 | + } |
|
50 | + return self::$resources; |
|
51 | + } |
|
52 | 52 | |
53 | - public static function getData($key1, $key2 = null) |
|
54 | - { |
|
55 | - if ($key2 != null) { |
|
56 | - if (isset(self::$data[$key1][$key2])) { |
|
57 | - return self::$data[$key1][$key2]; |
|
58 | - } else { |
|
59 | - throw new Exception("Resources keys {$key1}, {$key2} not found."); |
|
60 | - } |
|
61 | - } else { |
|
62 | - if (isset(self::$data[$key1])) { |
|
63 | - return self::$data[$key1]; |
|
64 | - } else { |
|
65 | - throw new Exception("Resources key {$key1} not found."); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
53 | + public static function getData($key1, $key2 = null) |
|
54 | + { |
|
55 | + if ($key2 != null) { |
|
56 | + if (isset(self::$data[$key1][$key2])) { |
|
57 | + return self::$data[$key1][$key2]; |
|
58 | + } else { |
|
59 | + throw new Exception("Resources keys {$key1}, {$key2} not found."); |
|
60 | + } |
|
61 | + } else { |
|
62 | + if (isset(self::$data[$key1])) { |
|
63 | + return self::$data[$key1]; |
|
64 | + } else { |
|
65 | + throw new Exception("Resources key {$key1} not found."); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - public static function setData($key1, $key2, $value) |
|
71 | - { |
|
72 | - if (isset(self::$data[$key1][$key2])) { |
|
73 | - self::$data[$key1][$key2] = $value; |
|
74 | - } else { |
|
75 | - throw new Exception("Resources keys {$key1}, {$key2} not found."); |
|
76 | - } |
|
77 | - } |
|
70 | + public static function setData($key1, $key2, $value) |
|
71 | + { |
|
72 | + if (isset(self::$data[$key1][$key2])) { |
|
73 | + self::$data[$key1][$key2] = $value; |
|
74 | + } else { |
|
75 | + throw new Exception("Resources keys {$key1}, {$key2} not found."); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - public static function getWebserviceUrl($environment) |
|
80 | - { |
|
81 | - if (isset(self::$data['webserviceUrl']) && |
|
82 | - isset(self::$data['webserviceUrl'][$environment]) |
|
83 | - ) { |
|
84 | - return self::$data['webserviceUrl'][$environment]; |
|
85 | - } else { |
|
86 | - throw new Exception("WebService URL not set for $environment environment."); |
|
87 | - } |
|
88 | - } |
|
79 | + public static function getWebserviceUrl($environment) |
|
80 | + { |
|
81 | + if (isset(self::$data['webserviceUrl']) && |
|
82 | + isset(self::$data['webserviceUrl'][$environment]) |
|
83 | + ) { |
|
84 | + return self::$data['webserviceUrl'][$environment]; |
|
85 | + } else { |
|
86 | + throw new Exception("WebService URL not set for $environment environment."); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - public static function getPaymentUrl($environment) |
|
91 | - { |
|
92 | - if (isset(self::$data['paymentService']) && isset(self::$data['paymentService']['baseUrl']) && |
|
93 | - isset(self::$data['paymentService']['baseUrl'][$environment]) |
|
94 | - ) { |
|
95 | - return self::$data['paymentService']['baseUrl'][$environment]; |
|
96 | - } else { |
|
97 | - throw new Exception("Payment URL not set for $environment environment."); |
|
98 | - } |
|
99 | - } |
|
90 | + public static function getPaymentUrl($environment) |
|
91 | + { |
|
92 | + if (isset(self::$data['paymentService']) && isset(self::$data['paymentService']['baseUrl']) && |
|
93 | + isset(self::$data['paymentService']['baseUrl'][$environment]) |
|
94 | + ) { |
|
95 | + return self::$data['paymentService']['baseUrl'][$environment]; |
|
96 | + } else { |
|
97 | + throw new Exception("Payment URL not set for $environment environment."); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - public static function getBaseUrl($environment) |
|
102 | - { |
|
103 | - if (isset(self::$data['baseUrl']) && |
|
104 | - isset(self::$data['baseUrl'][$environment]) |
|
105 | - ) { |
|
106 | - return self::$data['baseUrl'][$environment]; |
|
107 | - } else { |
|
108 | - throw new Exception("Base URL not set for $environment environment."); |
|
109 | - } |
|
110 | - } |
|
101 | + public static function getBaseUrl($environment) |
|
102 | + { |
|
103 | + if (isset(self::$data['baseUrl']) && |
|
104 | + isset(self::$data['baseUrl'][$environment]) |
|
105 | + ) { |
|
106 | + return self::$data['baseUrl'][$environment]; |
|
107 | + } else { |
|
108 | + throw new Exception("Base URL not set for $environment environment."); |
|
109 | + } |
|
110 | + } |
|
111 | 111 | |
112 | - public static function getStaticUrl($environment) |
|
113 | - { |
|
114 | - if (isset(self::$data['staticUrl']) && |
|
115 | - isset(self::$data['staticUrl'][$environment]) |
|
116 | - ) { |
|
117 | - return self::$data['staticUrl'][$environment]; |
|
118 | - } else { |
|
119 | - throw new Exception("Static URL not set for $environment environment."); |
|
120 | - } |
|
121 | - } |
|
112 | + public static function getStaticUrl($environment) |
|
113 | + { |
|
114 | + if (isset(self::$data['staticUrl']) && |
|
115 | + isset(self::$data['staticUrl'][$environment]) |
|
116 | + ) { |
|
117 | + return self::$data['staticUrl'][$environment]; |
|
118 | + } else { |
|
119 | + throw new Exception("Static URL not set for $environment environment."); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - public static function getInstallmentUrl() |
|
124 | - { |
|
125 | - if (isset(self::$data['installmentService']) && |
|
126 | - isset(self::$data['installmentService']['url']) |
|
127 | - ) { |
|
128 | - return self::$data['installmentService']['url']; |
|
129 | - } else { |
|
130 | - throw new Exception("Installment base URL not found"); |
|
131 | - } |
|
132 | - } |
|
123 | + public static function getInstallmentUrl() |
|
124 | + { |
|
125 | + if (isset(self::$data['installmentService']) && |
|
126 | + isset(self::$data['installmentService']['url']) |
|
127 | + ) { |
|
128 | + return self::$data['installmentService']['url']; |
|
129 | + } else { |
|
130 | + throw new Exception("Installment base URL not found"); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | - public static function getAuthorizationUrl() |
|
135 | - { |
|
136 | - if (isset(self::$data['authorizationService']) && |
|
137 | - isset(self::$data['authorizationService']['servicePath']) |
|
138 | - ) { |
|
139 | - return self::$data['authorizationService']['servicePath']; |
|
140 | - } else { |
|
141 | - throw new Exception("Authorization service path URL not found"); |
|
142 | - } |
|
143 | - } |
|
134 | + public static function getAuthorizationUrl() |
|
135 | + { |
|
136 | + if (isset(self::$data['authorizationService']) && |
|
137 | + isset(self::$data['authorizationService']['servicePath']) |
|
138 | + ) { |
|
139 | + return self::$data['authorizationService']['servicePath']; |
|
140 | + } else { |
|
141 | + throw new Exception("Authorization service path URL not found"); |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - public static function getSessionUrl() |
|
146 | - { |
|
147 | - if (isset(self::$data['sessionService']) && |
|
148 | - isset(self::$data['sessionService']['url']) |
|
149 | - ) { |
|
150 | - return self::$data['sessionService']['url']; |
|
151 | - } else { |
|
152 | - throw new Exception("Session base URL not found"); |
|
153 | - } |
|
154 | - } |
|
145 | + public static function getSessionUrl() |
|
146 | + { |
|
147 | + if (isset(self::$data['sessionService']) && |
|
148 | + isset(self::$data['sessionService']['url']) |
|
149 | + ) { |
|
150 | + return self::$data['sessionService']['url']; |
|
151 | + } else { |
|
152 | + throw new Exception("Session base URL not found"); |
|
153 | + } |
|
154 | + } |
|
155 | 155 | } |
@@ -27,104 +27,104 @@ |
||
27 | 27 | class PagSeguroDirectPaymentService |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var $connectionData |
|
32 | - */ |
|
33 | - private static $connectionData; |
|
30 | + /** |
|
31 | + * @var $connectionData |
|
32 | + */ |
|
33 | + private static $connectionData; |
|
34 | 34 | |
35 | - /*** |
|
35 | + /*** |
|
36 | 36 | * |
37 | 37 | */ |
38 | - const SERVICE_NAME = 'directPaymentService'; |
|
38 | + const SERVICE_NAME = 'directPaymentService'; |
|
39 | 39 | |
40 | - /*** |
|
40 | + /*** |
|
41 | 41 | * @param PagSeguroConnectionData $connectionData |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
45 | - { |
|
46 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
47 | - } |
|
44 | + private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
45 | + { |
|
46 | + return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
47 | + } |
|
48 | 48 | |
49 | - /*** |
|
49 | + /*** |
|
50 | 50 | * @param PagSeguroConnectionData $connectionData |
51 | 51 | * @param $code |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - private static function buildReturnUrl(PagSeguroConnectionData $connectionData, $code) |
|
55 | - { |
|
56 | - return $connectionData->getServiceUrl() . '/' .$code . '/?' . $connectionData->getCredentialsUrlQuery() ; |
|
57 | - } |
|
58 | - |
|
59 | - // createCheckoutRequest is the actual implementation of the Register method |
|
60 | - // This separation serves as test hook to validate the Uri |
|
61 | - // against the code returned by the service |
|
62 | - /*** |
|
54 | + private static function buildReturnUrl(PagSeguroConnectionData $connectionData, $code) |
|
55 | + { |
|
56 | + return $connectionData->getServiceUrl() . '/' .$code . '/?' . $connectionData->getCredentialsUrlQuery() ; |
|
57 | + } |
|
58 | + |
|
59 | + // createCheckoutRequest is the actual implementation of the Register method |
|
60 | + // This separation serves as test hook to validate the Uri |
|
61 | + // against the code returned by the service |
|
62 | + /*** |
|
63 | 63 | * @param PagSeguroCredentials $credentials |
64 | 64 | * @param PagSeguroDirectrequest $request |
65 | 65 | * @return bool|string |
66 | 66 | * @throws Exception|PagSeguroServiceException |
67 | 67 | * @throws Exception |
68 | 68 | */ |
69 | - public static function createCheckoutRequest( |
|
70 | - PagSeguroCredentials $credentials, |
|
71 | - PagSeguroDirectPaymentRequest $request |
|
72 | - ) { |
|
73 | - |
|
74 | - LogPagSeguro::info("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - begin"); |
|
75 | - |
|
76 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
77 | - |
|
78 | - try { |
|
79 | - |
|
80 | - $connection = new PagSeguroHttpConnection(); |
|
81 | - $connection->post( |
|
82 | - self::buildCheckoutRequestUrl($connectionData), |
|
83 | - PagSeguroDirectPaymentParser::getData($request), |
|
84 | - $connectionData->getServiceTimeout(), |
|
85 | - $connectionData->getCharset() |
|
86 | - ); |
|
87 | - |
|
88 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
89 | - |
|
90 | - switch ($httpStatus->getType()) { |
|
91 | - |
|
92 | - case 'OK': |
|
93 | - $paymentReturn = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
94 | - |
|
95 | - LogPagSeguro::info( |
|
96 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - end {1}" . |
|
97 | - $paymentReturn->getCode() |
|
98 | - ); |
|
99 | - break; |
|
100 | - |
|
101 | - case 'BAD_REQUEST': |
|
102 | - $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
103 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
104 | - LogPagSeguro::error( |
|
105 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
106 | - $e->getOneLineMessage() |
|
107 | - ); |
|
108 | - throw $e; |
|
109 | - break; |
|
110 | - |
|
111 | - default: |
|
112 | - $e = new PagSeguroServiceException($httpStatus); |
|
113 | - LogPagSeguro::error( |
|
114 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
115 | - $e->getOneLineMessage() |
|
116 | - ); |
|
117 | - throw $e; |
|
118 | - break; |
|
119 | - |
|
120 | - } |
|
121 | - return (isset($paymentReturn) ? $paymentReturn : false); |
|
122 | - |
|
123 | - } catch (PagSeguroServiceException $e) { |
|
124 | - throw $e; |
|
125 | - } catch (Exception $e) { |
|
126 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
127 | - throw $e; |
|
128 | - } |
|
129 | - } |
|
69 | + public static function createCheckoutRequest( |
|
70 | + PagSeguroCredentials $credentials, |
|
71 | + PagSeguroDirectPaymentRequest $request |
|
72 | + ) { |
|
73 | + |
|
74 | + LogPagSeguro::info("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - begin"); |
|
75 | + |
|
76 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
77 | + |
|
78 | + try { |
|
79 | + |
|
80 | + $connection = new PagSeguroHttpConnection(); |
|
81 | + $connection->post( |
|
82 | + self::buildCheckoutRequestUrl($connectionData), |
|
83 | + PagSeguroDirectPaymentParser::getData($request), |
|
84 | + $connectionData->getServiceTimeout(), |
|
85 | + $connectionData->getCharset() |
|
86 | + ); |
|
87 | + |
|
88 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
89 | + |
|
90 | + switch ($httpStatus->getType()) { |
|
91 | + |
|
92 | + case 'OK': |
|
93 | + $paymentReturn = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
94 | + |
|
95 | + LogPagSeguro::info( |
|
96 | + "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - end {1}" . |
|
97 | + $paymentReturn->getCode() |
|
98 | + ); |
|
99 | + break; |
|
100 | + |
|
101 | + case 'BAD_REQUEST': |
|
102 | + $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
103 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
104 | + LogPagSeguro::error( |
|
105 | + "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
106 | + $e->getOneLineMessage() |
|
107 | + ); |
|
108 | + throw $e; |
|
109 | + break; |
|
110 | + |
|
111 | + default: |
|
112 | + $e = new PagSeguroServiceException($httpStatus); |
|
113 | + LogPagSeguro::error( |
|
114 | + "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
115 | + $e->getOneLineMessage() |
|
116 | + ); |
|
117 | + throw $e; |
|
118 | + break; |
|
119 | + |
|
120 | + } |
|
121 | + return (isset($paymentReturn) ? $paymentReturn : false); |
|
122 | + |
|
123 | + } catch (PagSeguroServiceException $e) { |
|
124 | + throw $e; |
|
125 | + } catch (Exception $e) { |
|
126 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
127 | + throw $e; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
45 | 45 | { |
46 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
46 | + return $connectionData->getServiceUrl().'/?'.$connectionData->getCredentialsUrlQuery(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /*** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | private static function buildReturnUrl(PagSeguroConnectionData $connectionData, $code) |
55 | 55 | { |
56 | - return $connectionData->getServiceUrl() . '/' .$code . '/?' . $connectionData->getCredentialsUrlQuery() ; |
|
56 | + return $connectionData->getServiceUrl().'/'.$code.'/?'.$connectionData->getCredentialsUrlQuery(); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // createCheckoutRequest is the actual implementation of the Register method |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | PagSeguroDirectPaymentRequest $request |
72 | 72 | ) { |
73 | 73 | |
74 | - LogPagSeguro::info("PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - begin"); |
|
74 | + LogPagSeguro::info("PagSeguroDirectPaymentService.Register(".$request->toString().") - begin"); |
|
75 | 75 | |
76 | 76 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
77 | 77 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $paymentReturn = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
94 | 94 | |
95 | 95 | LogPagSeguro::info( |
96 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - end {1}" . |
|
96 | + "PagSeguroDirectPaymentService.Register(".$request->toString().") - end {1}". |
|
97 | 97 | $paymentReturn->getCode() |
98 | 98 | ); |
99 | 99 | break; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
103 | 103 | $e = new PagSeguroServiceException($httpStatus, $errors); |
104 | 104 | LogPagSeguro::error( |
105 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
105 | + "PagSeguroDirectPaymentService.Register(".$request->toString().") - error ". |
|
106 | 106 | $e->getOneLineMessage() |
107 | 107 | ); |
108 | 108 | throw $e; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | default: |
112 | 112 | $e = new PagSeguroServiceException($httpStatus); |
113 | 113 | LogPagSeguro::error( |
114 | - "PagSeguroDirectPaymentService.Register(" . $request->toString() . ") - error " . |
|
114 | + "PagSeguroDirectPaymentService.Register(".$request->toString().") - error ". |
|
115 | 115 | $e->getOneLineMessage() |
116 | 116 | ); |
117 | 117 | throw $e; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } catch (PagSeguroServiceException $e) { |
124 | 124 | throw $e; |
125 | 125 | } catch (Exception $e) { |
126 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
126 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
127 | 127 | throw $e; |
128 | 128 | } |
129 | 129 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | private static function buildInstallmentURL($connectionData) |
36 | 36 | { |
37 | - return $connectionData->getBaseUrl() . $connectionData->getInstallmentUrl(); |
|
37 | + return $connectionData->getBaseUrl().$connectionData->getInstallmentUrl(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /*** |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | |
57 | 57 | $connectionData = new PagSeguroConnectionData($credentials, 'installmentService'); |
58 | 58 | |
59 | - $url = self::buildInstallmentURL($connectionData) . |
|
60 | - "?sessionId=" . $session . |
|
61 | - "&amount=". $amount . |
|
62 | - "&creditCardBrand=" . $cardBrand; |
|
59 | + $url = self::buildInstallmentURL($connectionData). |
|
60 | + "?sessionId=".$session. |
|
61 | + "&amount=".$amount. |
|
62 | + "&creditCardBrand=".$cardBrand; |
|
63 | 63 | |
64 | 64 | LogPagSeguro::info( |
65 | 65 | "PagSeguroInstallmentService.getInstallments(".$amount.",".$cardBrand.") - begin" |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } else { |
91 | 91 | |
92 | 92 | LogPagSeguro::info( |
93 | - "PagSeguroInstallmentService.getInstallments() - error" . |
|
93 | + "PagSeguroInstallmentService.getInstallments() - error". |
|
94 | 94 | $installments->message |
95 | 95 | ); |
96 | 96 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse()); |
104 | 104 | $e = new PagSeguroServiceException($httpStatus, $errors); |
105 | 105 | LogPagSeguro::error( |
106 | - "PagSeguroInstallmentService.getInstallments() - error " . |
|
106 | + "PagSeguroInstallmentService.getInstallments() - error ". |
|
107 | 107 | $e->getOneLineMessage() |
108 | 108 | ); |
109 | 109 | throw $e; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | default: |
113 | 113 | $e = new PagSeguroServiceException($httpStatus); |
114 | 114 | LogPagSeguro::error( |
115 | - "PagSeguroInstallmentService.getInstallments() - error " . |
|
115 | + "PagSeguroInstallmentService.getInstallments() - error ". |
|
116 | 116 | $e->getOneLineMessage() |
117 | 117 | ); |
118 | 118 | throw $e; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | throw $e; |
126 | 126 | } |
127 | 127 | catch (Exception $e) { |
128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
128 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
129 | 129 | throw $e; |
130 | 130 | } |
131 | 131 | } |
@@ -123,8 +123,7 @@ |
||
123 | 123 | |
124 | 124 | } catch (PagSeguroServiceException $e) { |
125 | 125 | throw $e; |
126 | - } |
|
127 | - catch (Exception $e) { |
|
126 | + } catch (Exception $e) { |
|
128 | 127 | LogPagSeguro::error("Exception: " . $e->getMessage()); |
129 | 128 | throw $e; |
130 | 129 | } |
@@ -27,17 +27,17 @@ discard block |
||
27 | 27 | class PagSeguroInstallmentService |
28 | 28 | { |
29 | 29 | |
30 | - /*** |
|
30 | + /*** |
|
31 | 31 | * Build URL for get installments. |
32 | 32 | * @param PagSeguroConnectionData $connectionData |
33 | 33 | * @return string of url for connection with webservice. |
34 | 34 | */ |
35 | - private static function buildInstallmentURL($connectionData) |
|
36 | - { |
|
37 | - return $connectionData->getBaseUrl() . $connectionData->getInstallmentUrl(); |
|
38 | - } |
|
35 | + private static function buildInstallmentURL($connectionData) |
|
36 | + { |
|
37 | + return $connectionData->getBaseUrl() . $connectionData->getInstallmentUrl(); |
|
38 | + } |
|
39 | 39 | |
40 | - /*** |
|
40 | + /*** |
|
41 | 41 | * Get from webservice installments for direct payment. |
42 | 42 | * @param PagSeguroAccountCredentials $credentials |
43 | 43 | * @param mixed $session ID |
@@ -47,86 +47,86 @@ discard block |
||
47 | 47 | * @throws Exception|PagSeguroServiceException |
48 | 48 | * @throws Exception |
49 | 49 | */ |
50 | - public static function getInstallments( |
|
51 | - $credentials, |
|
52 | - $session, |
|
53 | - $amount, |
|
54 | - $cardBrand) |
|
55 | - { |
|
56 | - |
|
57 | - $connectionData = new PagSeguroConnectionData($credentials, 'installmentService'); |
|
58 | - |
|
59 | - $url = self::buildInstallmentURL($connectionData) . |
|
60 | - "?sessionId=" . $session . |
|
61 | - "&amount=". $amount . |
|
62 | - "&creditCardBrand=" . $cardBrand; |
|
63 | - |
|
64 | - LogPagSeguro::info( |
|
65 | - "PagSeguroInstallmentService.getInstallments(".$amount.",".$cardBrand.") - begin" |
|
66 | - ); |
|
67 | - |
|
68 | - try { |
|
69 | - |
|
70 | - $connection = new PagSeguroHttpConnection(); |
|
71 | - $connection->get( |
|
72 | - $url, |
|
73 | - $connectionData->getServiceTimeout(), |
|
74 | - $connectionData->getCharset() |
|
75 | - ); |
|
76 | - |
|
77 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
78 | - |
|
79 | - switch ($httpStatus->getType()) { |
|
80 | - |
|
81 | - case 'OK': |
|
82 | - $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse()); |
|
83 | - |
|
84 | - if (is_array($installments)) { |
|
85 | - |
|
86 | - LogPagSeguro::info( |
|
87 | - "PagSeguroInstallmentService.getInstallments() - end {1}" |
|
88 | - ); |
|
89 | - |
|
90 | - } else { |
|
91 | - |
|
92 | - LogPagSeguro::info( |
|
93 | - "PagSeguroInstallmentService.getInstallments() - error" . |
|
94 | - $installments->message |
|
95 | - ); |
|
96 | - |
|
97 | - throw new Exception($installments->message); |
|
98 | - } |
|
99 | - |
|
100 | - break; |
|
101 | - |
|
102 | - case 'BAD_REQUEST': |
|
103 | - $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse()); |
|
104 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
105 | - LogPagSeguro::error( |
|
106 | - "PagSeguroInstallmentService.getInstallments() - error " . |
|
107 | - $e->getOneLineMessage() |
|
108 | - ); |
|
109 | - throw $e; |
|
110 | - break; |
|
111 | - |
|
112 | - default: |
|
113 | - $e = new PagSeguroServiceException($httpStatus); |
|
114 | - LogPagSeguro::error( |
|
115 | - "PagSeguroInstallmentService.getInstallments() - error " . |
|
116 | - $e->getOneLineMessage() |
|
117 | - ); |
|
118 | - throw $e; |
|
119 | - break; |
|
120 | - |
|
121 | - } |
|
122 | - return (isset($installments) ? $installments : false); |
|
123 | - |
|
124 | - } catch (PagSeguroServiceException $e) { |
|
125 | - throw $e; |
|
126 | - } |
|
127 | - catch (Exception $e) { |
|
128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
129 | - throw $e; |
|
130 | - } |
|
131 | - } |
|
50 | + public static function getInstallments( |
|
51 | + $credentials, |
|
52 | + $session, |
|
53 | + $amount, |
|
54 | + $cardBrand) |
|
55 | + { |
|
56 | + |
|
57 | + $connectionData = new PagSeguroConnectionData($credentials, 'installmentService'); |
|
58 | + |
|
59 | + $url = self::buildInstallmentURL($connectionData) . |
|
60 | + "?sessionId=" . $session . |
|
61 | + "&amount=". $amount . |
|
62 | + "&creditCardBrand=" . $cardBrand; |
|
63 | + |
|
64 | + LogPagSeguro::info( |
|
65 | + "PagSeguroInstallmentService.getInstallments(".$amount.",".$cardBrand.") - begin" |
|
66 | + ); |
|
67 | + |
|
68 | + try { |
|
69 | + |
|
70 | + $connection = new PagSeguroHttpConnection(); |
|
71 | + $connection->get( |
|
72 | + $url, |
|
73 | + $connectionData->getServiceTimeout(), |
|
74 | + $connectionData->getCharset() |
|
75 | + ); |
|
76 | + |
|
77 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
78 | + |
|
79 | + switch ($httpStatus->getType()) { |
|
80 | + |
|
81 | + case 'OK': |
|
82 | + $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse()); |
|
83 | + |
|
84 | + if (is_array($installments)) { |
|
85 | + |
|
86 | + LogPagSeguro::info( |
|
87 | + "PagSeguroInstallmentService.getInstallments() - end {1}" |
|
88 | + ); |
|
89 | + |
|
90 | + } else { |
|
91 | + |
|
92 | + LogPagSeguro::info( |
|
93 | + "PagSeguroInstallmentService.getInstallments() - error" . |
|
94 | + $installments->message |
|
95 | + ); |
|
96 | + |
|
97 | + throw new Exception($installments->message); |
|
98 | + } |
|
99 | + |
|
100 | + break; |
|
101 | + |
|
102 | + case 'BAD_REQUEST': |
|
103 | + $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse()); |
|
104 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
105 | + LogPagSeguro::error( |
|
106 | + "PagSeguroInstallmentService.getInstallments() - error " . |
|
107 | + $e->getOneLineMessage() |
|
108 | + ); |
|
109 | + throw $e; |
|
110 | + break; |
|
111 | + |
|
112 | + default: |
|
113 | + $e = new PagSeguroServiceException($httpStatus); |
|
114 | + LogPagSeguro::error( |
|
115 | + "PagSeguroInstallmentService.getInstallments() - error " . |
|
116 | + $e->getOneLineMessage() |
|
117 | + ); |
|
118 | + throw $e; |
|
119 | + break; |
|
120 | + |
|
121 | + } |
|
122 | + return (isset($installments) ? $installments : false); |
|
123 | + |
|
124 | + } catch (PagSeguroServiceException $e) { |
|
125 | + throw $e; |
|
126 | + } |
|
127 | + catch (Exception $e) { |
|
128 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
129 | + throw $e; |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |