1 | <?php |
||
11 | abstract class Payment { |
||
12 | |||
13 | const ENDPOINT_START = 'https://www.'; |
||
14 | |||
15 | const WEBSCR_ENDPOINT_END = 'paypal.com/cgi-bin/webscr'; |
||
16 | |||
17 | const MERCHANT_ENDPOINT_START = 'https://api-3t.'; |
||
18 | |||
19 | const MERCHANT_ENDPOINT_END = 'paypal.com/nvp'; |
||
20 | |||
21 | const ENVIRONMENT_LIVE = ''; |
||
22 | |||
23 | const ENVIRONMENT_SANDBOX = 'sandbox.'; |
||
24 | |||
25 | public static $instances = array(); |
||
26 | |||
27 | public static $config = array( |
||
28 | 'app_id' => '', |
||
29 | 'username' => '', |
||
30 | 'password' => '', |
||
31 | 'signature' => '', |
||
32 | 'email' => '', |
||
33 | 'client_id' => '', |
||
34 | 'secret' => '', |
||
35 | 'currency' => 'USD', |
||
36 | ); |
||
37 | |||
38 | protected static $_allowed_environments = array( |
||
39 | self::ENVIRONMENT_LIVE, |
||
40 | self::ENVIRONMENT_SANDBOX |
||
41 | ); |
||
42 | |||
43 | private static $environment = self::ENVIRONMENT_SANDBOX; |
||
44 | |||
45 | 5 | public static function instance($name, array $config = array()) |
|
55 | |||
56 | 1 | public static function merchant_endpoint_url() |
|
60 | |||
61 | /** |
||
62 | * Webscr url based on command, params and environment |
||
63 | */ |
||
64 | 1 | public static function webscr_url($command = FALSE, array $params = array()) |
|
75 | |||
76 | 1 | public static function environment($environment = NULL) |
|
88 | |||
89 | 9 | public static function parse_response($response_string, $url, $request_data) |
|
90 | { |
||
91 | 9 | $response = Util::parse_str($response_string); |
|
92 | |||
93 | 9 | if ( ! isset($response['ACK']) OR strpos($response['ACK'], 'Success') === FALSE) |
|
94 | 6 | throw new Request_Exception('PayPal API request did not succeed for :url failed: :error:code.', $url, $request_data, array( |
|
95 | 6 | ':url' => $url, |
|
96 | 6 | ':error' => isset($response['L_LONGMESSAGE0']) ? $response['L_LONGMESSAGE0'] : 'Unknown error', |
|
97 | 6 | ':code' => isset($response['L_ERRORCODE0']) ? ' ('.$response['L_ERRORCODE0'].')' : '', |
|
98 | 6 | ), $response); |
|
99 | |||
100 | 3 | return $response; |
|
101 | } |
||
102 | |||
103 | protected $_config; |
||
104 | |||
105 | protected $_order = array(); |
||
106 | |||
107 | protected $_return_url = NULL; |
||
108 | |||
109 | protected $_cancel_url = NULL; |
||
110 | |||
111 | protected $_notify_url = NULL; |
||
112 | |||
113 | 2 | public function __construct(array $config = array()) |
|
117 | |||
118 | 2 | public function config($key, $value = NULL) |
|
136 | |||
137 | 1 | public function order(array $order = NULL) |
|
146 | |||
147 | 1 | public function return_url($return_url = NULL) |
|
156 | |||
157 | 1 | public function cancel_url($cancel_url = NULL) |
|
166 | |||
167 | 1 | public function notify_url($notify_url = NULL) |
|
176 | |||
177 | public function request($url, array $request_data = array(), array $headers = array()) |
||
224 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.