Skip to content

Commit

Permalink
Fix some bugs: namespace Execptions, change function http_build_query…
Browse files Browse the repository at this point in the history
… to json_encode. Added: function update from buyers
  • Loading branch information
tacio7brito committed Dec 30, 2020
1 parent 8a38760 commit ade939c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ Update your application configuration to register the package in `config/app.php
],
~~~

### 3 - Update ZOOP Laravel configuration
Rename config.example.php to config.php in `zoop/src/resources/config/` and change the following lines:
### 3 - Publish ZOOP Laravel configuration
Use the following command to publish the configuration settings from config.example.php in `zoop/src/resources/config/`:

~~~
php artisan vendor:publish --provider "Zoop\ZoopServiceProvider" --tag="config"
~~~

This will create the `config/zoopconfig.php` configuration file. Now, change the following lines:

~~~
'defaults' => [
Expand Down Expand Up @@ -128,9 +134,11 @@ class HomeController extends Controller{
'description' => 'Venda de teste, somente!',
'statement_descriptor' => 'Descrição de testes',
'on_behalf_of' => 'bb2a51f1c22a4c30b6bf6819be87ac52',
'installment_plan[mode]' => 'interest_free',
'installment_plan[number_installments]' => '1',
'customer' => 'bb2a51f1c22a4c30b6bf6819be87ac52', //buyer ud
'installment_plan' => [
'mode' => 'interest_free',
'number_installments' => '1'
],
'customer' => 'bb2a51f1c22a4c30b6bf6819be87ac52', //buyer id
]);

dd($cnp);
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/ZoopBuyers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function __construct(APIResource $APIResource);
*/
public function create($post);

/**
* Update a created Buyer
*
* @param $buyerID string
* @param $post array
*/
public function update($buyerID, $post);

/**
* Delete a Buyer by id
*
Expand All @@ -34,6 +42,13 @@ public function delete($buyerID);
*/
public function get($buyerID);

/**
* Retrieve the details of a Buyer by taxpayer_id
*
* @param $taxpayerID string
*/
public function getByTaxpayerId($taxpayerID);

/**
* Returns a JSON object with a list of buyers accounts.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ZoopSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(APIResource $APIResource);
*/
public function create($post);

/**
/**
* Update a created Subscription
*
* @param $subscriptionID string
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ZoopException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Zoop\src\Exceptions;
namespace Zoop\Exceptions;

class ZoopException extends \Exception {}
4 changes: 2 additions & 2 deletions src/Lib/APIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ private function requestWithCURL($method, $url, $headers, $data = Array()){

if (strtolower($method) == "post") {
$opts[CURLOPT_POST] = 1;
$opts[CURLOPT_POSTFIELDS] = http_build_query($data);
$opts[CURLOPT_POSTFIELDS] = json_encode($data);
}

if (strtolower($method) == "delete") $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';

if (strtolower($method) == "put") {
$opts[CURLOPT_CUSTOMREQUEST] = 'PUT';
$opts[CURLOPT_POSTFIELDS] = http_build_query($data);
$opts[CURLOPT_POSTFIELDS] = json_encode($data);
}

$opts[CURLOPT_URL] = $url;
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/APIResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function fileAPI($api, $files){

if(!is_file($files)) throw new ZoopException('Looks like this is not a file...');

if(!in_array(mime_content_type($files), $mimeTypes)) throw new ZoopException('You can only send files of types "jpg, png, pdf"!');
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()),
Expand Down
19 changes: 19 additions & 0 deletions src/Lib/ZoopBuyers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public function create($post = []){
return $this->APIResource->createAPI($api, $post);
}

/**
* @param string $buyerID
* @param array $post
* @return mixed
*/
public function update($buyerID, $post){
$api = 'buyers/' . $buyerID;
return $this->APIResource->updateAPI($api, $post);
}

/**
* @param string $buyerID
* @return mixed
Expand All @@ -47,6 +57,15 @@ public function get($buyerID){
return $this->APIResource->searchAPI($api);
}

/**
* @param string $taxpayerID
* @return mixed
*/
public function getByTaxpayerId($taxpayerID){
$api = 'buyers/search?taxpayer_id='.$taxpayerID;
return $this->APIResource->searchAPI($api);
}

/**
* @return mixed
*/
Expand Down

0 comments on commit ade939c

Please sign in to comment.