Skip to content

Commit 09be177

Browse files
author
epriestley
committedNov 6, 2013
Update WePay API to HEAD
Summary: This is mostly to pick up the LICENSE file for packaging purposes, but also fixes a bug I reported. Auditors: btrahan
1 parent 4f0f95f commit 09be177

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed
 

‎externals/wepay/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2013, WePay, Inc. <api at wepay dot com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎externals/wepay/composer.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "wepay/php-sdk",
3+
"description": "WePay APIv2 SDK for PHP",
4+
"authors": [
5+
{
6+
"name": "WePay",
7+
"email": "api@wepay.com"
8+
}
9+
],
10+
"autoload": {
11+
"files": ["wepay.php"]
12+
}
13+
}

‎externals/wepay/iframe_demoapp/checkout.php

100644100755
File mode changed.

‎externals/wepay/iframe_demoapp/list_accounts.php

100644100755
File mode changed.

‎externals/wepay/wepay.php

100644100755
+15-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class WePay {
55
/**
66
* Version number - sent in user agent string
77
*/
8-
const VERSION = '0.1.3';
8+
const VERSION = '0.1.4';
99

1010
/**
1111
* Scope fields
@@ -183,7 +183,7 @@ public function __destruct() {
183183
self::$ch = NULL;
184184
}
185185
}
186-
186+
187187
/**
188188
* create the cURL request and execute it
189189
*/
@@ -196,14 +196,14 @@ private static function make_request($endpoint, $values, $headers = array())
196196
curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);
197197
curl_setopt(self::$ch, CURLOPT_TIMEOUT, 30); // 30-second timeout, adjust to taste
198198
curl_setopt(self::$ch, CURLOPT_POST, !empty($values)); // WePay's API is not strictly RESTful, so all requests are sent as POST unless there are no request values
199-
199+
200200
$uri = self::getDomain() . $endpoint;
201201
curl_setopt(self::$ch, CURLOPT_URL, $uri);
202-
202+
203203
if (!empty($values)) {
204204
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, json_encode($values));
205205
}
206-
206+
207207
$raw = curl_exec(self::$ch);
208208
if ($errno = curl_errno(self::$ch)) {
209209
// Set up special handling for request timeouts
@@ -213,26 +213,23 @@ private static function make_request($endpoint, $values, $headers = array())
213213
throw new Exception('cURL error while making API call to WePay: ' . curl_error(self::$ch), $errno);
214214
}
215215
$result = json_decode($raw);
216-
217-
$error_code = null;
218-
if (isset($result->error_code)) {
219-
$error_code = $result->error_code;
220-
}
221-
222216
$httpCode = curl_getinfo(self::$ch, CURLINFO_HTTP_CODE);
223217
if ($httpCode >= 400) {
218+
if (!isset($result->error_code)) {
219+
throw new WePayServerException("WePay returned an error response with no error_code, please alert api@wepay.com. Original message: $result->error_description", $httpCode, $result, 0);
220+
}
224221
if ($httpCode >= 500) {
225-
throw new WePayServerException($result->error_description, $httpCode, $result, $error_code);
222+
throw new WePayServerException($result->error_description, $httpCode, $result, $result->error_code);
226223
}
227224
switch ($result->error) {
228225
case 'invalid_request':
229-
throw new WePayRequestException($result->error_description, $httpCode, $result, $error_code);
226+
throw new WePayRequestException($result->error_description, $httpCode, $result, $result->error_code);
230227
case 'access_denied':
231228
default:
232-
throw new WePayPermissionException($result->error_description, $httpCode, $result, $error_code);
229+
throw new WePayPermissionException($result->error_description, $httpCode, $result, $result->error_code);
233230
}
234231
}
235-
232+
236233
return $result;
237234
}
238235

@@ -246,13 +243,13 @@ private static function make_request($endpoint, $values, $headers = array())
246243
*/
247244
public function request($endpoint, array $values = array()) {
248245
$headers = array();
249-
246+
250247
if ($this->token) { // if we have an access_token, add it to the Authorization header
251248
$headers[] = "Authorization: Bearer $this->token";
252249
}
253-
250+
254251
$result = self::make_request($endpoint, $values, $headers);
255-
252+
256253
return $result;
257254
}
258255
}

0 commit comments

Comments
 (0)
Failed to load comments.