diff --git a/src/Contracts/ZoopBankAccounts.php b/src/Contracts/ZoopBankAccounts.php index 5db781a..bb1eb1d 100644 --- a/src/Contracts/ZoopBankAccounts.php +++ b/src/Contracts/ZoopBankAccounts.php @@ -13,6 +13,13 @@ interface ZoopBankAccounts{ */ public function __construct(APIResource $APIResource); + /** + * Create a new bank account token + * + * @param $post array + */ + public function create($post); + /** * Associate a bank account from a given token. * @@ -46,4 +53,11 @@ public function get($bankAccountID); * Returns a JSON object with a list of bank accounts. */ public function getAll(); + + /** + * Returns a JSON object with a list of bank accounts by seller. + * + * @param $sellerID string + */ + public function getAllBySeller($sellerID); } \ No newline at end of file diff --git a/src/Contracts/ZoopChargesCNP.php b/src/Contracts/ZoopChargesCNP.php index 1e68fc5..257ffea 100644 --- a/src/Contracts/ZoopChargesCNP.php +++ b/src/Contracts/ZoopChargesCNP.php @@ -48,4 +48,12 @@ public function get($transactionID); * @param $get array || null */ public function getAll($get = null); + + /** + * Returns a JSON object with a list of transactions by seller. + * + * @param $sellerID string + * @param $get array || null + */ + public function getAllBySeller($sellerID, $get = null); } \ No newline at end of file diff --git a/src/Contracts/ZoopSellers.php b/src/Contracts/ZoopSellers.php index 92a0e71..c58fb5c 100644 --- a/src/Contracts/ZoopSellers.php +++ b/src/Contracts/ZoopSellers.php @@ -20,6 +20,14 @@ public function __construct(APIResource $APIResource); */ public function createIndividuals($post); + /** + * Update a created Individual Seller + * + * @param $sellerID string + * @param $post array + */ + public function updateIndividuals($sellerID, $post); + /** * Create a new Business Seller * @@ -27,19 +35,41 @@ public function createIndividuals($post); */ public function createBusiness($post); + /** + * Update a created Business Seller + * + * @param $sellerID string + * @param $post array + */ + public function updateBusiness($sellerID, $post); + /** * Delete a Seller by id * - * @param $buyerID string + * @param $sellerID string */ - public function delete($buyerID); + public function delete($sellerID); /** * Retrieve the details of a Seller by id * - * @param $buyerID string + * @param $sellerID string */ - public function get($buyerID); + public function get($sellerID); + + /** + * Retrieve the details of a Seller by taxpayer_id + * + * @param $sellerTaxpayer_id string + */ + public function getByTaxpayer_id($sellerTaxpayer_id); + + /** + * Retrieve the details of a Seller by ein + * + * @param $sellerEin string + */ + public function getByEin($sellerEin); /** * Returns a JSON object with a list of Sellers. @@ -67,4 +97,21 @@ public function getDoc($docID); * @param $sellerID string */ public function getAllDocs($sellerID); + + /** + * Download doc file + * + * @param $docID string + */ + public function downloadDoc($docID); + + /** + * Returns a JSON object with a list of MCCs. + */ + public function getAllMccs(); + + /** + * Returns a JSON object with a current balance and total account balance + */ + public function getBalances($sellerID); } \ No newline at end of file diff --git a/src/Exceptions/ZoopAuthenticationException.php b/src/Exceptions/ZoopAuthenticationException.php index 70ba02f..212fd7e 100644 --- a/src/Exceptions/ZoopAuthenticationException.php +++ b/src/Exceptions/ZoopAuthenticationException.php @@ -1,5 +1,5 @@ zoopBase = $base; } @@ -37,7 +37,7 @@ public function __construct($base){ * * @return APIRequest */ - public static function getInstance($base){ + public static function getInstance($base) { if (is_null(self::$instance)) { self::$instance = new APIRequest($base); } @@ -57,7 +57,7 @@ public static function getInstance($base){ * @throws ZoopAuthenticationException * @throws ZoopObjectNotFound */ - public function request($method, $url, $headers, $data = []){ + public function request($method, $url, $headers, $data = []) { global $zoop_last_api_response_code; if ($this->zoopBase->getMarketplaceId() == null) { @@ -104,11 +104,11 @@ public function request($method, $url, $headers, $data = []){ * * @return array */ - private function requestWithCURL($method, $url, $headers, $data = Array()){ + private function requestWithCURL($method, $url, $headers, $data = Array()) { $curl = curl_init(); $opts = Array(); - if(strtolower($method) == 'file'){ + if(strtolower($method) == 'file') { $opts[CURLOPT_POST] = 1; $opts[CURLOPT_POSTFIELDS] = $data; } @@ -177,4 +177,4 @@ private function encodeParameters($method, $url, $data = []) { $data ]; } -} \ No newline at end of file +} diff --git a/src/Lib/APIResource.php b/src/Lib/APIResource.php index f98fcba..f4b950f 100644 --- a/src/Lib/APIResource.php +++ b/src/Lib/APIResource.php @@ -5,6 +5,7 @@ use Zoop\Exceptions\ZoopException; use Zoop\Helpers\ZoopHelpers; use Zoop\ZoopBase; +use Zoop\Exceptions\ZoopObjectNotFound; class APIResource{ @@ -41,7 +42,7 @@ class APIResource{ * * @param ZoopBase $zoopBase */ - protected function __construct(ZoopBase $zoopBase){ + protected function __construct(ZoopBase $zoopBase) { $this->zoopBase = $zoopBase; $this->APIRequest = APIRequest::getInstance($zoopBase); } @@ -53,7 +54,7 @@ protected function __construct(ZoopBase $zoopBase){ * * @return APIResource */ - public static function getSingleton(ZoopBase $zoopBase){ + public static function getSingleton(ZoopBase $zoopBase) { if (is_null(self::$instance)) { self::$instance = new APIResource($zoopBase); } @@ -70,7 +71,9 @@ public static function getSingleton(ZoopBase $zoopBase){ * * @throws ZoopException */ - public function fileAPI($api, $files){ + public function fileAPI($api, $files) { + $this->zoopBase->setApiVersionByResource($api); + if ($this->zoopBase->endpointIsBeta($api)) { $url = $this->zoopBase->getUrlBeta() . $this->zoopBase->getMarketplaceId() . '/' . $api; } else { @@ -83,7 +86,7 @@ public function fileAPI($api, $files){ ]; try { // - if(is_array($files)){ + if(is_array($files)) { throw new ZoopException('You can only upload one file per request! Array given...'); }else{ if(filesize($files) > 250000) throw new ZoopException('You can only send files with 250 kbytes of size.'); @@ -92,8 +95,8 @@ public function fileAPI($api, $files){ if(!in_array($files->getClientMimeType(), $mimeTypes)) throw new ZoopException('You can only send files of types "jpg, png, pdf"!'); - return $this->APIRequest->request('FILE', $url, $this->zoopBase->getHeaders(), [ - 'file' => new \CURLFile($files ,'' , uniqid()), + return $this->APIRequest->request('FILE', $url, $this->zoopBase->getHeadersFile(), [ + 'file' => new \CURLFile($files->getPathName(), $files->getClientMimeType(), $files->getClientOriginalName()), 'category' => 'identification' ]); } @@ -114,6 +117,8 @@ public function fileAPI($api, $files){ * @throws ZoopException */ public function createAPI($api, $attributes = []) { + $this->zoopBase->setApiVersionByResource($api); + if ($this->zoopBase->endpointIsBeta($api)) { $url = $this->zoopBase->getUrlBeta() . $this->zoopBase->getMarketplaceId() . '/' . $api; } else { @@ -136,7 +141,9 @@ public function createAPI($api, $attributes = []) { * * @throws ZoopException */ - public function searchAPI($api){ + public function searchAPI($api) { + $this->zoopBase->setApiVersionByResource($api); + if ($this->zoopBase->endpointIsBeta($api)) { $url = $this->zoopBase->getUrlBeta() . $this->zoopBase->getMarketplaceId() . '/' . $api; } else { @@ -145,6 +152,8 @@ public function searchAPI($api){ try { return $this->APIRequest->request('GET', $url, $this->zoopBase->getHeaders()); + } catch (ZoopObjectNotFound $e) { + return json_decode($e->getMessage()); } catch (ZoopException $e) { throw new ZoopException($e->getMessage()); } @@ -160,6 +169,8 @@ public function searchAPI($api){ * @throws ZoopException */ public function deleteAPI($api) { + $this->zoopBase->setApiVersionByResource($api); + if ($this->zoopBase->endpointIsBeta($api)) { $url = $this->zoopBase->getUrlBeta() . $this->zoopBase->getMarketplaceId() . '/' . $api; } else { @@ -183,7 +194,9 @@ public function deleteAPI($api) { * * @throws ZoopException */ - public function updateAPI($api, $attributes = []){ + public function updateAPI($api, $attributes = []) { + $this->zoopBase->setApiVersionByResource($api); + if ($this->zoopBase->endpointIsBeta($api)) { $url = $this->zoopBase->getUrlBeta() . $this->zoopBase->getMarketplaceId() . '/' . $api; } else { diff --git a/src/Lib/ZoopBankAccounts.php b/src/Lib/ZoopBankAccounts.php index 489b278..596a8d9 100644 --- a/src/Lib/ZoopBankAccounts.php +++ b/src/Lib/ZoopBankAccounts.php @@ -15,7 +15,7 @@ class ZoopBankAccounts implements \Zoop\Contracts\ZoopBankAccounts { * ZoopBankAccounts constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -23,7 +23,16 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function associateWithACustomer($post){ + public function create($post) { + $api = 'bank_accounts/tokens'; + return $this->APIResource->createAPI($api, $post); + } + + /** + * @param array $post + * @return mixed + */ + public function associateWithACustomer($post) { $api = 'bank_accounts'; return $this->APIResource->createAPI($api, $post); } @@ -33,7 +42,7 @@ public function associateWithACustomer($post){ * @param array $post * @return mixed */ - public function deactivate($bankAccountID, $post){ + public function deactivate($bankAccountID, $post) { $api = 'bank_accounts/' . $bankAccountID; return $this->APIResource->updateAPI($api, $post); } @@ -42,7 +51,7 @@ public function deactivate($bankAccountID, $post){ * @param string $bankAccountID * @return mixed */ - public function delete($bankAccountID){ + public function delete($bankAccountID) { $api = 'bank_accounts/' . $bankAccountID; return $this->APIResource->deleteAPI($api); } @@ -51,7 +60,7 @@ public function delete($bankAccountID){ * @param string $bankAccountID * @return mixed */ - public function get($bankAccountID){ + public function get($bankAccountID) { $api = 'bank_accounts/' . $bankAccountID; return $this->APIResource->searchAPI($api); } @@ -59,8 +68,17 @@ public function get($bankAccountID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'bank_accounts'; return $this->APIResource->searchAPI($api); } + + /** + * @param string $sellerID + * @return mixed + */ + public function getAllBySeller($sellerID) { + $api = 'sellers/' . $sellerID . '/bank_accounts'; + return $this->APIResource->searchAPI($api); + } } \ No newline at end of file diff --git a/src/Lib/ZoopBuyers.php b/src/Lib/ZoopBuyers.php index 8defac8..6f31591 100644 --- a/src/Lib/ZoopBuyers.php +++ b/src/Lib/ZoopBuyers.php @@ -16,7 +16,7 @@ class ZoopBuyers implements \Zoop\Contracts\ZoopBuyers { * ZoopBuyers constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'buyers'; return $this->APIResource->createAPI($api, $post); } @@ -34,7 +34,7 @@ public function create($post = []){ * @param array $post * @return mixed */ - public function update($buyerID, $post){ + public function update($buyerID, $post) { $api = 'buyers/' . $buyerID; return $this->APIResource->updateAPI($api, $post); } @@ -43,7 +43,7 @@ public function update($buyerID, $post){ * @param string $buyerID * @return mixed */ - public function delete($buyerID){ + public function delete($buyerID) { $api = 'buyers/' . $buyerID; return $this->APIResource->deleteAPI($api); } @@ -52,7 +52,7 @@ public function delete($buyerID){ * @param string $buyerID * @return mixed */ - public function get($buyerID){ + public function get($buyerID) { $api = 'buyers/' . $buyerID; return $this->APIResource->searchAPI($api); } @@ -61,7 +61,7 @@ public function get($buyerID){ * @param string $taxpayerID * @return mixed */ - public function getByTaxpayerId($taxpayerID){ + public function getByTaxpayerId($taxpayerID) { $api = 'buyers/search?taxpayer_id='.$taxpayerID; return $this->APIResource->searchAPI($api); } @@ -69,7 +69,7 @@ public function getByTaxpayerId($taxpayerID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'buyers'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopCards.php b/src/Lib/ZoopCards.php index 884980e..371ac23 100644 --- a/src/Lib/ZoopCards.php +++ b/src/Lib/ZoopCards.php @@ -15,7 +15,7 @@ class ZoopCards implements \Zoop\Contracts\ZoopCards { * ZoopCards constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -23,7 +23,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function associateWithACustomer($post){ + public function associateWithACustomer($post) { $api = 'cards'; return $this->APIResource->createAPI($api, $post); } @@ -33,7 +33,7 @@ public function associateWithACustomer($post){ * @param array $post * @return mixed */ - public function deactivate($creditCardID, $post){ + public function deactivate($creditCardID, $post) { $api = 'cards/' . $creditCardID; return $this->APIResource->updateAPI($api, $post); } @@ -42,7 +42,7 @@ public function deactivate($creditCardID, $post){ * @param string $creditCardID * @return mixed */ - public function delete($creditCardID){ + public function delete($creditCardID) { $api = 'cards/' . $creditCardID; return $this->APIResource->deleteAPI($api); } @@ -51,7 +51,7 @@ public function delete($creditCardID){ * @param string $creditCardID * @return mixed */ - public function get($creditCardID){ + public function get($creditCardID) { $api = 'cards/' . $creditCardID; return $this->APIResource->searchAPI($api); } @@ -59,7 +59,7 @@ public function get($creditCardID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'cards'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopChargesCNP.php b/src/Lib/ZoopChargesCNP.php index 573f7bc..715132e 100644 --- a/src/Lib/ZoopChargesCNP.php +++ b/src/Lib/ZoopChargesCNP.php @@ -15,7 +15,7 @@ class ZoopChargesCNP implements \Zoop\Contracts\ZoopChargesCNP { * ZoopChargesCNP constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -23,7 +23,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'transactions'; return $this->APIResource->createAPI($api, $post); } @@ -33,7 +33,7 @@ public function create($post = []){ * @param array $post * @return mixed */ - public function cancel($transactionID, $post){ + public function cancel($transactionID, $post) { $api = 'transactions/' . $transactionID . '/void'; return $this->APIResource->createAPI($api, $post); } @@ -43,7 +43,7 @@ public function cancel($transactionID, $post){ * @param array $post * @return mixed */ - public function capture($transactionID, $post){ + public function capture($transactionID, $post) { $api = 'transactions/' . $transactionID . '/capture'; return $this->APIResource->createAPI($api, $post); } @@ -52,7 +52,7 @@ public function capture($transactionID, $post){ * @param string $transactionID * @return mixed */ - public function get($transactionID){ + public function get($transactionID) { $api = 'transactions/' . $transactionID; return $this->APIResource->searchAPI($api); } @@ -61,12 +61,26 @@ public function get($transactionID){ * @param $get array || null * @return mixed */ - public function getAll($get = null){ - if(!is_null($get)){ + public function getAll($get = null) { + if(!is_null($get)) { $api = 'transactions?' . http_build_query($get); }else{ $api = 'transactions'; } return $this->APIResource->searchAPI($api); } + + /** + * @param string $sellerID + * @param $get array || null + * @return mixed + */ + public function getAllBySeller($sellerID, $get = null) { + if(!is_null($get)) { + $api = 'sellers/' . $sellerID . '/transactions?' . http_build_query($get); + }else{ + $api = 'sellers/' . $sellerID . '/transactions'; + } + return $this->APIResource->searchAPI($api); + } } \ No newline at end of file diff --git a/src/Lib/ZoopInvoices.php b/src/Lib/ZoopInvoices.php index 78deb01..6fb17ee 100644 --- a/src/Lib/ZoopInvoices.php +++ b/src/Lib/ZoopInvoices.php @@ -16,7 +16,7 @@ class ZoopInvoices implements \Zoop\Contracts\ZoopInvoices { * ZoopInvoices constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'invoices'; return $this->APIResource->createAPI($api, $post); } @@ -34,7 +34,7 @@ public function create($post = []){ * @param array $post * @return mixed */ - public function update($InvoiceID, $post){ + public function update($InvoiceID, $post) { $api = 'invoices/' . $InvoiceID; return $this->APIResource->updateAPI($api, $post); } @@ -44,7 +44,7 @@ public function update($InvoiceID, $post){ * @param array $post * @return mixed */ - public function approve($InvoiceID){ + public function approve($InvoiceID) { $api = 'invoices/' . $InvoiceID . '/approve'; return $this->APIResource->createAPI($api); } @@ -54,7 +54,7 @@ public function approve($InvoiceID){ * @param array $post * @return mixed */ - public function void($InvoiceID){ + public function void($InvoiceID) { $api = 'invoices/' . $InvoiceID . '/void'; return $this->APIResource->createAPI($api); } @@ -63,7 +63,7 @@ public function void($InvoiceID){ * @param string $InvoiceID * @return mixed */ - public function delete($InvoiceID){ + public function delete($InvoiceID) { $api = 'invoices/' . $InvoiceID; return $this->APIResource->deleteAPI($api); } @@ -72,7 +72,7 @@ public function delete($InvoiceID){ * @param string $InvoiceID * @return mixed */ - public function get($InvoiceID){ + public function get($InvoiceID) { $api = 'invoices/' . $InvoiceID; return $this->APIResource->searchAPI($api); } @@ -80,7 +80,7 @@ public function get($InvoiceID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'invoices'; return $this->APIResource->searchAPI($api); } @@ -88,7 +88,7 @@ public function getAll(){ /** * @return mixed */ - public function getAllBySeller($customerID){ + public function getAllBySeller($customerID) { $api = 'sellers/' . $customerID . '/invoices'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopPlans.php b/src/Lib/ZoopPlans.php index 989190f..c30a4de 100644 --- a/src/Lib/ZoopPlans.php +++ b/src/Lib/ZoopPlans.php @@ -16,7 +16,7 @@ class ZoopPlans implements \Zoop\Contracts\ZoopPlans { * ZoopPlans constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'plans'; return $this->APIResource->createAPI($api, $post); } @@ -34,7 +34,7 @@ public function create($post = []){ * @param array $post * @return mixed */ - public function update($planID, $post){ + public function update($planID, $post) { $api = 'plans/' . $planID; return $this->APIResource->updateAPI($api, $post); } @@ -43,7 +43,7 @@ public function update($planID, $post){ * @param string $planID * @return mixed */ - public function delete($planID){ + public function delete($planID) { $api = 'plans/' . $planID; return $this->APIResource->deleteAPI($api); } @@ -52,7 +52,7 @@ public function delete($planID){ * @param string $planID * @return mixed */ - public function get($planID){ + public function get($planID) { $api = 'plans/' . $planID; return $this->APIResource->searchAPI($api); } @@ -60,7 +60,7 @@ public function get($planID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'plans'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopSellers.php b/src/Lib/ZoopSellers.php index 11ae022..ee15a1d 100644 --- a/src/Lib/ZoopSellers.php +++ b/src/Lib/ZoopSellers.php @@ -15,7 +15,7 @@ class ZoopSellers implements \Zoop\Contracts\ZoopSellers { * ZoopSellers constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -23,21 +23,45 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function createIndividuals($post = []){ + public function createIndividuals($post = []) { $api = 'sellers/individuals'; return $this->APIResource->createAPI($api, $post); } - public function createBusiness($post){ + /** + * @param string $sellerID + * @param array $post + * @return mixed + */ + public function updateIndividuals($sellerID, $post) { + $api = 'sellers/individuals/' . $sellerID; + return $this->APIResource->updateAPI($api, $post); + } + + /** + * @param array $post + * @return mixed + */ + public function createBusiness($post) { $api = 'sellers/businesses'; return $this->APIResource->createAPI($api, $post); } /** * @param string $sellerID + * @param array $post * @return mixed */ - public function delete($sellerID){ + public function updateBusiness($sellerID, $post) { + $api = 'sellers/businesses/' . $sellerID; + return $this->APIResource->updateAPI($api, $post); + } + + /** + * @param string $sellerID + * @return mixed + */ + public function delete($sellerID) { $api = 'sellers/' . $sellerID; return $this->APIResource->deleteAPI($api); } @@ -46,48 +70,92 @@ public function delete($sellerID){ * @param string $sellerID * @return mixed */ - public function get($sellerID){ + public function get($sellerID) { $api = 'sellers/' . $sellerID; return $this->APIResource->searchAPI($api); } - + /** + * @param string $sellerTaxpayer_id * @return mixed */ - public function getAll(){ - $api = 'sellers'; + public function getByTaxpayer_id($sellerTaxpayer_id) { + $api = 'sellers/search?taxpayer_id=' . $sellerTaxpayer_id; return $this->APIResource->searchAPI($api); } + /** + * @param string $sellerEin + * @return mixed + */ + public function getByEin($sellerEin) { + $api = 'sellers/search?ein=' . $sellerEin; + return $this->APIResource->searchAPI($api); + } + /** + * @return mixed + */ + public function getAll() { + $api = 'sellers'; + return $this->APIResource->searchAPI($api); + } + /** * @param $sellerID string * @param $files array * * @return mixed */ - public function sendDocs($sellerID, $files){ + public function sendDocs($sellerID, $files) { $api = 'sellers/' . $sellerID . '/documents'; return $this->APIResource->fileAPI($api, $files); } - + /** * @param $docID string * * @return mixed */ - public function getDoc($docID){ + public function getDoc($docID) { $api = 'documents/' . $docID; return $this->APIResource->searchAPI($api); } - + /** * @param $sellerID string * * @return mixed - */ - public function getAllDocs($sellerID){ + */ + public function getAllDocs($sellerID) { $api = 'sellers/' . $sellerID . '/documents'; return $this->APIResource->searchAPI($api); } + + /** + * @param $docID string + * + * @return mixed + */ + public function downloadDoc($docID) { + $api = 'documents/' . $docID . '/file'; + return $this->APIResource->searchAPI($api); + } + + /** + * @return mixed + */ + public function getAllMccs() { + $api = 'merchant_category_codes'; + return $this->APIResource->searchAPI($api); + } + + /** + * @return mixed + */ + public function getBalances($sellerID) { + $api = 'sellers/' . $sellerID . '/balances'; + return $this->APIResource->searchAPI($api); + } + } \ No newline at end of file diff --git a/src/Lib/ZoopSplitTransactions.php b/src/Lib/ZoopSplitTransactions.php index 1426e28..73a153f 100644 --- a/src/Lib/ZoopSplitTransactions.php +++ b/src/Lib/ZoopSplitTransactions.php @@ -16,7 +16,7 @@ class ZoopSplitTransactions implements \Zoop\Contracts\ZoopSplitTransactions { * * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = ($APIResource); } @@ -25,7 +25,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($transactionID, $post){ + public function create($transactionID, $post) { $api = 'transactions/' . $transactionID . '/split_rules'; return $this->APIResource->createAPI($api, $post); } @@ -35,7 +35,7 @@ public function create($transactionID, $post){ * @param array $post * @return mixed */ - public function update($transactionID, $splitRuleID, $post){ + public function update($transactionID, $splitRuleID, $post) { $api = 'transactions/' . $transactionID . '/split_rules/' . $splitRuleID; return $this->APIResource->updateAPI($api, $post); } @@ -45,7 +45,7 @@ public function update($transactionID, $splitRuleID, $post){ * @param string $splitRuleID * @return mixed */ - public function delete($transactionID, $splitRuleID){ + public function delete($transactionID, $splitRuleID) { $api = 'transactions/' . $transactionID . '/split_rules/' . $splitRuleID; return $this->APIResource->deleteAPI($api); } @@ -54,7 +54,7 @@ public function delete($transactionID, $splitRuleID){ * @param string $transactionID * @return mixed */ - public function getAllSplitRules($transactionID){ + public function getAllSplitRules($transactionID) { $api = 'transactions/' . $transactionID . '/split_rules'; return $this->APIResource->searchAPI($api); } @@ -63,7 +63,7 @@ public function getAllSplitRules($transactionID){ * @param string $transactionID * @return mixed */ - public function getTransactionReceivables($transactionID){ + public function getTransactionReceivables($transactionID) { $api = 'transactions/' . $transactionID . '/receivables'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopSubscriptions.php b/src/Lib/ZoopSubscriptions.php index c127e8e..077f6dc 100644 --- a/src/Lib/ZoopSubscriptions.php +++ b/src/Lib/ZoopSubscriptions.php @@ -16,7 +16,7 @@ class ZoopSubscriptions implements \Zoop\Contracts\ZoopSubscriptions { * ZoopSubscriptions constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'subscriptions'; return $this->APIResource->createAPI($api, $post); } @@ -34,7 +34,7 @@ public function create($post = []){ * @param array $post * @return mixed */ - public function update($subscriptionID, $post){ + public function update($subscriptionID, $post) { $api = 'subscriptions/' . $subscriptionID; return $this->APIResource->updateAPI($api, $post); } @@ -44,7 +44,7 @@ public function update($subscriptionID, $post){ * @param array $post * @return mixed */ - public function suspend($subscriptionID){ + public function suspend($subscriptionID) { $api = 'subscriptions/' . $subscriptionID . '/suspend'; return $this->APIResource->createAPI($api); } @@ -54,7 +54,7 @@ public function suspend($subscriptionID){ * @param array $post * @return mixed */ - public function reactivate($subscriptionID){ + public function reactivate($subscriptionID) { $api = 'subscriptions/' . $subscriptionID . '/reactivate'; return $this->APIResource->createAPI($api); } @@ -63,7 +63,7 @@ public function reactivate($subscriptionID){ * @param string $subscriptionID * @return mixed */ - public function delete($subscriptionID){ + public function delete($subscriptionID) { $api = 'subscriptions/' . $subscriptionID; return $this->APIResource->deleteAPI($api); } @@ -72,7 +72,7 @@ public function delete($subscriptionID){ * @param string $subscriptionID * @return mixed */ - public function get($subscriptionID){ + public function get($subscriptionID) { $api = 'subscriptions/' . $subscriptionID; return $this->APIResource->searchAPI($api); } @@ -80,7 +80,7 @@ public function get($subscriptionID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'subscriptions'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopTokens.php b/src/Lib/ZoopTokens.php index f2aa6c8..020eba5 100644 --- a/src/Lib/ZoopTokens.php +++ b/src/Lib/ZoopTokens.php @@ -15,7 +15,7 @@ class ZoopTokens implements \Zoop\Contracts\ZoopTokens { * ZoopTokens constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -23,7 +23,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function tokenizeCard($post){ + public function tokenizeCard($post) { $api = 'cards/tokens'; return $this->APIResource->createAPI($api, $post); } @@ -32,7 +32,7 @@ public function tokenizeCard($post){ * @param array $post * @return mixed */ - public function tokenizeBankAccount($post){ + public function tokenizeBankAccount($post) { $api = 'bank_accounts/tokens'; return $this->APIResource->createAPI($api, $post); } @@ -40,7 +40,7 @@ public function tokenizeBankAccount($post){ /** * @param string $token */ - public function get($token){ + public function get($token) { $api = 'tokens/' . $token; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopTransfers.php b/src/Lib/ZoopTransfers.php index 2cd6cc0..a87ef26 100644 --- a/src/Lib/ZoopTransfers.php +++ b/src/Lib/ZoopTransfers.php @@ -15,7 +15,7 @@ class ZoopTransfers implements \Zoop\Contracts\ZoopTransfers { * ZoopTransfers constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($bankAccountID, $post = []){ + public function create($bankAccountID, $post = []) { $api = 'bankaccounts/' . $bankAccountID . '/transfers'; return $this->APIResource->createAPI($api, $post); } @@ -33,7 +33,7 @@ public function create($bankAccountID, $post = []){ * @param string $bankAccountID * @return mixed */ - public function get($bankAccountID){ + public function get($bankAccountID) { $api = 'bankaccounts/' . $bankAccountID; return $this->APIResource->searchAPI($api); } @@ -41,7 +41,7 @@ public function get($bankAccountID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'bankaccounts'; return $this->APIResource->searchAPI($api); } diff --git a/src/Lib/ZoopUtilities.php b/src/Lib/ZoopUtilities.php index edd5c71..d0b6144 100644 --- a/src/Lib/ZoopUtilities.php +++ b/src/Lib/ZoopUtilities.php @@ -11,7 +11,7 @@ class ZoopUtilities{ * * @return string */ - public static function utf8($value){ + public static function utf8($value) { return (is_string($value) && mb_detect_encoding($value, "UTF-8", true) != "UTF-8")?utf8_encode($value):$value; } @@ -22,7 +22,7 @@ public static function utf8($value){ * * @return false|int */ - public static function convertDateFromISO($datetime ){ + public static function convertDateFromISO($datetime ) { return strtotime($datetime); } @@ -33,7 +33,7 @@ public static function convertDateFromISO($datetime ){ * * @return false|string */ - public static function convertEpochToISO($epoch ){ + public static function convertEpochToISO($epoch ) { return date("c", $epoch); } @@ -45,7 +45,7 @@ public static function convertEpochToISO($epoch ){ * * @return string */ - public static function arrayToParams($array, $prefix = null){ + public static function arrayToParams($array, $prefix = null) { if (!is_array($array)) return $array; $params = Array(); diff --git a/src/Lib/ZoopWebhooks.php b/src/Lib/ZoopWebhooks.php index e05836d..166946c 100644 --- a/src/Lib/ZoopWebhooks.php +++ b/src/Lib/ZoopWebhooks.php @@ -16,7 +16,7 @@ class ZoopWebhooks implements \Zoop\Contracts\ZoopPlans { * ZoopPlans constructor. * @param APIResource $APIResource */ - public function __construct(APIResource $APIResource){ + public function __construct(APIResource $APIResource) { $this->APIResource = $APIResource; } @@ -24,7 +24,7 @@ public function __construct(APIResource $APIResource){ * @param array $post * @return mixed */ - public function create($post = []){ + public function create($post = []) { $api = 'webhooks'; return $this->APIResource->createAPI($api, $post); } @@ -33,7 +33,7 @@ public function create($post = []){ * @param string $webhookID * @return mixed */ - public function delete($webhookID){ + public function delete($webhookID) { $api = 'webhooks/' . $webhookID; return $this->APIResource->deleteAPI($api); } @@ -42,7 +42,7 @@ public function delete($webhookID){ * @param string $webhookID * @return mixed */ - public function get($webhookID){ + public function get($webhookID) { $api = 'webhooks/' . $webhookID; return $this->APIResource->searchAPI($api); } @@ -50,7 +50,7 @@ public function get($webhookID){ /** * @return mixed */ - public function getAll(){ + public function getAll() { $api = 'webhooks'; return $this->APIResource->searchAPI($api); } diff --git a/src/ZoopBase.php b/src/ZoopBase.php index be20c05..766ecf7 100644 --- a/src/ZoopBase.php +++ b/src/ZoopBase.php @@ -23,7 +23,7 @@ class ZoopBase { * * @param array $config */ - private function __construct(array $config = []){ + private function __construct(array $config = []) { $this->config = $config; } @@ -34,19 +34,32 @@ private function __construct(array $config = []){ * * @return ZoopBase */ - public static function getSingleton($config = []){ - if(is_null(self::$instance)){ + public static function getSingleton($config = []) { + if(is_null(self::$instance)) { self::$instance = new ZoopBase($config); } return self::$instance; } + /** + * Set Api Version By Resource + * + * @return void + */ + public function setApiVersionByResource($apiResource) { + [$resource] = explode('/', $apiResource); + + if (!empty($this->config['custom'][$resource])) { + $this->config['defaults']['api_version'] = $this->config['custom'][$resource]['api_version']; + } + } + /** * Get Publishable Key * * @return string */ - public function getPublishableKey(){ + public function getPublishableKey() { return $this->config['defaults']['publishable_key']; } @@ -55,7 +68,7 @@ public function getPublishableKey(){ * * @return string */ - public function getMarketplaceId(){ + public function getMarketplaceId() { return $this->config['defaults']['marketplace_id']; } @@ -64,7 +77,7 @@ public function getMarketplaceId(){ * * @return string */ - public function getUrl(){ + public function getUrl() { return $this->config['defaults']['endpoint'] . '/' . $this->config['defaults']['api_version'] . '/marketplaces/'; } @@ -73,7 +86,7 @@ public function getUrl(){ * * @return string */ - public function getUrlBeta(){ + public function getUrlBeta() { return $this->config['defaults']['endpoint_beta'] . '/' . $this->config['defaults']['api_version'] . '/marketplaces/'; } @@ -82,10 +95,30 @@ public function getUrlBeta(){ * * @return array */ - public function getHeaders(){ + public function getHeaders() { return $this->config['headers']; } + /** + * Get Curl Headers to upload files + * + * @return array + */ + public function getHeadersFile() { + $headers = $this->getHeaders(); + + $contentTypeDefault = 'Content-Type: application/json'; + $contentTypeFile = 'Content-Type: multipart/form-data'; + + if ($key = array_search($contentTypeDefault, $headers)) { + $headers[$key] = $contentTypeFile; + } else if (!$key = array_search($contentTypeFile, $headers)) { + $headers[] = $contentTypeFile; + } + + return $headers; + } + /** * return bool api is beta * diff --git a/src/ZoopServiceProvider.php b/src/ZoopServiceProvider.php index e15cd9d..e180ab2 100644 --- a/src/ZoopServiceProvider.php +++ b/src/ZoopServiceProvider.php @@ -23,7 +23,7 @@ class ZoopServiceProvider extends ServiceProvider { /** * @return void */ - public function boot(){ + public function boot() { $this->registerPublishing(); $this->mergeConfigFrom(__DIR__.'/resources/config/config.example.php', 'zoopconfig'); } @@ -31,7 +31,7 @@ public function boot(){ /** * @return void */ - public function register(){ + public function register() { $service = ZoopBase::getSingleton($this->app['config']->get('zoopconfig', [])); $this->app->singleton('ZoopBankAccounts', function () use ($service) { @@ -101,7 +101,7 @@ private function registerPublishing() /** * @return array */ - public function provides(){ + public function provides() { return [ ZoopBankAccounts::class, ZoopBuyers::class, diff --git a/src/resources/config/config.example.php b/src/resources/config/config.example.php index 8872f97..f32805f 100644 --- a/src/resources/config/config.example.php +++ b/src/resources/config/config.example.php @@ -13,5 +13,13 @@ 'endpoint_beta' => 'https://api-beta.zoop.ws', 'api_version' => 'v1', 'apis_use_beta' => ['tests', 'examples'], + ], + 'custom' => [ + 'plans' => [ + 'api_version' => 'v2' + ], + 'subscriptions' => [ + 'api_version' => 'v2' + ] ] ]; \ No newline at end of file