diff --git a/composer.json b/composer.json index 0292916..89e5fc9 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=7.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", @@ -29,4 +29,4 @@ "PagarmeCoreApiLib\\": "src/" } } -} \ No newline at end of file +} diff --git a/src/Controllers/AccountsController.php b/src/Controllers/AccountsController.php new file mode 100644 index 0000000..5fd8009 --- /dev/null +++ b/src/Controllers/AccountsController.php @@ -0,0 +1,99 @@ + $accountId, + )); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'Accept' => 'application/json' + ); + + //set HTTP basic auth parameters + Request::auth(Configuration::$basicAuthUserName, Configuration::$basicAuthPassword); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + $mapper = $this->getJsonMapper(); + + return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetAccountResponse'); + } +} diff --git a/src/Controllers/BaseController.php b/src/Controllers/BaseController.php index f991e59..8ba137e 100644 --- a/src/Controllers/BaseController.php +++ b/src/Controllers/BaseController.php @@ -24,7 +24,7 @@ class BaseController * User-agent to be sent with API calls * @var string */ - const USER_AGENT = 'PagarmeCoreApi - PHP 5.7.0'; + const USER_AGENT = 'PagarmeCoreApi - PHP 5.6.3'; /** * HttpCallBack instance associated with this controller diff --git a/src/Models/GetAccountResponse.php b/src/Models/GetAccountResponse.php new file mode 100644 index 0000000..193b046 --- /dev/null +++ b/src/Models/GetAccountResponse.php @@ -0,0 +1,324 @@ +id = func_get_arg(0); + $this->secretKey = func_get_arg(1); + $this->publicKey = func_get_arg(2); + $this->name = func_get_arg(3); + $this->timeZone = func_get_arg(4); + $this->defaultCurrency = func_get_arg(5); + $this->status = func_get_arg(6); + $this->domains = func_get_arg(7); + $this->antifraudSettings = func_get_arg(8); + $this->mundipaggSettings = func_get_arg(9); + $this->pagarmeSettings = func_get_arg(10); + $this->creditCardSettings = func_get_arg(11); + $this->debitCardSettings = func_get_arg(12); + $this->voucherSettings = func_get_arg(13); + $this->boletoSettings = func_get_arg(14); + $this->bankTransferSettings = func_get_arg(15); + $this->walletSettings = func_get_arg(16); + $this->safetypaySettings = func_get_arg(17); + $this->facebookSettings = func_get_arg(18); + $this->generalSettings = func_get_arg(19); + $this->webhookSettings = func_get_arg(20); + $this->splitSettings = func_get_arg(21); + $this->subscriptionSettings = func_get_arg(22); + $this->orderSettings = func_get_arg(23); + $this->notificationSettings = func_get_arg(24); + $this->cancellationSettings = func_get_arg(25); + $this->renewCardSettings = func_get_arg(26); + $this->cashSettings = func_get_arg(27); + $this->checkoutSettings = func_get_arg(28); + $this->pixSettings = func_get_arg(29); + } + } + + /** + * Encode this object to JSON + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $json = array(); + $json['id'] = $this->id; + $json['secret_key'] = $this->secretKey; + $json['public_key'] = $this->publicKey; + $json['name'] = $this->name; + $json['time_zone'] = $this->timeZone; + $json['default_currency'] = $this->defaultCurrency; + $json['status'] = $this->status; + $json['domains'] = $this->domains ?? null; + $json['antifraud_settings'] = $this->antifraudSettings ?? null; + $json['mundipagg_settings'] = $this->mundipaggSettings ?? null; + $json['pagarme_settings'] = $this->pagarmeSettings ?? null; + $json['credit_card_settings'] = $this->creditCardSettings ?? null; + $json['debit_card_settings'] = $this->debitCardSettings ?? null; + $json['voucher_settings'] = $this->voucherSettings ?? null; + $json['boleto_settings'] = $this->boletoSettings ?? null; + $json['bank_transfer_settings'] = $this->bankTransferSettings ?? null; + $json['wallet_settings'] = $this->walletSettings ?? null; + $json['safetypay_settings'] = $this->safetypaySettings ?? null; + $json['facebook_settings'] = $this->facebookSettings ?? null; + $json['general_settings'] = $this->generalSettings ?? null; + $json['webhook_settings'] = $this->webhookSettings ?? null; + $json['split_settings'] = $this->splitSettings ?? null; + $json['subscription_settings'] = $this->subscriptionSettings ?? null; + $json['order_settings'] = $this->orderSettings ?? null; + $json['notification_settings'] = $this->notificationSettings ?? null; + $json['guaranteed_cancellation_settings'] = $this->cancellationSettings ?? null; + $json['renew_card_settings'] = $this->renewCardSettings ?? null; + $json['cash_Settings'] = $this->cashSettings ?? null; + $json['checkout_settings'] = $this->checkoutSettings ?? null; + $json['pix_settings'] = $this->pixSettings ?? null; + return $json; + } +} diff --git a/src/PagarmeCoreApiClient.php b/src/PagarmeCoreApiClient.php index e87f9f3..1778029 100644 --- a/src/PagarmeCoreApiClient.php +++ b/src/PagarmeCoreApiClient.php @@ -104,4 +104,12 @@ public function getTransactions() { return Controllers\TransactionsController::getInstance(); } + /** + * Singleton access to Transactions controller + * @return Controllers\AccountsController The *Singleton* instance + */ + public function getAccounts() + { + return Controllers\AccountsController::getInstance(); + } }