tipo: modificación del cpanel y gitignore de la carpeta vendor
This commit is contained in:
+178
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class Openpay
|
||||
{
|
||||
|
||||
private static $instance = null;
|
||||
private static $id;
|
||||
private static $apiKey;
|
||||
private static $userAgent = '';
|
||||
private static $country;
|
||||
private static $apiEndpoint = '';
|
||||
private static $apiSandboxEndpoint = '';
|
||||
private static $sandboxMode = true;
|
||||
private static $classification = '';
|
||||
private static $publicIp;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance($id, $apiKey, $country, $publicIp)
|
||||
{
|
||||
if ($id != '') {
|
||||
self::setId($id);
|
||||
}
|
||||
if ($apiKey != '') {
|
||||
self::setApiKey($apiKey);
|
||||
}
|
||||
if ($country != '') {
|
||||
self::setCountry($country);
|
||||
self::setEndpointUrl($country);
|
||||
}
|
||||
if(!is_null($publicIp)){
|
||||
self::setPublicIp($publicIp);
|
||||
}
|
||||
$instance = OpenpayApi::getInstance(null);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public static function setUserAgent($userAgent)
|
||||
{
|
||||
if ($userAgent != '') {
|
||||
self::$userAgent = $userAgent;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUserAgent()
|
||||
{
|
||||
$userAgent = self::$userAgent;
|
||||
return $userAgent;
|
||||
}
|
||||
|
||||
public static function setClassificationMerchant($classification)
|
||||
{
|
||||
if ($classification != '') {
|
||||
self::$classification = $classification;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getClassificationMerchant()
|
||||
{
|
||||
$classification = self::$classification;
|
||||
return $classification;
|
||||
}
|
||||
|
||||
public static function setApiKey($key = '')
|
||||
{
|
||||
if ($key != '') {
|
||||
self::$apiKey = $key;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getApiKey()
|
||||
{
|
||||
$key = self::$apiKey;
|
||||
if (!$key) {
|
||||
$key = getenv('OPENPAY_API_KEY');
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
public static function setId($id = '')
|
||||
{
|
||||
if ($id != '') {
|
||||
self::$id = $id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function setCountry($country = '')
|
||||
{
|
||||
if ($country != '') {
|
||||
self::$country = $country;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCountry()
|
||||
{
|
||||
$country = self::$country;
|
||||
return $country;
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
$id = self::$id;
|
||||
if (!$id) {
|
||||
$id = getenv('OPENPAY_MERCHANT_ID');
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function setPublicIp($publicIp = null)
|
||||
{
|
||||
if (!is_null($publicIp)) {
|
||||
self::$publicIp = $publicIp;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getPublicIp() {
|
||||
return self::$publicIp;
|
||||
|
||||
}
|
||||
|
||||
public static function getSandboxMode()
|
||||
{
|
||||
$sandbox = self::$sandboxMode;
|
||||
if (getenv('OPENPAY_PRODUCTION_MODE')) {
|
||||
$sandbox = (strtoupper(getenv('OPENPAY_PRODUCTION_MODE')) == 'FALSE');
|
||||
}
|
||||
return $sandbox;
|
||||
}
|
||||
|
||||
public static function setSandboxMode($mode)
|
||||
{
|
||||
self::$sandboxMode = $mode ? true : false;
|
||||
}
|
||||
|
||||
public static function getProductionMode()
|
||||
{
|
||||
$sandbox = self::$sandboxMode;
|
||||
if (getenv('OPENPAY_PRODUCTION_MODE')) {
|
||||
$sandbox = (strtoupper(getenv('OPENPAY_PRODUCTION_MODE')) == 'FALSE');
|
||||
}
|
||||
return !$sandbox;
|
||||
}
|
||||
|
||||
public static function setProductionMode($mode)
|
||||
{
|
||||
self::$sandboxMode = $mode ? false : true;
|
||||
}
|
||||
|
||||
public static function setEndpointUrl($country)
|
||||
{
|
||||
if ($country == 'MX') {
|
||||
if (self::getClassificationMerchant() != 'eglobal') {
|
||||
self::$apiEndpoint = 'https://api.openpay.mx/v1';
|
||||
self::$apiSandboxEndpoint = 'https://sandbox-api.openpay.mx/v1';
|
||||
} else {
|
||||
self::$apiEndpoint = 'https://api.ecommercebbva.com/v1';
|
||||
self::$apiSandboxEndpoint = 'https://sand-api.ecommercebbva.com/v1';
|
||||
}
|
||||
} elseif ($country == 'CO') {
|
||||
self::$apiEndpoint = 'https://api.openpay.co/v1';
|
||||
self::$apiSandboxEndpoint = 'https://sandbox-api.openpay.co/v1';
|
||||
} elseif ($country == 'PE') {
|
||||
self::$apiEndpoint = 'https://api.openpay.pe/v1';
|
||||
self::$apiSandboxEndpoint = 'https://sandbox-api.openpay.pe/v1';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getEndpointUrl()
|
||||
{
|
||||
return (self::getSandboxMode() ? self::$apiSandboxEndpoint : self::$apiEndpoint);
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApi extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $derivedResources = array(
|
||||
'Bine' => array(),
|
||||
'Customer' => array(),
|
||||
'Card' => array(),
|
||||
'Charge' => array(),
|
||||
'Pse' => array(),
|
||||
'Payout' => array(),
|
||||
'Fee' => array(),
|
||||
'Plan' => array(),
|
||||
'Webhook' => array(),
|
||||
'Token' => array());
|
||||
|
||||
public static function getInstance($r, $p = null)
|
||||
{
|
||||
if(version_compare(phpversion(), '8.3.0', '<')){
|
||||
$resourceName = get_class();
|
||||
} else {
|
||||
$resourceName = self::class;
|
||||
}
|
||||
return parent::getInstance($resourceName);
|
||||
}
|
||||
|
||||
public function getMerchantInfo()
|
||||
{
|
||||
return parent::getMerchantInfo();
|
||||
}
|
||||
|
||||
protected function getResourceUrlName($p = true)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getFullURL()
|
||||
{
|
||||
return $this->getUrl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiAuthError extends OpenpayApiError
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiConnectionError extends OpenpayApiError
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
use Openpay\Data\Openpay as Openpay;
|
||||
|
||||
class OpenpayApiConnector
|
||||
{
|
||||
|
||||
private static $instance;
|
||||
private $apiKey;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->apiKey = '';
|
||||
}
|
||||
|
||||
private static function getInstance()
|
||||
{
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ------------------ PRIVATE FUNCTIONS ------------------
|
||||
|
||||
private function _request($method, $url, $params)
|
||||
{
|
||||
if (!class_exists('Openpay\\Data\\Openpay')) {
|
||||
throw new OpenpayApiError("Library install error, there are some missing classes");
|
||||
}
|
||||
OpenpayApiConsole::trace('OpenpayApiConnector @_request');
|
||||
|
||||
$myId = Openpay::getId();
|
||||
if (!$myId) {
|
||||
throw new OpenpayApiAuthError("Empty or no Merchant ID provided");
|
||||
} else if (!preg_match('/^[a-z0-9]{20}$/i', $myId)) {
|
||||
throw new OpenpayApiAuthError("Invalid Merchant ID '" . $myId . "'");
|
||||
}
|
||||
|
||||
$myApiKey = Openpay::getApiKey();
|
||||
if (!$myApiKey) {
|
||||
throw new OpenpayApiAuthError("Empty or no Private Key provided");
|
||||
} else if (!preg_match('/^sk_[a-z0-9]{32}$/i', $myApiKey)) {
|
||||
throw new OpenpayApiAuthError("Invalid Private Key '" . $myApiKey . "'");
|
||||
}
|
||||
|
||||
$publicIp = Openpay::getPublicIp();
|
||||
if(is_null($publicIp)){
|
||||
throw new OpenpayApiAuthError("Empty or no public ip provided");
|
||||
} else if (!filter_var($publicIp, FILTER_VALIDATE_IP)){
|
||||
throw new OpenpayApiAuthError("Invalid public ip '" . $publicIp . "'");
|
||||
}
|
||||
|
||||
$absUrl = Openpay::getEndpointUrl();
|
||||
if (!$absUrl) {
|
||||
throw new OpenpayApiConnectionError("No API endpoint set");
|
||||
}
|
||||
$absUrl .= '/' . $myId . $url;
|
||||
|
||||
//$params = self::_encodeObjects($params);
|
||||
|
||||
$userAgent = Openpay::getUserAgent();
|
||||
|
||||
if (empty($userAgent))
|
||||
$headers = array('User-Agent: OpenpayPhp/v2');
|
||||
else
|
||||
$headers = array('User-Agent: ' . $userAgent);
|
||||
|
||||
array_push($headers, 'X-Forwarded-For: ' . $publicIp);
|
||||
|
||||
list($rbody, $rcode) = $this->_curlRequest($method, $absUrl, $headers, $params, $myApiKey);
|
||||
return $this->interpretResponse($rbody, $rcode);
|
||||
}
|
||||
|
||||
private function _curlRequest($method, $absUrl, $headers, $params, $auth = null)
|
||||
{
|
||||
OpenpayApiConsole::trace('OpenpayApiConnector @_curlRequest');
|
||||
|
||||
$opts = array();
|
||||
if (!is_array($headers)) {
|
||||
$headers = array();
|
||||
}
|
||||
|
||||
if ($method == 'get') {
|
||||
$opts[CURLOPT_HTTPGET] = 1;
|
||||
if (count($params) > 0) {
|
||||
$encoded = $this->encodeToQueryString($params);
|
||||
$absUrl = $absUrl . '?' . $encoded;
|
||||
}
|
||||
} else if ($method == 'post') {
|
||||
$data = $this->encodeToJson($params);
|
||||
$opts[CURLOPT_POST] = 1;
|
||||
$opts[CURLOPT_POSTFIELDS] = $data;
|
||||
array_push($headers, 'Content-Type: application/json');
|
||||
array_push($headers, 'Content-Length: ' . strlen($data));
|
||||
} else if ($method == 'put') {
|
||||
$data = $this->encodeToJson($params);
|
||||
$opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
|
||||
$opts[CURLOPT_POSTFIELDS] = $data;
|
||||
array_push($headers, 'Content-Type: application/json');
|
||||
array_push($headers, 'Content-Length: ' . strlen($data));
|
||||
} else if ($method == 'delete') {
|
||||
$opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
|
||||
if (count($params) > 0) {
|
||||
$encoded = $this->encodeToQueryString($params);
|
||||
$absUrl = $absUrl . '?' . $encoded;
|
||||
}
|
||||
} else {
|
||||
throw new OpenpayApiError("Invalid request method '" . $method . "'");
|
||||
}
|
||||
|
||||
|
||||
$opts[CURLOPT_URL] = $absUrl;
|
||||
$opts[CURLOPT_RETURNTRANSFER] = TRUE;
|
||||
$opts[CURLOPT_CONNECTTIMEOUT] = 30;
|
||||
$opts[CURLOPT_TIMEOUT] = 80;
|
||||
$opts[CURLOPT_HTTPHEADER] = $headers;
|
||||
$opts[CURLOPT_SSL_VERIFYPEER] = TRUE;
|
||||
|
||||
if ($auth) {
|
||||
$opts[CURLOPT_USERPWD] = $auth . ':';
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, $opts);
|
||||
|
||||
OpenpayApiConsole::debug('Executing cURL: ' . strtoupper($method) . ' > ' . $absUrl);
|
||||
|
||||
$rbody = curl_exec($curl);
|
||||
$errorCode = curl_errno($curl);
|
||||
|
||||
// if request fails because bad certificate verification, then
|
||||
// retry the request by using the CA certificates bundle
|
||||
// CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE
|
||||
if ($errorCode == 60 || $errorCode == 77) {
|
||||
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
|
||||
$rbody = curl_exec($curl);
|
||||
}
|
||||
|
||||
if ($rbody === false) {
|
||||
OpenpayApiConsole::error('cURL request error: ' . curl_errno($curl));
|
||||
$message = curl_error($curl);
|
||||
$errorCode = curl_errno($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$this->handleCurlError($errorCode, $message);
|
||||
}
|
||||
$rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if (mb_detect_encoding($rbody, 'UTF-8', true) != 'UTF-8') {
|
||||
OpenpayApiConsole::warn('Response body is not an UTF-8 string');
|
||||
}
|
||||
|
||||
OpenpayApiConsole::debug('cURL body: ' . $rbody);
|
||||
OpenpayApiConsole::debug('cURL code: ' . $rcode);
|
||||
|
||||
return array($rbody, $rcode);
|
||||
}
|
||||
|
||||
private function encodeToQueryString($arr, $prefix = null)
|
||||
{
|
||||
if (!is_array($arr))
|
||||
return $arr;
|
||||
|
||||
$r = array();
|
||||
foreach ($arr as $k => $v) {
|
||||
if (is_null($v))
|
||||
continue;
|
||||
|
||||
if ($prefix && $k && !is_int($k))
|
||||
$k = $prefix . "[" . $k . "]";
|
||||
else if ($prefix)
|
||||
$k = $prefix . "[]";
|
||||
|
||||
if (is_array($v)) {
|
||||
$r[] = $this->encodeToQueryString($v, $k, true);
|
||||
} else {
|
||||
$r[] = urlencode($k) . "=" . urlencode($v);
|
||||
}
|
||||
}
|
||||
$string = implode("&", $r);
|
||||
OpenpayApiConsole::debug('Query string: ' . $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
private function encodeToJson($arr)
|
||||
{
|
||||
$encoded = json_encode($arr);
|
||||
if (mb_detect_encoding($encoded, 'UTF-8', true) != 'UTF-8') {
|
||||
$encoded = utf8_encode($encoded);
|
||||
}
|
||||
OpenpayApiConsole::debug('JSON UTF8 string: ' . $encoded);
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
private function interpretResponse($responseBody, $responseCode)
|
||||
{
|
||||
OpenpayApiConsole::trace('OpenpayApiConnector @interpretResponse');
|
||||
try {
|
||||
// return json as an array NOT an object
|
||||
if (!empty($responseBody)) {
|
||||
$traslatedResponse = json_decode($responseBody, true);
|
||||
} else {
|
||||
$traslatedResponse = array();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new OpenpayApiRequestError("Invalid response: " . $responseBody, $responseCode);
|
||||
}
|
||||
|
||||
if ($responseCode < 200 || $responseCode >= 300) {
|
||||
OpenpayApiConsole::error('Request finished with HTTP code ' . $responseCode);
|
||||
$this->handleRequestError($responseBody, $responseCode, $traslatedResponse);
|
||||
return array();
|
||||
}
|
||||
return $traslatedResponse;
|
||||
}
|
||||
|
||||
private function handleRequestError($responseBody, $responseCode, $traslatedResponse)
|
||||
{
|
||||
if (!is_array($traslatedResponse) || !isset($traslatedResponse['error_code'])) {
|
||||
throw new OpenpayApiRequestError("Invalid response body received from Openpay API Server");
|
||||
}
|
||||
|
||||
$message = isset($traslatedResponse['description']) ? $traslatedResponse['description'] : 'No description';
|
||||
$error = $traslatedResponse['error_code'];
|
||||
$category = isset($traslatedResponse['category']) ? $traslatedResponse['category'] : null;
|
||||
$request_id = isset($traslatedResponse['request_id']) ? $traslatedResponse['request_id'] : null;
|
||||
$fraud_rules = isset($traslatedResponse['fraud_rules']) ? $traslatedResponse['fraud_rules'] : null;
|
||||
|
||||
switch ($responseCode) {
|
||||
|
||||
// Unauthorized - Forbidden
|
||||
case 401:
|
||||
case 403:
|
||||
throw new OpenpayApiAuthError($message, $error, $category, $request_id, $responseCode, $fraud_rules);
|
||||
break;
|
||||
|
||||
// Bad Request - Request Entity too large - Request Entity too large - Internal Server Error - Service Unavailable
|
||||
case 400:
|
||||
case 404:
|
||||
case 413:
|
||||
case 422:
|
||||
case 500:
|
||||
case 503:
|
||||
throw new OpenpayApiRequestError($message, $error, $category, $request_id, $responseCode, $fraud_rules);
|
||||
break;
|
||||
|
||||
// Payment Required - Conflict - Preconditon Failed - Unprocessable Entity - Locked
|
||||
case 402:
|
||||
case 409:
|
||||
case 412:
|
||||
case 423:
|
||||
throw new OpenpayApiTransactionError($message, $error, $category, $request_id, $responseCode, $fraud_rules);
|
||||
break;
|
||||
|
||||
// Not Found
|
||||
default:
|
||||
throw new OpenpayApiError($message, $error, $category, $request_id, $responseCode, $fraud_rules);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleCurlError($errorCode, $message)
|
||||
{
|
||||
switch ($errorCode) {
|
||||
case CURLE_COULDNT_CONNECT:
|
||||
case CURLE_COULDNT_RESOLVE_HOST:
|
||||
case CURLE_OPERATION_TIMEOUTED:
|
||||
$msg = "Could not connect to Openpay. Please check your internet connection and try again";
|
||||
break;
|
||||
default:
|
||||
$msg = "Unexpected error connecting to Openpay";
|
||||
}
|
||||
|
||||
$msg .= " (Network error " . $errorCode . ")";
|
||||
throw new OpenpayApiConnectionError($msg);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ------------------ PUBLIC FUNCTIONS -------------------
|
||||
|
||||
public static function request($method, $url, $params = null)
|
||||
{
|
||||
OpenpayApiConsole::trace('OpenpayApiConnector @request ' . $url);
|
||||
|
||||
if (!$params) {
|
||||
$params = array();
|
||||
}
|
||||
|
||||
$method = strtolower($method);
|
||||
if (!in_array($method, array('get', 'post', 'delete', 'put'))) {
|
||||
throw new OpenpayApiError("Invalid request method '" . $method . "'");
|
||||
}
|
||||
|
||||
$connector = self::getInstance();
|
||||
return $connector->_request($method, $url, $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiConsole {
|
||||
|
||||
const CONSOLE_NONE = 0;
|
||||
const CONSOLE_TRACE = 2;
|
||||
const CONSOLE_DEBUG = 4;
|
||||
const CONSOLE_INFO = 8;
|
||||
const CONSOLE_WARNING = 16;
|
||||
const CONSOLE_ERROR = 32;
|
||||
const CONSOLE_CRITICAL = 64;
|
||||
const CONSOLE_ALL = 126;
|
||||
|
||||
private static $instance;
|
||||
private $level;
|
||||
private $toScreen;
|
||||
|
||||
private function __construct() {
|
||||
$this->level = self::CONSOLE_NONE;
|
||||
$this->toScreen = false;
|
||||
}
|
||||
|
||||
private function record($prefix, $text) {
|
||||
$output = $prefix . ': ' . print_r($text, true);
|
||||
if ($this->toScreen == true) {
|
||||
print_r('<pre>' . $output . '</pre>' . "\n");
|
||||
} else {
|
||||
syslog(LOG_INFO, $output);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkFlag($flag, $value) {
|
||||
return (($flag & $value) == $flag);
|
||||
}
|
||||
|
||||
private static function getInstance() {
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private static function _log($type, $flag, $text) {
|
||||
$logger = self::getInstance();
|
||||
if ($logger->checkFlag($flag, $logger->level))
|
||||
$logger->record('[' . strtoupper($type) . ']', $text);
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
public static function setLevel($level) {
|
||||
$instance = self::getInstance();
|
||||
$instance->level = $level;
|
||||
}
|
||||
|
||||
public static function printToScreen($flag) {
|
||||
$instance = self::getInstance();
|
||||
$instance->toScreen = ($flag ? true : false);
|
||||
}
|
||||
|
||||
public static function trace($text) {
|
||||
self::_log('trace', self::CONSOLE_TRACE, $text);
|
||||
}
|
||||
|
||||
public static function debug($text) {
|
||||
self::_log('debug', self::CONSOLE_DEBUG, $text);
|
||||
}
|
||||
|
||||
public static function info($text) {
|
||||
self::_log('info', self::CONSOLE_INFO, $text);
|
||||
}
|
||||
|
||||
public static function warn($text) {
|
||||
self::_log('warning', self::CONSOLE_WARNING, $text);
|
||||
}
|
||||
|
||||
public static function error($text) {
|
||||
self::_log('error', self::CONSOLE_ERROR, $text);
|
||||
}
|
||||
|
||||
public static function critical($text) {
|
||||
self::_log('critical', self::CONSOLE_CRITICAL, $text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiDerivedResource extends OpenpayApiResourceBase {
|
||||
|
||||
private $cacheList = array();
|
||||
|
||||
protected static function getInstance($resourceName, $p = null) {
|
||||
if (class_exists($resourceName . 'List')) {
|
||||
$resource = $resourceName . 'List';
|
||||
return new $resource($resourceName);
|
||||
}
|
||||
return new self($resourceName);
|
||||
}
|
||||
|
||||
protected function addResource($resource, $id = null) {
|
||||
if (!$id && isset($resource->id)) {
|
||||
$id = $resource->id;
|
||||
} else if (is_string($id)) {
|
||||
$id = strtolower($id);
|
||||
} else {
|
||||
$id = count($this->cacheList) + 1;
|
||||
}
|
||||
if (!$this->isResourceListed($id)) {
|
||||
$resource->parent = $this;
|
||||
$this->cacheList[$id] = $resource;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getResource($id) {
|
||||
$id = strtolower($id);
|
||||
if ($this->isResourceListed($id)) {
|
||||
return $this->cacheList[$id];
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeResource($id) {
|
||||
$id = strtolower($id);
|
||||
if ($this->isResourceListed($id)) {
|
||||
unset($this->cacheList[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function isResourceListed($id) {
|
||||
$id = strtolower($id);
|
||||
return (isset($this->cacheList[$id]) && !empty($this->cacheList[$id]));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ------------------ PUBLIC FUNCTIONS -------------------
|
||||
|
||||
|
||||
public function add($params) {
|
||||
OpenpayApiConsole::trace('OpenpayApiDerivedResource @add');
|
||||
|
||||
// TODO: validate call when the parent has not a valid ID
|
||||
$resource = parent::_create($this->resourceName, $params, array('parent' => $this));
|
||||
$this->addResource($resource);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function get($id) {
|
||||
OpenpayApiConsole::trace('OpenpayApiDerivedResource @get');
|
||||
|
||||
if ($this->isResourceListed($id)) {
|
||||
return $this->getResource($id);
|
||||
}
|
||||
$resource = parent::_retrieve($this->resourceName, $id, array('parent' => $this));
|
||||
$this->addResource($resource);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function getList($params) {
|
||||
OpenpayApiConsole::trace('OpenpayApiDerivedResource @find');
|
||||
|
||||
$list = parent::_find($this->resourceName, $params, array('parent' => $this));
|
||||
foreach ($list as $resource) {
|
||||
$this->addResource($resource);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
use Exception;
|
||||
|
||||
class OpenpayApiError extends Exception
|
||||
{
|
||||
|
||||
protected $description;
|
||||
protected $error_code;
|
||||
protected $category;
|
||||
protected $http_code;
|
||||
protected $request_id;
|
||||
protected $fraud_rules;
|
||||
|
||||
public function __construct($message = null, $error_code = 0, $category = null, $request_id = null, $http_code = null, $fraud_rules = null) {
|
||||
parent::__construct($message, $error_code);
|
||||
$this->description = $message;
|
||||
$this->error_code = isset($error_code) ? $error_code : 0;
|
||||
$this->category = isset($category) ? $category : '';
|
||||
$this->http_code = isset($http_code) ? $http_code : 0;
|
||||
$this->request_id = isset($request_id) ? $request_id : '';
|
||||
$this->fraud_rules = isset($fraud_rules) ? $fraud_rules : array();
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function getErrorCode() {
|
||||
return $this->error_code;
|
||||
}
|
||||
|
||||
public function getCategory() {
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function getHttpCode() {
|
||||
return $this->http_code;
|
||||
}
|
||||
|
||||
public function getRequestId() {
|
||||
return $this->request_id;
|
||||
}
|
||||
|
||||
public function getFraudRules() {
|
||||
return $this->fraud_rules;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiRequestError extends OpenpayApiError
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
abstract class OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $id;
|
||||
protected $parent;
|
||||
protected $resourceName = '';
|
||||
protected $serializableData;
|
||||
protected $noSerializableData;
|
||||
protected $derivedResources;
|
||||
|
||||
protected function __construct($resourceName, $params = array()) {
|
||||
$this->resourceName = $resourceName;
|
||||
$this->serializableData = array();
|
||||
$this->noSerializableData = array();
|
||||
|
||||
if (!is_array($params)) {
|
||||
throw new OpenpayApiError("Invalid parameter type detected when instantiating an Openpay resource (passed '".gettype($params)."', array expected)");
|
||||
}
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if ($key == 'id') {
|
||||
$this->id = $value;
|
||||
continue;
|
||||
}
|
||||
if ($key == 'parent') {
|
||||
$this->parent = $value;
|
||||
continue;
|
||||
}
|
||||
$this->serializableData[$key] = $value;
|
||||
}
|
||||
|
||||
if ($derived = $this->derivedResources) {
|
||||
foreach ($derived as $k => $v) {
|
||||
$name = strtolower($k).'s';
|
||||
$this->derivedResources[$name] = $this->processAttribute($k, $v);
|
||||
|
||||
// unsets the original attribute
|
||||
unset($this->derivedResources[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getInstance($resourceName, $props = null) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @getInstance > '.$resourceName);
|
||||
if (!class_exists($resourceName)) {
|
||||
throw new OpenpayApiError("Invalid Openpay resource type (class resource '".$resourceName."' is invalid)");
|
||||
}
|
||||
if (is_string($props)) {
|
||||
$props = array('id' => $props);
|
||||
} else if (!is_array($props)) {
|
||||
$props = array();
|
||||
}
|
||||
$resource = new $resourceName($resourceName, $props);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ------------------ PRIVATE FUNCTIONS ------------------
|
||||
|
||||
private function isList($var) {
|
||||
if (!is_array($var))
|
||||
return false;
|
||||
|
||||
foreach (array_keys($var) as $k) {
|
||||
if (!is_numeric($k))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function processAttribute($k, $v) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @processAttribute > '.$k);
|
||||
$value = null;
|
||||
|
||||
$resourceName = $this->getResourceName($k);
|
||||
if ($this->isResource($resourceName)) {
|
||||
// check is its a resource list
|
||||
if ($this->isList($v)) {
|
||||
$list = OpenpayApiDerivedResource::getInstance("Openpay\\Resources\\".$resourceName);
|
||||
$list->parent = $this;
|
||||
foreach ($v as $index => $objData) {
|
||||
$list->add($objData);
|
||||
}
|
||||
$value = $list;
|
||||
} else {
|
||||
$resource = self::getInstance("Openpay\\Resources\\".$resourceName);
|
||||
$resource->parent = $this;
|
||||
$resource->refreshData($v);
|
||||
$value = $resource;
|
||||
|
||||
if ($resourceName != $this->resourceName) {
|
||||
$this->registerInParent($resource);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_array($v)) {
|
||||
// if it's an array, then is an object an instance a standar class
|
||||
|
||||
$object = new \stdClass();
|
||||
foreach ($v as $key => $value) {
|
||||
$object->$key = $value;
|
||||
}
|
||||
$value = $object;
|
||||
} else {
|
||||
$value = $v;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function getResourceName($name) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @getResourceName');
|
||||
if (substr($name, 0, strlen('Openpay')) == 'Openpay') {
|
||||
return $name;
|
||||
}
|
||||
return 'Openpay'.ucfirst($name);
|
||||
}
|
||||
|
||||
private function isResource($resourceName) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @isResource > '.$resourceName);
|
||||
// $resourceName = $this->getResourceName($name);
|
||||
|
||||
return class_exists("Openpay\\Resources\\".$resourceName);
|
||||
}
|
||||
|
||||
private function registerInParent($resource) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @registerInParent');
|
||||
$parent = $this->parent;
|
||||
if ($parent instanceof OpenpayApiDerivedResource) {
|
||||
$parent = $this->parent->parent;
|
||||
}
|
||||
|
||||
if (!is_object($parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($container = $parent->getResource($resource->resourceName)) { // $resourceName
|
||||
if ($container instanceof OpenpayApiDerivedResource && method_exists($container, 'addResource')) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @registerInParent > registering derived resource in parent');
|
||||
$container->addResource($resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getSerializeParameters() {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @getSerializeParameters');
|
||||
return $this->serializableData;
|
||||
}
|
||||
|
||||
private function getResource($resourceName) {
|
||||
if ($this->derivedResources !== null) {
|
||||
foreach ($this->derivedResources as $resource) {
|
||||
if ($resource->resourceName == $resourceName) {
|
||||
return $resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ----------------- PROTECTED FUNCTIONS -----------------
|
||||
|
||||
protected function refreshData($data) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @refreshData');
|
||||
|
||||
if (!$data) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new OpenpayApiError("Invalid data received for processing, cannot update the Openpay resource");
|
||||
}
|
||||
|
||||
// unsets the unused attributes
|
||||
$removed = array_diff(array_keys($this->serializableData), array_keys($data));
|
||||
if (count($removed)) {
|
||||
OpenpayApiConsole::debug('OpenpayApiResourceBase @refreshData > removing unused data');
|
||||
foreach ($removed as $k) {
|
||||
if ($this->serializableData[$k]) {
|
||||
unset($this->serializableData[$k]);
|
||||
}
|
||||
if ($this->noSerializableData[$k]) {
|
||||
$this->noSerializableData[$k] = null;
|
||||
}
|
||||
if ($this->derivedResources[$k]) {
|
||||
//$this->derivedResources[$k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$k = strtolower($k);
|
||||
|
||||
$value = $this->processAttribute($k, $v);
|
||||
|
||||
if ($k == 'id') {
|
||||
if (!isset($this->id)) {
|
||||
$this->id = $v;
|
||||
}
|
||||
continue;
|
||||
|
||||
// by default, only protected vars & serializable data will be refresh
|
||||
// in this version, noSerializableData does not store any value
|
||||
} else if (property_exists($this, $k)) {
|
||||
$this->$k = $value;
|
||||
//if ($this->noSerializableData[$k]) {
|
||||
// $this->noSerializableData[$k] = $value;
|
||||
//}
|
||||
} else {
|
||||
$this->serializableData[$k] = $value;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getResourceUrlName($pluralize = true) {
|
||||
$ResourceUrl = explode('\\', $this->resourceName);
|
||||
$class = $ResourceUrl[sizeof($ResourceUrl)-1];
|
||||
if (substr($class, 0, strlen('Openpay')) == 'Openpay') {
|
||||
$class = substr($class, strlen('Openpay'));
|
||||
}
|
||||
if (substr($class, -1 * strlen('List')) == 'List') {
|
||||
$class = substr($class, 0, -1 * strlen('List'));
|
||||
}
|
||||
if (substr($class, -1 * strlen('OpenpayPse')) == 'Pse') {
|
||||
$class = 'Pse';
|
||||
return strtolower(urlencode($class));
|
||||
}
|
||||
return strtolower(urlencode($class)).($pluralize ? 's' : '');
|
||||
}
|
||||
|
||||
protected function validateParams($params) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @validateParams');
|
||||
if (!is_array($params)) {
|
||||
throw new OpenpayApiRequestError("Invalid parameters type detected (type '".gettype($params)."' received, Array expected)");
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateId($id) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @validateId');
|
||||
$class = $this->resourceName;
|
||||
if (substr($class, -1 * strlen('Bine')) != 'Bine') {
|
||||
if (!is_string($id) || !preg_match('/^[a-z][a-z0-9]{0,20}$/i', $id)) {
|
||||
throw new OpenpayApiRequestError("Invalid ID detected (value '".$id."' received, alphanumeric string not longer than 20 characters expected)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMerchantInfo(){
|
||||
$response = OpenpayApiConnector::request('get', '/' , null);
|
||||
return json_decode(json_encode($response));
|
||||
}
|
||||
|
||||
protected function _create($resourceName, $params, $props = null) {
|
||||
|
||||
$resource = self::getInstance($resourceName, $props);
|
||||
$resource->validateParams($params);
|
||||
|
||||
// TODO: handle errors, not return anything
|
||||
$response = OpenpayApiConnector::request('post', $resource->getUrl(), $params);
|
||||
return $resource->refreshData($response);
|
||||
}
|
||||
|
||||
protected function _retrieve($resourceName, $id, $props = null) {
|
||||
if ($props && is_array($props)) {
|
||||
$props['id'] = $id;
|
||||
} else {
|
||||
$props = array('id' => $id);
|
||||
}
|
||||
|
||||
$resource = self::getInstance($resourceName, $props);
|
||||
$resource->validateId($id);
|
||||
|
||||
$response = OpenpayApiConnector::request('get', $resource->getUrl());
|
||||
return $resource->refreshData($response);
|
||||
}
|
||||
|
||||
protected function _find($resourceName, $params, $props = null) {
|
||||
|
||||
$resource = self::getInstance($resourceName, $props);
|
||||
$resource->validateParams($params);
|
||||
|
||||
$list = array();
|
||||
$response = OpenpayApiConnector::request('get', $resource->getUrl(), $params);
|
||||
if ($this->isList($response)) {
|
||||
foreach ($response as $v) {
|
||||
$item = self::getInstance($resourceName);
|
||||
$item->refreshData($v);
|
||||
array_push($list, $item);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function _update() {
|
||||
$params = $this->getSerializeParameters();
|
||||
|
||||
if (count($params)) {
|
||||
$response = OpenpayApiConnector::request('put', $this->getUrl(), $params);
|
||||
return $this->refreshData($response);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _updateCharge($params) {
|
||||
if (count($params)) {
|
||||
$response = OpenpayApiConnector::request('put', $this->getResourceUrlName(), $params);
|
||||
return $this->refreshData($response);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _delete() {
|
||||
OpenpayApiConnector::request('delete', $this->getUrl(), null);
|
||||
|
||||
// remove from list, if parent is a list
|
||||
if ($this->id && $this->parent && method_exists($this->parent, 'removeResource')) {
|
||||
$this->parent->removeResource($this->id);
|
||||
}
|
||||
//$this->empty(); // TODO
|
||||
}
|
||||
|
||||
protected function _getAttributes($param) {
|
||||
$url = $this->getUrl().'/'.$param;
|
||||
$response = OpenpayApiConnector::request('get', $url, null);
|
||||
return json_decode(json_encode($response));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// ------------------ PUBLIC FUNCTIONS -------------------
|
||||
|
||||
public function getUrl() { // $includeId = true
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @getUrl > class/parent: '.get_class($this).'/'.($this->parent ? 'true' : 'false'));
|
||||
$parentUrl = '';
|
||||
|
||||
if ($this->parent) {
|
||||
$parentUrl = $this->parent->getUrl();
|
||||
if ($this->parent instanceof OpenpayApiDerivedResource) {
|
||||
return $parentUrl.($this->id ? '/'.$this->id : '');
|
||||
}
|
||||
}
|
||||
$resourceUrlName = $this->getResourceUrlName();
|
||||
return ($parentUrl != '' ? $parentUrl : '').($resourceUrlName != '' ? '/'.$resourceUrlName : '').($this->id ? '/'.$this->id : '');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// -------------------- MAGIC METHODS --------------------
|
||||
|
||||
public function __set($key, $value) {
|
||||
OpenpayApiConsole::trace('OpenpayApiResourceBase @__set > '.$key.' = '.$value);
|
||||
if ($value === '' || !$value) {
|
||||
error_log("[OPENPAY Notice] The property '".$key."' will be set to en empty string which will be intepreted ad a NULL in request");
|
||||
}
|
||||
if (isset($this->$key) && is_array($value)) {
|
||||
// TODO: handle this properly, eg: interpret the array as an object and replace value as
|
||||
// $this->$key->replaceWith($value);
|
||||
throw new OpenpayApiError("The property '".$key."' cannot be assigned directly with an array");
|
||||
//} else if (property_exists($this, $key)) {
|
||||
// $this->$key = $value;
|
||||
} else if (isset($this->serializableData[$key])) {
|
||||
$this->serializableData[$key] = $value;
|
||||
} elseif (isset($this->derivedResources[$key])) {
|
||||
$this->derivedResources[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
if (property_exists($this, $key)) {
|
||||
return $this->$key;
|
||||
} else if (array_key_exists($key, $this->serializableData)) {
|
||||
return $this->serializableData[$key];
|
||||
} else if (array_key_exists($key, $this->derivedResources)) {
|
||||
return $this->derivedResources[$key];
|
||||
} else if (array_key_exists($key, $this->noSerializableData)) {
|
||||
return $this->noSerializableData[$key];
|
||||
} else {
|
||||
$resourceName = get_class($this);
|
||||
error_log("[OPENPAY Notice] Undefined property of $resourceName instance: $key"); // TODO error_log?
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Data;
|
||||
|
||||
class OpenpayApiTransactionError extends OpenpayApiError
|
||||
{
|
||||
|
||||
}
|
||||
+3451
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayBankAccount extends OpenpayApiResourceBase
|
||||
{
|
||||
protected $bank_code;
|
||||
protected $bank_name;
|
||||
protected $creation_date;
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->_delete();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayBankAccountList extends OpenpayApiDerivedResource
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayBine extends OpenpayApiResourceBase {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayCapture extends OpenpayApiResourceBase {
|
||||
protected function getResourceUrlName($p = true){
|
||||
return parent::getResourceUrlName(false);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Openpay API v1 Client for PHP (version 2.2.*)
|
||||
*
|
||||
* Copyright © Openpay SAPI de C.V. All rights reserved.
|
||||
* http://www.openpay.mx/
|
||||
* soporte@openpay.mx
|
||||
*/
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayCard extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $type;
|
||||
protected $brand;
|
||||
protected $allows_charges;
|
||||
protected $allows_payouts;
|
||||
protected $creation_date;
|
||||
protected $bank_name;
|
||||
protected $bank_code;
|
||||
protected $customer_id;
|
||||
|
||||
public function delete() {
|
||||
$this->_delete();
|
||||
}
|
||||
|
||||
public function get($param) {
|
||||
return $this->_getAttributes($param);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayCardList extends OpenpayApiDerivedResource
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayCharge extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $authorization;
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $customer_id;
|
||||
protected $operation_type;
|
||||
protected $status;
|
||||
protected $transaction_type;
|
||||
// temporal hack
|
||||
// TODO: checar porque no instancia Openpaycard al recibir el parametro
|
||||
protected $card;
|
||||
protected $derivedResources = array('Refund' => null, 'Capture' => null);
|
||||
|
||||
public function refund($params)
|
||||
{
|
||||
$resource = $this->derivedResources['refunds'];
|
||||
if ($resource) {
|
||||
return parent::_create($resource->resourceName, $params, array('parent' => $this));
|
||||
}
|
||||
}
|
||||
|
||||
public function capture($params)
|
||||
{
|
||||
$resource = $this->derivedResources['captures'];
|
||||
if ($resource) {
|
||||
return parent::_create($resource->resourceName, $params, array('parent' => $this));
|
||||
}
|
||||
}
|
||||
|
||||
public function update($params)
|
||||
{
|
||||
return $this->_updateCharge($params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayChargeList extends OpenpayApiDerivedResource
|
||||
{
|
||||
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayCustomer extends OpenpayApiResourceBase {
|
||||
|
||||
protected $status;
|
||||
protected $creation_date;
|
||||
protected $balance;
|
||||
protected $clabe;
|
||||
protected $derivedResources = array(
|
||||
'Card' => array(),
|
||||
'BankAccount' => array(),
|
||||
'Charge' => array(),
|
||||
'Pse' => array(),
|
||||
'Transfer' => array(),
|
||||
'Payout' => array(),
|
||||
'Subscription' => array());
|
||||
|
||||
public function save() {
|
||||
return $this->_update();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->_delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayCustomerList extends OpenpayApiDerivedResource
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayFee extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $authorization;
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $operation_type;
|
||||
protected $status;
|
||||
protected $transaction_type;
|
||||
protected $error_message;
|
||||
protected $method;
|
||||
protected $derivedResources = array('Refund' => null);
|
||||
|
||||
public function refund($params) {
|
||||
$resource = $this->derivedResources['refunds'];
|
||||
if ($resource) {
|
||||
return parent::_create($resource->resourceName, $params, array('parent' => $this));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayFeeList extends OpenpayApiDerivedResource
|
||||
{
|
||||
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayPayout extends OpenpayApiResourceBase {
|
||||
protected $authorization;
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $operation_type;
|
||||
protected $status;
|
||||
protected $transaction_type;
|
||||
protected $error_message;
|
||||
protected $method;
|
||||
|
||||
// temporal hack
|
||||
// TODO: checar porque no instancia Openpaycard al recibir el parametro
|
||||
protected $card;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayPayoutList extends OpenpayApiDerivedResource
|
||||
{
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayPlan extends OpenpayApiResourceBase {
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $amount;
|
||||
protected $repeat_every;
|
||||
protected $repeat_unit;
|
||||
protected $retry_times;
|
||||
protected $status;
|
||||
protected $status_after_retry;
|
||||
|
||||
protected $derivedResources = array('Subscription' => array());
|
||||
|
||||
public function save() {
|
||||
return $this->_update();
|
||||
}
|
||||
public function delete() {
|
||||
$this->_delete();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayPlanList extends OpenpayApiDerivedResource
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayPse extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $authorization;
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $customer_id;
|
||||
protected $operation_type;
|
||||
protected $status;
|
||||
protected $transaction_type;
|
||||
protected $derivedResources = array();
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayPseList extends OpenpayApiDerivedResource
|
||||
{
|
||||
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayRefund extends OpenpayApiResourceBase {
|
||||
protected function getResourceUrlName($p = true){
|
||||
return parent::getResourceUrlName(false);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpaySubscription extends OpenpayApiResourceBase {
|
||||
protected $status;
|
||||
protected $charge_date;
|
||||
protected $creation_date;
|
||||
protected $current_period_number;
|
||||
protected $period_end_date;
|
||||
protected $plan_id;
|
||||
protected $customer_id;
|
||||
|
||||
// temporal hack
|
||||
// TODO: checar porque no instancia Openpaycard al recibir el parametro
|
||||
protected $card;
|
||||
|
||||
public function save() {
|
||||
return $this->_update();
|
||||
}
|
||||
public function delete() {
|
||||
$this->_delete();
|
||||
}
|
||||
|
||||
public function __set($key, $value) {
|
||||
|
||||
if ($key == 'source_id') {
|
||||
if (!array_key_exists($key, $this->serializableData)) {
|
||||
$this->serializableData['source_id'] = $value;
|
||||
}
|
||||
} else {
|
||||
parent::__set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpaySubscriptionList extends OpenpayApiDerivedResource
|
||||
{
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayToken extends OpenpayApiResourceBase
|
||||
{
|
||||
protected $card;
|
||||
|
||||
public function get($param) {
|
||||
return $this->_getAttributes($param);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayTransfer extends OpenpayApiResourceBase {
|
||||
protected $authorization;
|
||||
protected $creation_date;
|
||||
protected $currency;
|
||||
protected $operation_type;
|
||||
protected $status;
|
||||
protected $transaction_type;
|
||||
protected $error_message;
|
||||
protected $method;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiDerivedResource;
|
||||
|
||||
class OpenpayTransferList extends OpenpayApiDerivedResource
|
||||
{
|
||||
public function create($params)
|
||||
{
|
||||
return $this->add($params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Openpay\Resources;
|
||||
|
||||
use Openpay\Data\OpenpayApiResourceBase;
|
||||
|
||||
class OpenpayWebhook extends OpenpayApiResourceBase
|
||||
{
|
||||
|
||||
protected $url;
|
||||
protected $event_types;
|
||||
|
||||
public function save()
|
||||
{
|
||||
return $this->_update();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->_delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user