From f1cd973e47257d73e7710bd2cb61e6fca66e7ed7 Mon Sep 17 00:00:00 2001 From: Hamidouh Semix Date: Mon, 29 Apr 2019 16:54:37 +0300 Subject: [PATCH 1/2] Added Namespaced Coded --- ExampleInstance.php | 61 ++++ ExampleStatic.php | 67 ++++ beyonic/src/Beyonic.php | 306 +++++++++++++++++++ beyonic/src/Collection/Account.php | 16 + beyonic/src/Collection/Collection.php | 17 ++ beyonic/src/Collection/Contact.php | 16 + beyonic/src/Collection/Payment.php | 15 + beyonic/src/Collection/Request.php | 16 + beyonic/src/Collection/Response.php | 43 +++ beyonic/src/Collection/Transaction.php | 16 + beyonic/src/Collection/WebHook.php | 16 + beyonic/src/Endpoint/Wrapper.php | 154 ++++++++++ beyonic/src/Exceptions/BeyonicException.php | 50 +++ beyonic/src/Exceptions/NotFoundException.php | 10 + 14 files changed, 803 insertions(+) create mode 100755 ExampleInstance.php create mode 100755 ExampleStatic.php create mode 100755 beyonic/src/Beyonic.php create mode 100755 beyonic/src/Collection/Account.php create mode 100755 beyonic/src/Collection/Collection.php create mode 100755 beyonic/src/Collection/Contact.php create mode 100755 beyonic/src/Collection/Payment.php create mode 100755 beyonic/src/Collection/Request.php create mode 100755 beyonic/src/Collection/Response.php create mode 100755 beyonic/src/Collection/Transaction.php create mode 100755 beyonic/src/Collection/WebHook.php create mode 100755 beyonic/src/Endpoint/Wrapper.php create mode 100755 beyonic/src/Exceptions/BeyonicException.php create mode 100755 beyonic/src/Exceptions/NotFoundException.php diff --git a/ExampleInstance.php b/ExampleInstance.php new file mode 100755 index 0000000..cec37c3 --- /dev/null +++ b/ExampleInstance.php @@ -0,0 +1,61 @@ + '+256702880228', + "amount" => '500', + "currency" => "UGX", + "description" => 'Units Payment', + "metadata" => ['id' => '58475848kdd', 'appId' => 'Company Details Payment'], + "send_instructions" => true +]; +$beyonic->payment()->create($values); + +/** + * Make a Request i.e access the \Beyonic\Collection\Request object + * Through this one instance + */ + + $beyonic->request()->create($values); +/** + * Make a Response call i.e access the \Beyonic\Collection\Response object + * Through this one instance + */ + $beyonic->response()->getAll(); + /** + * Make a call to Accounts i.e access the \Beyonic\Collection\Account object + * Through this one instance + */ + $beyonic->account()->get(23343); + /** + * Make a call to Contacts i.e access the \Beyonic\Collection\Contact object + * Through this one instance + */ + $beyonic->contact()->getAll(); + /** + * Make a call to a Collection i.e access the \Beyonic\Collection\Collection object + * Through this one instance + */ + $beyonic->collection()->getAll(); + /** + * Make a Transaction i.e access the \Beyonic\Collection\Transaction object + * Through this one instance + */ + $beyonic->transaction()->getAll(); + /** + * Make a WebHook i.e access the \Beyonic\Collection\WebHook object + * Through this one instance + */ + $beyonic->webHook()->get(47737); \ No newline at end of file diff --git a/ExampleStatic.php b/ExampleStatic.php new file mode 100755 index 0000000..fe3cce5 --- /dev/null +++ b/ExampleStatic.php @@ -0,0 +1,67 @@ +setApiKey(key) + * is needed. The rest are optional + * + * Let's see how it works + */ + +$beyonic = new Beyonic('840604c20904844jjdjfhdj8747673n43j33k93'); +$values = [ + "phonenumber" => '+256702880228', + "amount" => '500', + "currency" => "UGX", + "description" => 'Units Payment', + "metadata" => ['id' => '58475848kdd', 'appId' => 'Company Details Payment'], +]; +/** + * Make a Payment i.e access the \Beyonic\Collection\Payment object + * Through this one instance + */ +$payment = \Beyonic\Collection\Payment::create($values); + +/** + * Make a Request i.e access the \Beyonic\Collection\Request object + * Through this one instance + */ + + $request = \Beyonic\Collection\Request::create($values); +/** + * Make a Response call i.e access the \Beyonic\Collection\Response object + * Through this one instance + */ + $response = \Beyonic\Collection\Response::getAll(); + /** + * Make a call to Accounts i.e access the \Beyonic\Collection\Account object + * Through this one instance + */ + $account = \Beyonic\Collection\Account::get(23343); + /** + * Make a call to Contacts i.e access the \Beyonic\Collection\Contact object + * Through this one instance + */ + $contact = \Beyonic\Collection\Contact::getAll(); + /** + * Make a call to a Collection i.e access the \Beyonic\Collection\Collection object + * Through this one instance + */ + $collection = \Beyonic\Collection\Collection::getAll(); + /** + * Make a Transaction i.e access the \Beyonic\Collection\Transaction object + * Through this one instance + */ + $transaction = \Beyonic\Collection\Transaction::getAll(); + /** + * Make a WebHook i.e access the \Beyonic\Collection\WebHook object + * Through this one instance + */ + $webHook = \Beyonic\Collection\WebHook::get(47737); \ No newline at end of file diff --git a/beyonic/src/Beyonic.php b/beyonic/src/Beyonic.php new file mode 100755 index 0000000..8e7d143 --- /dev/null +++ b/beyonic/src/Beyonic.php @@ -0,0 +1,306 @@ + + * @package Beyonic + */ +class Beyonic +{ + const CLIENT_VERSION = "0.0.6"; + protected $apiKey = null; + protected $apiURL = 'https://app.beyonic.com/api'; + protected $apiVersion = null; + protected $lastResult = null; + protected $wrapper; + + protected static $instance; + protected $methods = [ + 'request', + 'payment', + 'contact', + 'contact', + 'collection', + 'account', + 'webHook', + 'transaction' + ]; + + /** + * @author Hamidouh Semix + * @param string|null $apiKey + * @param string $apiUri + * @param string|null $lastResult + * @param string|null $apiVersion + */ + public function __construct($apiKey = null, $apiUri = 'https://app.beyonic.com/api', $lastResult = null, $apiVersion = null) + { + $this->apiKey = $apiKey; + $this->apiURL = $apiUri; + $this->apiVersion = $apiVersion; + $this->lastResult = $lastResult; + $this->wrapper = new Wrapper(); + if (!static::$instance) { + static::$instance = $this; + } + } + + /** + * Return a static instance of the Beyonic object through out the request + * + * @author Hamidouh Semix + * @param null + * @return static $instance + */ + + public static function getInstance() + { + if (is_null(static::$instance)) { + throw new NotFoundException(sprintf("No instance of %s was found, create one to proceed", static::class)); + } + return static::$instance; + } + + /** + * setAPIKey - Sets the API Key for this client / developer + * + * @author Hamidouh Semix + * @param string|null $newApiKey + * @return void + */ + public function setApiKey($newApiKey = null) + { + $this->apiKey = $newApiKey; + } + + /** + * Return the apiKey that was set + * + * @author Hamidouh Semix + * @param null + * @return string|null $apiKey + */ + public function getApiKey() + { + return $this->apiKey; + } + + /** + * setAPIVersion - Sets the API Version for this client / developer. + * + * @author Hamidouh Semix + * @param string|null $newApiVersion + * @return void + */ + public function setApiVersion($newApiVersion = null) + { + $this->apiVersion = $newApiVersion; + } + /** + * Return the apiVersion that was set + * + * @author Hamidouh Semix + * @param null + * @return string|null $apiVersion + */ + public function getApiVersion() + { + return $this->apiVersion; + } + + /** + * Return the client version + * + * @author Hamidouh Semix + * @param null + * @return string + */ + public static function getClientVersion() + { + return self::CLIENT_VERSION; + } + + /** + * sendRequest - Sends a REST request to the Beyonic API endpoint. + * $endpoint is the endpoint that is the target of the request. + * $method is one of GET, POST, PUT or DELETE. + * $id is used to identify the target of a GET, PUT or DELETE request. + * $parameters is used for POST and PUT, are content is based on the request. + * + * @author Hamidouh Semix + * @param string $endpoint + * @param string $method + * @param int|null $id + * @param array|null $parameters + * @return mixed $endpointObject + */ + public function sendRequest($endpoint, $method = 'GET', $id = null, array $parameters = null) + { + $beyonic = static::getInstance(); + $requestURL = $beyonic->apiURL . '/' . $endpoint; + if( $id != null ) + $requestURL .= '/' . $id; + + $jsonData = null; + if ($parameters != null ) { + $metadata = []; + foreach($parameters as $key => $value) { + // if the key starts with 'metadata.', transform it to array notation + if (strpos($key, 'metadata.') === 0) { + $metadata[explode('.', $key)[1]] = $value; + unset($parameters[$key]); + } + } + if ($metadata) { + $parameters = array_merge($parameters, ['metadata'=>$metadata]); + } + $jsonData = json_encode($parameters); + } + + $httpHeaders = [ + 'Content-Type: application/json', + 'Content-Language:en-US', + 'Authorization: Token ' . $beyonic->apiKey, + 'Beyonic-Client: Php', + 'Beyonic-Client-Version: ' . self::CLIENT_VERSION + ]; + + if ($beyonic->apiVersion != null) + $httpHeaders[] = 'Beyonic-Version: ' . $beyonic->apiVersion; + + $ch = curl_init(); + switch ($method) { + case 'GET': + if ($parameters != null) { + $requestURL .= "?"; + foreach($parameters as $key=>$value) { + $requestURL .= $key . "=" . urlencode($value) . "&"; + } + } + break; + case 'POST': + curl_setopt($ch, CURLOPT_POST, 1); + if ($jsonData != null) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + $httpHeaders[] = 'Content-Length:' . strlen( $jsonData ); + } + break; + case 'PATCH': + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); + if ($jsonData != null) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + $httpHeaders[] = 'Content-Length:' . strlen( $jsonData ); + } + break; + case 'DELETE': + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + break; + } + + $endpointObject = $beyonic->send($ch, $requestURL, $httpHeaders, $method); + + return $endpointObject; + } + + /** + * Send a request to an endpoint + * + * @author Hamidouh Semix + * @param string $ch + * @param string $requestURL + * @param array $httpHeaders + * @param string $method + * @return string json + */ + protected function send($ch, $requestURL, $httpHeaders, $method) + { + curl_setopt($ch, CURLOPT_URL, $requestURL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_VERBOSE, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); + + $response = curl_exec($ch); + $responseArray = []; + $responseArray['requestURL'] = $requestURL; + $responseArray['httpResponseCode'] = curl_getinfo( $ch, CURLINFO_HTTP_CODE); + $headerSize = curl_getinfo( $ch, CURLINFO_HEADER_SIZE); + $responseArray['responseHeader'] = substr( $response, 0, $headerSize); + $responseArray['responseBody'] = substr($response, $headerSize); + + $this->lastResult = $responseArray; + + if( $responseArray['httpResponseCode'] >= 400 ) { + $headerArray = preg_split( "/\n/", $responseArray['responseHeader'] ); + throw new BeyonicException( + substr($headerArray[0],0,strlen($headerArray[0]) - 1), + $responseArray['httpResponseCode'], + $requestURL, + $method, + $responseArray['responseBody'] + ); + } + + return json_decode($responseArray['responseBody']); + } + + /** + * Return all endpoints to be accessed as methods for a bridge + * to the endpoint objects + * + * @author Hamidouh Semix + * @param null + * @return array $methods + */ + + public function getMethods() + { + return $this->methods; + } + + /** + * Build Dynamic methods to simplify the acces of all endpoints of the api + * And make all methods accessible with a class instance + * + * @author Hamidouh Semix + * @param string $method + * @param mixed $parameters + * @return \Beyonic\Endpoint\Wrapper + * @throws \Beyonic\Exceptions\NotFoundException + */ + public function __call($method, $parameters) + { + if (in_array($method, $this->getMethods())) { + $endPoint = '\\Beyonic\\Collection\\'. ucfirst($method); + return $this->wrapper = new $endPoint(null, $this); + } + throw new NotFoundException(sprintf("The method: %s doesn't exist in class: %s", $method, static::class)); + } + + /** + * Build Dynamic methods to simplify the acces of all endpoints of the api + * And make all methods accessible statically, i.e no need for a class instance + * + * @author Hamidouh Semix + * @param string $method + * @param mixed $parameters + * @return \Beyonic\Endpoint\Wrapper + * @throws \Beyonic\Exceptions\NotFoundException + */ + public static function __callStatic($method, $parameters) + { + $instance = static::getInstance(); + if (in_array($method, $instance->getMethods())) { + $endPoint = '\\Beyonic\\Collection\\'. ucfirst($method); + return $instance->wrapper = new $endPoint(null, $instance); + } + throw new NotFoundException(sprintf("The method: %s doesn't exist in class: %s", $method, static::class)); + } +} \ No newline at end of file diff --git a/beyonic/src/Collection/Account.php b/beyonic/src/Collection/Account.php new file mode 100755 index 0000000..870aced --- /dev/null +++ b/beyonic/src/Collection/Account.php @@ -0,0 +1,16 @@ + + * @package Beyonic + */ +class Account extends Wrapper +{ + protected $endpoint = 'accounts'; +} \ No newline at end of file diff --git a/beyonic/src/Collection/Collection.php b/beyonic/src/Collection/Collection.php new file mode 100755 index 0000000..9dcc9d7 --- /dev/null +++ b/beyonic/src/Collection/Collection.php @@ -0,0 +1,17 @@ + + * @package Beyonic + */ +class Collection extends Wrapper +{ + protected $endpoint = 'collections'; +} + diff --git a/beyonic/src/Collection/Contact.php b/beyonic/src/Collection/Contact.php new file mode 100755 index 0000000..c615ddd --- /dev/null +++ b/beyonic/src/Collection/Contact.php @@ -0,0 +1,16 @@ + + * @package Beyonic + */ +class Contact extends Wrapper +{ + protected $endpoint = 'contacts'; +} diff --git a/beyonic/src/Collection/Payment.php b/beyonic/src/Collection/Payment.php new file mode 100755 index 0000000..5f35a32 --- /dev/null +++ b/beyonic/src/Collection/Payment.php @@ -0,0 +1,15 @@ + + * @package Beyonic + */ +class Payment extends Wrapper +{ + protected $endpoint = 'payments'; +} diff --git a/beyonic/src/Collection/Request.php b/beyonic/src/Collection/Request.php new file mode 100755 index 0000000..3e1ebef --- /dev/null +++ b/beyonic/src/Collection/Request.php @@ -0,0 +1,16 @@ + + * @package Beyonic + */ +class Request extends Wrapper +{ + protected $endpoint = 'collectionrequests'; +} diff --git a/beyonic/src/Collection/Response.php b/beyonic/src/Collection/Response.php new file mode 100755 index 0000000..8f7f727 --- /dev/null +++ b/beyonic/src/Collection/Response.php @@ -0,0 +1,43 @@ + + * @package Beyonic + */ +class Response +{ + private $endpoint; + + /** + * @author Hamidouh Semix + * @param $jsonObject + * @param $endpoint + */ + public function __construct($jsonObject, $endpoint) + { + $this->endpoint = $endpoint; + foreach ($jsonObject as $prop => $value) + $this->$prop = $value; + } + + /** + * Return the Beyonic->sendRequest Object + * + * @author Hamidouh Semix + * @param null + * @return mixed + */ + + public function send() + { + $values = []; + foreach ($this as $prop => $value) + if ($prop != 'endpoint') + $values[$prop] = $value; + + return Beyonic::sendRequest($this->endpoint, 'PUT', $this->id, $values); + } +} \ No newline at end of file diff --git a/beyonic/src/Collection/Transaction.php b/beyonic/src/Collection/Transaction.php new file mode 100755 index 0000000..3994fb3 --- /dev/null +++ b/beyonic/src/Collection/Transaction.php @@ -0,0 +1,16 @@ + + * @package Beyonic + */ +class Transaction extends Wrapper +{ + protected $endpoint = 'transactions'; +} diff --git a/beyonic/src/Collection/WebHook.php b/beyonic/src/Collection/WebHook.php new file mode 100755 index 0000000..8943df0 --- /dev/null +++ b/beyonic/src/Collection/WebHook.php @@ -0,0 +1,16 @@ + + * @package Beyonic + */ +class WebHook extends Wrapper +{ + protected $endpoint = 'webhooks'; +} diff --git a/beyonic/src/Endpoint/Wrapper.php b/beyonic/src/Endpoint/Wrapper.php new file mode 100755 index 0000000..84a6523 --- /dev/null +++ b/beyonic/src/Endpoint/Wrapper.php @@ -0,0 +1,154 @@ + + * @package Beyonic + */ +class Wrapper +{ + protected static $beyonic; + protected $endpoint = null; + protected static $instances; + + /** + * @author Hamidouh Semix + * @param string|null $jsonObject + * @param Beyonic|null $beyonic + */ + public function __construct($jsonObject = null, Beyonic $beyonic = null) + { + static::$beyonic = $beyonic; + if ($jsonObject != null) + foreach ($jsonObject as $prop => $value) + $this->$prop = $value; + } + /** + * Return an Instance of the endpoint Object + * + * @author Hamidouh Semix + * @param null + * @return static + */ + final public static function instance() + { + $className = get_called_class(); + if (!isset(static::$instances[$className])) + static::$instances[$className] = new $className(null, Beyonic::getInstance()); + + return static::$instances[$className]; + } + + /** + * Send any changes made as a PATCH Request + * + * @author Hamidouh Semix + * @param null + * @return static + */ + public function send() + { + + $values = array(); + foreach( $this as $prop => $value ) + $values[$prop] = $value; + + return $this->update($this->id, $values); + } + + /** + * Get the associated object with $id + * + * @param int $id + * @param array|null $parameters + * + * @return static + */ + public function get($id, array $parameters = null) + { + return new static( + Beyonic::sendRequest(static::instance()->endpoint, 'GET', $id, $parameters), + static::getBeyonic() + ); + } + + + /** + * Get all of the associated object. Use $parameters (when available) to search for a subset + * + * @param array|null $parameters + */ + public function getAll(array $parameters = null) + { + $resp = Beyonic::sendRequest(static::instance()->endpoint, 'GET', null, $parameters); + $all = array(); + $all["count"] = $resp->count; + $all["next"] = $resp->next; + $all["previous"] = $resp->previous; + $all["results"] = array(); + foreach ($resp->results as $index => $json) + $all["results"][] = new static($json, static::getBeyonic()); + + return($all); + } + + /** + * Create the new object based on the $parameters + * + * @author Hamidouh Semix + * @param array $parameters + * @return static + */ + public function create($parameters) + { + return new static( + Beyonic::sendRequest(static::instance()->endpoint, 'POST', null, $parameters), + static::getBeyonic() + ); + } + + /** + * Return a static Beyonic object instance + * + * @author Hamidouh Semix + * @param null + * @return Beyonic $beyonic + */ + + public function getBeyonic() + { + return static::$beyonic; + } + + /** + * Update the object associated with $id using $parameters + * + * @author Hamidouh Semix + * @param int $id + * @param array $parameters + * @return static + */ + public function update($id, array $parameters) + { + return new static( + Beyonic::sendRequest(static::instance()->endpoint, 'PATCH', $id, $parameters), + static::getBeyonic() + ); + } + + /** + * Delete the object associated with $id + * + * @author Hamidouh Semix + * @param int $id + * @return static + */ + public function delete($id) + { + new static(Beyonic::sendRequest(static::instance()->endpoint, 'DELETE', $id)); + } +} \ No newline at end of file diff --git a/beyonic/src/Exceptions/BeyonicException.php b/beyonic/src/Exceptions/BeyonicException.php new file mode 100755 index 0000000..0577855 --- /dev/null +++ b/beyonic/src/Exceptions/BeyonicException.php @@ -0,0 +1,50 @@ +requestURL = $requestURL; + $this->responseBody = $responseBody; + $this->requestMethod = $requestMethod; + } + + /** + * Custom string representation of object + */ + public function __toString() + { + return __CLASS__ . " Error {$this->code}: {$this->message} when sending {$this->requestMethod} to {$this->requestURL}\n"; + } +} \ No newline at end of file diff --git a/beyonic/src/Exceptions/NotFoundException.php b/beyonic/src/Exceptions/NotFoundException.php new file mode 100755 index 0000000..ecec4bd --- /dev/null +++ b/beyonic/src/Exceptions/NotFoundException.php @@ -0,0 +1,10 @@ + Date: Mon, 29 Apr 2019 16:57:05 +0300 Subject: [PATCH 2/2] Added readme and composer.json files --- README.md | 143 +++++++++++++++++++++++++++++++++++++++++++++++++- composer.json | 10 +++- 2 files changed, 150 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b3890cb..e6d7dc4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,9 @@ To use the library, download the latest release and uncompress it in a location Once that's done, you can include the library in your scripts as follows: ```php -require('./lib/Beyonic.php'); +use Beyonic\Beyonic; + +require "vendor/autoload.php"; ``` ### Composer @@ -33,3 +35,142 @@ To install the library via [Composer](https://getcomposer.org/), add composer.js Please visit http://support.beyonic.com/api for usage documentation [![Latest Stable Version](https://poser.pugx.org/beyonic/beyonic-php/v/stable.svg)](https://packagist.org/packages/beyonic/beyonic-php) [![Latest Unstable Version](https://poser.pugx.org/beyonic/beyonic-php/v/unstable.svg)](https://packagist.org/packages/beyonic/beyonic-php) [![Total Downloads](https://poser.pugx.org/beyonic/beyonic-php/downloads.svg)](https://packagist.org/packages/beyonic/beyonic-php) [![License](https://poser.pugx.org/beyonic/beyonic-php/license.svg)](https://packagist.org/packages/beyonic/beyonic-php) + + +## **Examples for an instance object** + +```php + +use Beyonic\Beyonic; + +require "vendor/autoload.php"; + +/** + * Instance usage + */ +$beyonic = new Beyonic('840604c20904844jjdjfhdj8747673n43j33k93'); + +/** + * Make a Payment i.e access the \Beyonic\Collection\Payment object + * Through this one instance + */ + +$values = [ + "phonenumber" => '+256702455228', + "amount" => '500', + "currency" => "UGX", + "description" => 'Units Payment', + "metadata" => ['id' => '58475848kdd', 'appId' => 'Company Details Payment'], + "send_instructions" => true +]; +$beyonic->payment()->create($values); + +/** + * Make a Request i.e access the \Beyonic\Collection\Request object + * Through this one instance + */ + + $beyonic->request()->create($values); +/** + * Make a Response call i.e access the \Beyonic\Collection\Response object + * Through this one instance + */ + $beyonic->response()->getAll(); + /** + * Make a call to Accounts i.e access the \Beyonic\Collection\Account object + * Through this one instance + */ + $beyonic->account()->get(23343); + /** + * Make a call to Contacts i.e access the \Beyonic\Collection\Contact object + * Through this one instance + */ + $beyonic->contact()->getAll(); + /** + * Make a call to a Collection i.e access the \Beyonic\Collection\Collection object + * Through this one instance + */ + $beyonic->collection()->getAll(); + /** + * Make a Transaction i.e access the \Beyonic\Collection\Transaction object + * Through this one instance + */ + $beyonic->transaction()->getAll(); + /** + * Make a WebHook i.e access the \Beyonic\Collection\WebHook object + * Through this one instance + */ + $beyonic->webHook()->get(47737); + + ``` + + ## **Examples for a static object** + + ```php + + use Beyonic\Beyonic; + +require "vendor/autoload.php"; + +/** + * Some developers find it easy for them to be able + * to access api calls with static references of + * different classes if known. + * + * There is no problem with this since I just extended the functionality but still + * a single instance of new \Beyonic\Beyonic(key) or (new \Beyonic\Beyonic())->setApiKey(key) + * is needed. The rest are optional + * + * Let's see how it works + */ + +$beyonic = new Beyonic('840604c20904844jjdjfhdj8747673n43j33k93'); +$values = [ + "phonenumber" => '+256702455228', + "amount" => '500', + "currency" => "UGX", + "description" => 'Units Payment', + "metadata" => ['id' => '58475848kdd', 'appId' => 'Company Details Payment'], +]; +/** + * Make a Payment i.e access the \Beyonic\Collection\Payment object + * Through this one instance + */ +$payment = \Beyonic\Collection\Payment::create($values); + +/** + * Make a Request i.e access the \Beyonic\Collection\Request object + * Through this one instance + */ + + $request = \Beyonic\Collection\Request::create($values); +/** + * Make a Response call i.e access the \Beyonic\Collection\Response object + * Through this one instance + */ + $response = \Beyonic\Collection\Response::getAll(); + /** + * Make a call to Accounts i.e access the \Beyonic\Collection\Account object + * Through this one instance + */ + $account = \Beyonic\Collection\Account::get(23343); + /** + * Make a call to Contacts i.e access the \Beyonic\Collection\Contact object + * Through this one instance + */ + $contact = \Beyonic\Collection\Contact::getAll(); + /** + * Make a call to a Collection i.e access the \Beyonic\Collection\Collection object + * Through this one instance + */ + $collection = \Beyonic\Collection\Collection::getAll(); + /** + * Make a Transaction i.e access the \Beyonic\Collection\Transaction object + * Through this one instance + */ + $transaction = \Beyonic\Collection\Transaction::getAll(); + /** + * Make a WebHook i.e access the \Beyonic\Collection\WebHook object + * Through this one instance + */ + $webHook = \Beyonic\Collection\WebHook::get(47737); \ No newline at end of file diff --git a/composer.json b/composer.json index bc98be6..0b7c916 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,10 @@ { "name": "Beyonic", "homepage": "http://beyonic.com" + }, + { + "name": "Hamidouh Semix", + "email": "semix.hamidouh@gmail.com" } ], "require": { @@ -22,7 +26,9 @@ "ext-json": "*", "ext-mbstring": "*" }, - "autoload": { - "classmap": ["lib/Beyonic/"] + "autoload" :{ + "psr-4":{ + "Beyonic\\":"beyonic/src/" + } } }