This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Culqi;
/**
* Class Cards
*
* @package Culqi
*/
class Cards extends Resource {
const URL_CARDS = "/cards/";
/**
* @param array|null $options
*
* @return all Cards.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_CARDS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Card response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_CARDS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return delete a Card response.
*/
public function delete($id = NULL) {
return $this->request("DELETE", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return get a Card.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Card response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_CARDS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Culqi;
/**
* Class Charges
*
* @package Culqi
*/
class Charges extends Resource {
const URL_CHARGES = "/charges/";
/**
* @param array|null $options
*
* @return all Charges.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Charge response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_CHARGES, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Charge.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return get a capture of Charge.
*/
public function capture($id = NULL) {
return $this->request("POST", self::URL_CHARGES . $id . "/capture/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Charge response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_CHARGES . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Culqi;
use Culqi\Error as Errors;
/**
* Class Client
*
* @package Culqi
*/
class Client {
public function request($method, $url, $api_key, $data = NULL) {
try {
$url_params = is_array($data) ? '?' . http_build_query($data) : '';
$headers= array("Authorization" => "Bearer ".$api_key, "Content-Type" => "application/json", "Accept" => "application/json");
$options = array(
'timeout' => 120
);
if($method == "GET") {
$response = \Requests::get(Culqi::BASE_URL. $url . $url_params, $headers, $options);
} else if($method == "POST") {
$response = \Requests::post(Culqi::BASE_URL . $url, $headers, json_encode($data), $options);
} else if($method == "PATCH") {
$response = \Requests::patch(Culqi::BASE_URL . $url, $headers, json_encode($data), $options);
} else if($method == "DELETE") {
$response = \Requests::delete(Culqi::BASE_URL. $url . $url_params, $headers, $options);
}
} catch (\Exception $e) {
throw new Errors\UnableToConnect();
}
if ($response->status_code >= 200 && $response->status_code <= 206) {
return json_decode($response->body);
}
if ($response->status_code == 400) {
throw new Errors\UnhandledError($response->body, $response->status_code);
}
if ($response->status_code == 401) {
throw new Errors\AuthenticationError();
}
if ($response->status_code == 404) {
throw new Errors\NotFound();
}
if ($response->status_code == 403) {
throw new Errors\InvalidApiKey();
}
if ($response->status_code == 405) {
throw new Errors\MethodNotAllowed();
}
throw new Errors\UnhandledError($response->body, $response->status_code);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Culqi;
use Culqi\Error as Errors;
/**
* Class Culqi
*
* @package Culqi
*/
class Culqi
{
public $api_key;
/**
* La versión de API usada
*/
const API_VERSION = "v2.0";
/**
* La URL Base por defecto
*/
const BASE_URL = "https://api.culqi.com/v2";
/**
* Constructor.
*
* @param array|null $options
*
* @throws Error\InvalidApiKey
*
* @example array('api_key' => "{api_key}")
*
*/
public function __construct($options)
{
$this->api_key = $options["api_key"];
if (!$this->api_key) {
throw new Errors\InvalidApiKey();
}
$this->Tokens = new Tokens($this);
$this->Charges = new Charges($this);
$this->Subscriptions = new Subscriptions($this);
$this->Refunds = new Refunds($this);
$this->Plans = new Plans($this);
$this->Transfers = new Transfers($this);
$this->Iins = new Iins($this);
$this->Cards = new Cards($this);
$this->Events = new Events($this);
$this->Customers = new Customers($this);
$this->Orders = new Orders($this);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Culqi;
/**
* Class Customers
*
* @package Culqi
*/
class Customers extends Resource {
const URL_CUSTOMERS = "/customers/";
/**
* @param array|null $options
*
* @return all Customers.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Customer response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_CUSTOMERS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return delete a Customer response.
*/
public function delete($id = NULL) {
return $this->request("DELETE", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return get a Customer.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Charge response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_CUSTOMERS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Culqi\Error;
/**
* Culqi Exceptions
*/
/**
* Base Culqi Exception
*/
class CulqiException extends \Exception {
protected $message = "Base Culqi Exception";
}
/**
* Input validation error
*/
namespace Culqi\Error;
class InputValidationError extends CulqiException {
protected $message = "Error de validacion en los campos";
}
/**
* Authentication error
*/
namespace Culqi\Error;
class AuthenticationError extends CulqiException {
protected $message = "Error de autenticación";
}
/**
* Resource not found
*/
namespace Culqi\Error;
class NotFound extends CulqiException {
protected $message = "Recurso no encontrado";
}
/**
* Method not allowed
*/
namespace Culqi\Error;
class MethodNotAllowed extends CulqiException {
protected $message = "Method not allowed";
}
/**
* Unhandled error
*/
namespace Culqi\Error;
class UnhandledError extends CulqiException {
protected $message = "Unhandled error";
}
/**
* Invalid API Key
*/
namespace Culqi\Error;
class InvalidApiKey extends CulqiException {
protected $message = "API Key invalido";
}
/**
* Unable to connect to Culqi API
*/
class UnableToConnect extends CulqiException {
protected $message = "Imposible conectar a Culqi API";
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Culqi;
/**
* Class Events
*
* @package Culqi
*/
class Events extends Resource {
const URL_EVENTS = "/events/";
/**
* @param array|null $options
*
* @return all Events.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_EVENTS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Event.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_EVENTS . $id . "/", $api_key = $this->culqi->api_key);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Culqi;
/**
* Class Iins
*
* @package Culqi
*/
class Iins extends Resource {
const URL_IINS = "/iins/";
/**
* @param array|null $options
*
* @return all Iins.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_IINS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Iin.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_IINS . $id . "/", $api_key = $this->culqi->api_key);
}
}

View File

@@ -0,0 +1,2 @@
<?php
namespace Culqi\Lang\messages;

View File

@@ -0,0 +1,2 @@
<?php
namespace Culqi\Lang\messages;

View File

@@ -0,0 +1,70 @@
<?php
namespace Culqi;
/**
* Class Orders
*
* @package Culqi
*/
class Orders extends Resource {
const URL_ORDERS = "/orders/";
/**
* @param array|null $options
*
* @return Get all Orders
*/
public function all($options) {
return $this->request("GET", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Order
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return confirm Order
*/
public function confirm($id = NULL) {
return $this->request("POST", self::URL_ORDERS . $id . "/confirm/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return get a Order
*/
public function get($id) {
return $this->request("GET", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return delete a Order
*/
public function delete($id) {
return $this->request("DELETE", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Order
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Culqi;
/**
* Class Plans
*
* @package Culqi
*/
class Plans extends Resource {
const URL_PLANS = "/plans/";
/**
* @param array|null $options
*
* @return all Plans.
*/
public function all($options) {
return $this->request("GET", self::URL_PLANS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Plan response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_PLANS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Plan.
*/
public function get($id) {
return $this->request("GET", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return delete a Plan.
*/
public function delete($id) {
return $this->request("DELETE", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Plan response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_PLANS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Culqi;
/**
* Class Plans
*
* @package Culqi
*/
class Refunds extends Resource {
const URL_REFUNDS = "/refunds/";
/**
* @param array|null $options
*
* @return all Refunds.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Refund response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_REFUNDS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Refund.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_REFUNDS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Refund response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_REFUNDS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Culqi;
/**
* Class Resource
*
* @package Culqi
*/
class Resource extends Client {
/**
* Constructor.
*/
public function __construct($culqi)
{
$this->culqi = $culqi;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Culqi;
/**
* Class Subscriptions
*
* @package Culqi
*/
class Subscriptions extends Resource {
const URL_SUBSCRIPTIONS = "/subscriptions/";
/**
* @param array|null $options
*
* @return all Subscriptions.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Subscription response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_SUBSCRIPTIONS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return delete a Subscription response.
*/
public function delete($id = NULL) {
return $this->request("DELETE", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
*
* @return get a Subscription.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Subscription response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_SUBSCRIPTIONS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Culqi;
/**
* Class Tokens
*
* @package Culqi
*/
class Tokens extends Resource {
const URL_TOKENS = "/tokens/";
/**
* @param array|string|null $options
*
* @return all Tokens.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param array|null $options
*
* @return create Token response.
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_TOKENS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Token.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_TOKENS . $id . "/", $api_key = $this->culqi->api_key);
}
/**
* @param string|null $id
* @param array|null $options
*
* @return update Token response.
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_TOKENS . $id . "/", $api_key = $this->culqi->api_key, $options);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Culqi;
/**
* Class Transfers
*
* @package Culqi
*/
class Transfers extends Resource {
const URL_TRANSFERS = "/transfers/";
/**
* @param array|null $options
*
* @return all Transfers.
*/
public function all($options = NULL) {
return $this->request("GET", self::URL_TRANSFERS, $api_key = $this->culqi->api_key, $options);
}
/**
* @param string|null $id
*
* @return get a Transfers.
*/
public function get($id = NULL) {
return $this->request("GET", self::URL_TRANSFERS . $id . "/", $api_key = $this->culqi->api_key);
}
}

32
vendor/culqi/culqi-php/lib/culqi.php vendored Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* CULQI PHP SDK
*
* Init, cargamos todos los archivos necesarios
*
* @version 1.3.0
* @package Culqi
* @copyright Copyright (c) 2015-2017 Culqi
* @license MIT
* @license https://opensource.org/licenses/MIT MIT License
* @link https://developers.culqi.com/ Culqi Developers
*/
// Errors
include_once dirname(__FILE__).'/Culqi/Error/Errors.php';
include_once dirname(__FILE__).'/Culqi/Client.php';
include_once dirname(__FILE__).'/Culqi/Resource.php';
// Culqi API
include_once dirname(__FILE__).'/Culqi/Transfers.php';
include_once dirname(__FILE__).'/Culqi/Cards.php';
include_once dirname(__FILE__).'/Culqi/Events.php';
include_once dirname(__FILE__).'/Culqi/Customers.php';
include_once dirname(__FILE__).'/Culqi/Tokens.php';
include_once dirname(__FILE__).'/Culqi/Charges.php';
include_once dirname(__FILE__).'/Culqi/Refunds.php';
include_once dirname(__FILE__).'/Culqi/Subscriptions.php';
include_once dirname(__FILE__).'/Culqi/Plans.php';
include_once dirname(__FILE__).'/Culqi/Iins.php';
include_once dirname(__FILE__).'/Culqi/Orders.php';
include_once dirname(__FILE__).'/Culqi/Culqi.php';