mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
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
This commit is contained in:
parent
4f0f95f7b5
commit
09be177376
5 changed files with 49 additions and 18 deletions
21
externals/wepay/LICENSE
vendored
Normal file
21
externals/wepay/LICENSE
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (C) 2013, WePay, Inc. <api at wepay dot com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
13
externals/wepay/composer.json
vendored
Normal file
13
externals/wepay/composer.json
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "wepay/php-sdk",
|
||||
"description": "WePay APIv2 SDK for PHP",
|
||||
"authors": [
|
||||
{
|
||||
"name": "WePay",
|
||||
"email": "api@wepay.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"files": ["wepay.php"]
|
||||
}
|
||||
}
|
0
externals/wepay/iframe_demoapp/checkout.php
vendored
Normal file → Executable file
0
externals/wepay/iframe_demoapp/checkout.php
vendored
Normal file → Executable file
0
externals/wepay/iframe_demoapp/list_accounts.php
vendored
Normal file → Executable file
0
externals/wepay/iframe_demoapp/list_accounts.php
vendored
Normal file → Executable file
33
externals/wepay/wepay.php
vendored
Normal file → Executable file
33
externals/wepay/wepay.php
vendored
Normal file → Executable file
|
@ -5,7 +5,7 @@ class WePay {
|
|||
/**
|
||||
* Version number - sent in user agent string
|
||||
*/
|
||||
const VERSION = '0.1.3';
|
||||
const VERSION = '0.1.4';
|
||||
|
||||
/**
|
||||
* Scope fields
|
||||
|
@ -183,7 +183,7 @@ class WePay {
|
|||
self::$ch = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create the cURL request and execute it
|
||||
*/
|
||||
|
@ -196,14 +196,14 @@ class WePay {
|
|||
curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt(self::$ch, CURLOPT_TIMEOUT, 30); // 30-second timeout, adjust to taste
|
||||
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
|
||||
|
||||
|
||||
$uri = self::getDomain() . $endpoint;
|
||||
curl_setopt(self::$ch, CURLOPT_URL, $uri);
|
||||
|
||||
|
||||
if (!empty($values)) {
|
||||
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, json_encode($values));
|
||||
}
|
||||
|
||||
|
||||
$raw = curl_exec(self::$ch);
|
||||
if ($errno = curl_errno(self::$ch)) {
|
||||
// Set up special handling for request timeouts
|
||||
|
@ -213,26 +213,23 @@ class WePay {
|
|||
throw new Exception('cURL error while making API call to WePay: ' . curl_error(self::$ch), $errno);
|
||||
}
|
||||
$result = json_decode($raw);
|
||||
|
||||
$error_code = null;
|
||||
if (isset($result->error_code)) {
|
||||
$error_code = $result->error_code;
|
||||
}
|
||||
|
||||
$httpCode = curl_getinfo(self::$ch, CURLINFO_HTTP_CODE);
|
||||
if ($httpCode >= 400) {
|
||||
if (!isset($result->error_code)) {
|
||||
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);
|
||||
}
|
||||
if ($httpCode >= 500) {
|
||||
throw new WePayServerException($result->error_description, $httpCode, $result, $error_code);
|
||||
throw new WePayServerException($result->error_description, $httpCode, $result, $result->error_code);
|
||||
}
|
||||
switch ($result->error) {
|
||||
case 'invalid_request':
|
||||
throw new WePayRequestException($result->error_description, $httpCode, $result, $error_code);
|
||||
throw new WePayRequestException($result->error_description, $httpCode, $result, $result->error_code);
|
||||
case 'access_denied':
|
||||
default:
|
||||
throw new WePayPermissionException($result->error_description, $httpCode, $result, $error_code);
|
||||
throw new WePayPermissionException($result->error_description, $httpCode, $result, $result->error_code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -246,13 +243,13 @@ class WePay {
|
|||
*/
|
||||
public function request($endpoint, array $values = array()) {
|
||||
$headers = array();
|
||||
|
||||
|
||||
if ($this->token) { // if we have an access_token, add it to the Authorization header
|
||||
$headers[] = "Authorization: Bearer $this->token";
|
||||
}
|
||||
|
||||
|
||||
$result = self::make_request($endpoint, $values, $headers);
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue