diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44dfa32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +vendor +composer.lock +mock.bat \ No newline at end of file diff --git a/NowPaymentsAPI.class.php b/NowPaymentsAPI.class.php deleted file mode 100644 index c61a028..0000000 --- a/NowPaymentsAPI.class.php +++ /dev/null @@ -1,154 +0,0 @@ -token = $token; - } - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - - $this->session = $ch; - } - - private function Call($method, $endpoint, $data = []) { - $ch = $this->session; - - switch ($method) { - case 'GET': - curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-API-KEY: '.$this->token]); - if(!empty($data)) { - if(is_array($data)) { - $parameters = http_build_query($data); - curl_setopt($ch, CURLOPT_URL, self::API_BASE.$endpoint.'?'.$parameters); - } else { - if($endpoint == 'payment') curl_setopt($ch, CURLOPT_URL, self::API_BASE.$endpoint.'/'.$data); - } - } else { - curl_setopt($ch, CURLOPT_URL, self::API_BASE.$endpoint); - } - break; - - case 'POST': - $data = json_encode($data); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-API-KEY: '.$this->token, 'Content-Type: application/json']); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - curl_setopt($ch, CURLOPT_URL, self::API_BASE.$endpoint); - break; - - default: - break; - } - - $response = curl_exec($ch); - - return $response; - } - - public function status() { - return $this->Call('GET', 'status'); - } - - public function getCurrencies() { - return $this->Call('GET', 'currencies'); - } - - /** - * @param array $params Array of options - * $params = [ - * 'amount' => (int|float) Required. - * 'currency_from' => (string) Required. - * 'currency_to' => (string) Required. - * ] - */ - public function getEstimatePrice(array $params) { - return $this->Call('GET', 'estimate', $params); - } - - /** - * @param array $params Array of options - * $params = [ - * 'price_amount' => (int|float) Required. The fiat equivalent of the price to be paid in crypto. - * 'price_currency' => (string) Required. The fiat currency in which the price_amount is specified (usd, eur, etc) - * 'pay_currency' => (string) Required. The crypto currency in which the pay_amount is specified (btc, eth, etc) - * 'pay_amount' => (int|float) Optional. The amount that users have to pay for the order stated in crypto - * 'ipn_callback_url' => (string) Optional. URL to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io" - * 'order_id' => (string) Optional. Inner store order ID, e.g. "RGDBP-21314" - * 'order_description' => (string) Optional. Inner store order description, e.g. "Apple Macbook Pro 2019 x 1" - * 'purchase_id' => (string) Optional. ID of purchase for which you want to create aother payment, only used for several payments for one order - * 'payout_address' => (string) Optional. Usually the funds will go to the address you specify in your Personal account - * 'payout_currency' => (string) Optional. Currency of your external payout_address, required when payout_adress is specified - * 'payout_extra_id' => (string) Optional. Extra ID or memo or tag for external payout_address - * 'fixed_rate' => (bool) Optional. Required for fixed-rate exchanges - * ] - */ - public function createPayment(array $params) { - return $this->Call('POST', 'payment', $params); - } - - /** - * @param int $paymentID Required. ID of created payment - */ - public function getPaymentStatus(int $paymentID) { - return $this->Call('GET', 'payment', $paymentID); - } - - /** - * @param array $params Array of options - * $params = [ - * 'currency_from' => (string) Required. - * 'currency_to' => (string) Required. - * ] - */ - public function getMinimumPaymentAmount(array $params) { - return $this->Call('GET', 'min-amount', $params); - } - - /** - * @param array $params Array of options, all values are optional - * $params = [ - * 'limit' => (int|string) number of records in one page. (possible values: from 1 to 500) - * 'page' => (int|string) the page number you want to get (possible values: from 0 to page count - 1) - * 'sortBy' => (string) sort the received list by a paramenter. Set to created_at by default (possible values: payment_id, payment_status, pay_address, price_amount, price_currency, pay_amount, actually_paid, pay_currency, order_id, order_description, purchase_id, outcome_amount, outcome_currency) - * 'orderBy' => (string) display the list in ascending or descending order. Set to asc by default (possible values: asc, desc) - * 'dateFrom' => (string) select the displayed period start date (date format: YYYY-MM-DD or yy-MM-ddTHH:mm:ss.SSSZ) - * 'dateTo' => (string) select the displayed period end date (date format: YYYY-MM-DD or yy-MM-ddTHH:mm:ss.SSSZ) - * ] - */ - public function getListPayments(array $params = []) { - return $this->Call('GET', 'payment', $params); - } - - /** - * @param array $params Array of options - * $params = [ - * 'price_amount' => (int|float) Required. The fiat equivalent of the price to be paid in crypto. - * 'price_currency' => (string) Required. The fiat currency in which the price_amount is specified (usd, eur, etc) - * 'pay_currency' => (string) Required. The crypto currency in which the pay_amount is specified (btc, eth, etc) - * 'ipn_callback_url' => (string) Optional. URL to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io" - * 'order_id' => (string) Optional. Inner store order ID, e.g. "RGDBP-21314" - * 'order_description' => (string) Optional. Inner store order description, e.g. "Apple Macbook Pro 2019 x 1" - * 'success_url' => (string) Optional. URL where the customer will be redirected after successful payment - * 'cancel_url' => (string) Optional. URL where the customer will be redirected after failed payment - * ] - */ - public function createInvoice(array $params) { - return $this->Call('POST', 'invoice', $params); - } - - function __destruct() { - curl_close($this->session); - } -} - - ?> \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b7db36 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ + + + +## Installation +This project using composer. +``` +$ composer require bearname/nowpayments-api-php +``` + +## Usage +Genrate random password. +```php +status(); +``` diff --git a/composer.json b/composer.json index f4e67e4..a708fdd 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,58 @@ { - "name": "nowpayments/nowpayments-api-php", - "type": "library", + "name": "bearname/nowpayments-api-php", + "description": "Nowpayments php api", + "homepage": "https://github.com/bearname/nowpayments-api-php", + "keywords": [ + "template", + "composer", + "package", + "skeleton", + "boilerplate", + "composer template", + "package template", + "composer package template" + ], "license": "MIT", - "homepage": "https://github.com/NowPaymentsIO/nowpayments-api-php", - "description": "PHP Library", "authors": [ { - "name": "bogdanaks", - "email": "bogdanaks@bk.ru" + "name": "Bearname", + "email": "ya.mikushoff@gmail.com", + "role": "Developer" } ], + "support": { + "source": "https://github.com/bearname/nowpayments-api-php", + "docs": "https://github.com/bearname/nowpayments-api-php/blob/master/README.md", + "issues": "https://github.com/bearname/nowpayments-api-php/issues" + }, + "type": "project", "require": { - "php": ">=7.2" + "php": "^7.4", + "symfony/http-client": "^4.4" }, "require-dev": { - "phpunit/phpunit": "~8.0" + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.0", + "phpmd/phpmd" : "^2.6", + "phpdocumentor/phpdocumentor" : "^2.0" + }, + "autoload": { + "psr-4": { + "NowPaymentsIO": "src/" + } + }, + "scripts": { + "test": [ + "@php vendor/bin/phpunit" + ], + "psr2check": [ + "@php vendor/bin/phpcs --standard=PSR2 src/" + ], + "psr2autofix": [ + "@php vendor/bin/phpcbf --standard=PSR2 src/" + ], + "docs": [ + "@php vendor/bin/phpdoc -d \"src\" -t \"docs\"" + ] } } diff --git a/example.php b/example.php new file mode 100644 index 0000000..44da2b8 --- /dev/null +++ b/example.php @@ -0,0 +1,28 @@ +setCancelUrl("https://cancel.url"); + $invoiceReturn = $yourClass->createInvoice($invoice); + var_dump($invoiceReturn); + var_dump($yourClass->status()); + var_dump($yourClass->getCurrencies()); + var_dump($yourClass->getListPayments()); + var_dump($yourClass->getListPayments(new GetListPayments())); + var_dump($yourClass->getEstimatePrice(new GetEstimatePrice('3999.5000', 'usd', 'btc'))); + var_dump($yourClass->createPayment(new CreatePayment(3999.5, Currency::BTC, Currency::ADA))); + var_dump($yourClass->getMinimumPaymentAmount(Currency::BTC, Currency::ADA)); +} catch (MyException $e) { + var_dump($e->getMessage()); +} \ No newline at end of file diff --git a/main.php b/main.php new file mode 100644 index 0000000..e1fb9f4 --- /dev/null +++ b/main.php @@ -0,0 +1,31 @@ +status()); +//var_dump($yourClass->getCurrencies()); + +try { + $invoice = new CreateInvoice(4.0234, Currency::BTC); + $invoice->setCancelUrl("https://cancel.url"); + $invoiceReturn = $yourClass->createInvoice($invoice); + var_dump($invoiceReturn); +// var_dump($yourClass->getListPayments()); +// var_dump($yourClass->createPayment(3999.5, Currency::BTC, Currency::ADA)); +// var_dump($yourClass->getMinimumPaymentAmount(Currency::BTC, Currency::ADA)); +} catch (MyException $e) { + var_dump($e->getMessage()); +} + +//var_dump(validateDate("2020-01-01")); +//var_dump(validateDate("20-01-01T12:02:40.", "yy-MM-ddTHH:mm:ss.SSSZ")); + + +//var_dump($yourClass->getEstimatePrice('3999.5000', 'usd', 'btc')); \ No newline at end of file diff --git a/src/Currency.php b/src/Currency.php new file mode 100644 index 0000000..4633a4b --- /dev/null +++ b/src/Currency.php @@ -0,0 +1,64 @@ +code}]: {$this->message}\n"; + } +} \ No newline at end of file diff --git a/src/NOWPaymentsApi.php b/src/NOWPaymentsApi.php new file mode 100644 index 0000000..2089a29 --- /dev/null +++ b/src/NOWPaymentsApi.php @@ -0,0 +1,584 @@ +apiKey = $apiKey; + $this->url = 'https://api.nowpayments.io/v1'; + // $this->url = 'http://localhost:3000/v1'; + } + + /** + * @return StatusReturn + * @throws MyException + */ + public function status(): StatusReturn + { + $httpClient = HttpClient::create(); + try { + $response = $httpClient->request('GET', $this->url . '/status'); + $content = $response->getContent(); + $decode = json_decode($content, true); + + if ($this->checkExistKey($decode, "message")) { + throw new MyException("response json don't have message field"); + } + return new StatusReturn($decode["message"]); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * @return array + * @throws MyException + */ + public function getCurrencies(): array + { + try { + $httpClient = HttpClient::create(); + + $options = [ + 'headers' => ['x-api-key' => $this->apiKey], + ]; + + $response = $httpClient->request('GET', $this->url . '/currencies', $options); + $content = $response->getContent(); + $decode = json_decode($content, true); + + if ($this->checkExistKey($decode, "currencies")) { + throw new MyException("response json don't have currencies field"); + } + + return $decode["currencies"]; + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * @param GetEstimatePrice $getEstimatePrice + * @return EstimatedPriceReturn + * @throws MyException + */ + public function getEstimatePrice(GetEstimatePrice $getEstimatePrice): EstimatedPriceReturn + { + try { + $httpClient = HttpClient::create(); + + $response = $httpClient->request('GET', $this->url . '/estimate', [ + 'headers' => ['x-api-key' => $this->apiKey], + 'query' => [ + "amount" => $getEstimatePrice->getAmount(), + "currency_from" => $getEstimatePrice->getCurrencyFrom(), + "currency_to" => $getEstimatePrice->getCurrencyTo(), + ] + ]); + + $content = $response->getContent(); + $decode = json_decode($content, true); + + if ($this->checkExistKey($decode, "currency_from")) { + throw new MyException("response json don't have currency_from field"); + } + if ($this->checkExistKey($decode, "amount_from")) { + throw new MyException("response json don't have amount_from field"); + } + if ($this->checkExistKey($decode, "currency_to")) { + throw new MyException("response json don't have currency_to field"); + } + if ($this->checkExistKey($decode, "estimated_amount")) { + throw new MyException("response json don't have estimated_amount field"); + } + + return new EstimatedPriceReturn($decode["currency_from"], $decode["amount_from"], $decode["currency_to"], $decode["estimated_amount"]); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * * This is the method to create a payment. You need to provide your data as a JSON-object payload. Next is a description of the required request fields: + * price_amount (required) - the fiat equivalent of the price to be paid in crypto. If the pay_amount parameter is left empty, our system will automatically convert this fiat price into its crypto equivalent. Please note that this does not enable fiat payments, only provides a fiat price for yours and the customer’s convenience and information. + * price_currency (required) - the fiat currency in which the price_amount is specified (usd, eur, etc). + * pay_amount (optional) - the amount that users have to pay for the order stated in crypto. You can either specify it yourself, or we will automatically convert the amount you indicated in price_amount. + * pay_currency (required) - the crypto currency in which the pay_amount is specified (btc, eth, etc). + * ipn_callback_url (optional) - url to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io" + * order_id (optional) - inner store order ID, e.g. "RGDBP-21314" + * order_description (optional) - inner store order description, e.g. "Apple Macbook Pro 2019 x 1" + * purchase_id (optional) - id of purchase for which you want to create aother payment, only used for several payments for one order + * payout_address (optional) - usually the funds will go to the address you specify in your Personal account. In case you want to receive funds on another address, you can specify it in this parameter. + * payout_currency (optional) - currency of your external payout_address, required when payout_adress is specified. + * payout_extra_id(optional) - extra id or memo or tag for external payout_address. + * fixed_rate(optional) - boolean, can be true or false. Required for fixed-rate exchanges. + * @param CreatePayment $createPayment + * @return CreatePaymentReturn + * @throws MyException + */ + public function createPayment(CreatePayment $createPayment): CreatePaymentReturn + { + try { + $httpClient = HttpClient::create(); + + if (strlen($createPayment->getPayoutAddress()) !== 0 && strlen($createPayment->getPayoutCurrency()) === 0) { + throw new MyException("currency of your external payout_address, required when payout_adress is specified."); + } + + $data['price_amount'] = $createPayment->getPriceAmount(); + $data['price_currency'] = $createPayment->getPriceCurrency(); + if ($createPayment->getPayAmount() !== -1) { + $data['pay_amount'] = $createPayment->getPayAmount(); + } + + $data['pay_currency'] = $createPayment->getPayCurrency(); + if ($createPayment->isSetPayoutCurrency()) { + $data['ipn_callback_url'] = $createPayment->getIpnCallbackUrl(); + } + if ($createPayment->isSetOrderId()) { + $data['order_id'] = $createPayment->getOrderId(); + } + if ($createPayment->isSetOrderDescription()) { + $data['order_description'] = $createPayment->getOrderDescription(); + } + if ($createPayment->isSetPurchaseId()) { + $data['purchase_id'] = $createPayment->getPurchaseId(); + } + if ($createPayment->isSetPayoutAddress()) { + $data['payout_address'] = $createPayment->getPayoutAddress(); + } + if ($createPayment->isSetPayCurrency()) { + $data['payout_currency'] = $createPayment->getPayCurrency(); + } + if ($createPayment->isSetPayoutExtraId()) { + $data['payout_extra_id'] = $createPayment->getPayoutExtraId(); + } + if ($createPayment->isSetFixedRate()) { + $data['fixed_rate'] = $createPayment->getFixedRate(); + } + + $response = $httpClient->request('POST', $this->url . '/payment', [ + 'headers' => [ + 'Content-Type' => 'application/json', + 'x-api-key' => $this->apiKey + ], + 'body' => json_encode($data) + ]); + + $content = $response->getContent(); + $decode = json_decode($content, true); + + return $this->buildPaymentReturn($decode); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * @param $paymentId + * @return PaymentStatusReturn + * @throws MyException + */ + public function getPaymentStatus($paymentId): PaymentStatusReturn + { + try { + $httpClient = HttpClient::create(); + + $response = $httpClient->request('GET', $this->url . '/payment/' . $paymentId, [ + 'headers' => ['x-api-key' => $this->apiKey], + ]); + + $content = $response->getContent(); + $decode = json_decode($content, true); + if ($this->checkExistKey($decode, "payment_id")) { + throw new MyException("response json don't have payment_id field"); + } + if ($this->checkExistKey($decode, "payment_status")) { + throw new MyException("response json don't have payment_status field"); + } + if ($this->checkExistKey($decode, "pay_address")) { + throw new MyException("response json don't have pay_address field"); + } + if ($this->checkExistKey($decode, "price_amount")) { + throw new MyException("response json don't have price_amount field"); + } + if ($this->checkExistKey($decode, "price_currency")) { + throw new MyException("response json don't have price_currency field"); + } + if ($this->checkExistKey($decode, "pay_amount")) { + throw new MyException("response json don't have pay_amount field"); + } + if ($this->checkExistKey($decode, "actually_paid")) { + throw new MyException("response json don't have actually_paid field"); + } + if ($this->checkExistKey($decode, "pay_currency")) { + throw new MyException("response json don't have pay_currency field"); + } + if ($this->checkExistKey($decode, "order_id")) { + throw new MyException("response json don't have order_id field"); + } + if ($this->checkExistKey($decode, "order_description")) { + throw new MyException("response json don't have order_description field"); + } + if ($this->checkExistKey($decode, "purchase_id")) { + throw new MyException("response json don't have purchase_id field"); + } + if ($this->checkExistKey($decode, "created_at")) { + throw new MyException("response json don't have created_at field"); + } + if ($this->checkExistKey($decode, "updated_at")) { + throw new MyException("response json don't have updated_at field"); + } + if ($this->checkExistKey($decode, "outcome_amount")) { + throw new MyException("response json don't have outcome_currency field"); + } + + return new PaymentStatusReturn( + $decode["payment_id"], $decode["payment_status"], $decode["pay_address"], $decode["price_amount"], + $decode["price_currency"], $decode["pay_amount"], $decode["actually_paid"], $decode["pay_currency"], + $decode["order_id"], $decode["order_description"], $decode["purchase_id"], $decode["created_at"], $decode["updated_at"], + $decode["outcome_amount"], $decode["outcome_currency"]); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * Get the minimum payment amount for a specific pair. + * You can provide both currencies in the pair or just currency_from, and we will calculate the minimum payment amount for currency_from and currency which you have specified as the outcome in the Store Settings. + * In the case of several outcome wallets we will calculate the minimum amount in the same way we route your payment to a specific wallet. + * @param $currency_from + * @param $currency_to + * @return MinimumPaymentAmountResponse + * @throws MyException + */ + public function getMinimumPaymentAmount($currency_from, $currency_to): MinimumPaymentAmountResponse + { + try { + $httpClient = HttpClient::create(); + + $response = $httpClient->request('GET', $this->url . '/min-amount', [ + 'headers' => ['x-api-key' => $this->apiKey], + 'query' => [ + "currency_from" => $currency_from, + "currency_to" => $currency_to + ] + ]); + + $content = $response->getContent(); + $result = json_decode($content, true); + var_dump($result); + + if ($this->checkExistKey($result, "currency_from")) { + throw new MyException("response json don't have currency_from field"); + } + + if ($this->checkExistKey($result, "currency_to")) { + throw new MyException("response json don't have currency_to field"); + } + + if ($this->checkExistKey($result, "min_amount")) { + throw new MyException("response json don't have min_amount field"); + } + + return new MinimumPaymentAmountResponse($result["currency_from"], $result["currency_to"], $result["min_amount"]); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * Get the minimum payment amount for a specific pair. + * You can provide both currencies in the pair or just currency_from, and we will calculate the minimum payment amount for currency_from and currency which you have specified as the outcome in the Store Settings. + * In the case of several outcome wallets we will calculate the minimum amount in the same way we route your payment to a specific wallet. + * @param GetListPayments|null $getListPayments + * @return GetListPaymentsReturn + * @throws MyException + */ + public function getListPayments(GetListPayments $getListPayments = null): GetListPaymentsReturn + { + try { + $httpClient = HttpClient::create(); + + $query = []; + if ($getListPayments !== null) { + $limit = $getListPayments->getLimit(); + if ($getListPayments->isSetLimit()) { + $query['limit'] = $limit; + } + + $page = $getListPayments->getPage(); + if ($getListPayments->isSetPage()) { + $query['page'] = $page; + } + + $sortBy = $getListPayments->getSortBy(); + if ($getListPayments->isSetSortBy()) { + $query['sortBy'] = $sortBy; + } + + $orderBy = $getListPayments->getOrderBy(); + if ($getListPayments->isSetOrderBy()) { + $query['orderBy'] = $orderBy; + } + + $dateFrom = $getListPayments->getDateFrom(); + if ($getListPayments->isSetDateFrom()) { + $query['dateFrom'] = $dateFrom; + } + + $dateTo = $getListPayments->getDateTo(); + if ($getListPayments->isSetDateTo()) { + $query['dateTo'] = $dateTo; + } + } + + $response = $httpClient->request('GET', $this->url . '/payment', [ + 'headers' => ['x-api-key' => $this->apiKey], + 'query' => $query + ]); + + $content = $response->getContent(); + $result = json_decode($content, true); + if ($this->checkExistKey($result, "data")) { + throw new MyException("response json don't have date field"); + } + if ($this->checkExistKey($result, "limit")) { + throw new MyException("response json don't have limit field"); + } + if ($this->checkExistKey($result, "page")) { + throw new MyException("response json don't have page field"); + } + if ($this->checkExistKey($result, "pagesCount")) { + throw new MyException("response json don't have pagesCount field"); + } + if ($this->checkExistKey($result, "total")) { + throw new MyException("response json don't have total field"); + } + + $getListPaymentsReturn = new GetListPaymentsReturn($result["limit"], $result["page"], $result["pagesCount"], $result["total"]); + + foreach ($result["data"] as $invoice) { + + $invoice1 = new ListPaymentItem($invoice["payment_id"], + $invoice["payment_status"], + $invoice["pay_address"], + $invoice["price_amount"], + $invoice["price_currency"], + $invoice["pay_amount"], + $invoice["actually_paid"], + $invoice["pay_currency"], + $invoice["order_id"], + $invoice["order_description"]); + + if ($this->checkExistKey($invoice, "purchase_id")) { + $invoice1->setPurchaseId($invoice["purchase_id"]); + } + if ($this->checkExistKey($invoice, "outcome_amount")) { + $invoice1->setOutcomeAmount($invoice["outcome_amount"]); + } + if ($this->checkExistKey($invoice, "outcome_currency")) { + $invoice1->setOutcomeCurrency($invoice["outcome_amount"]); + } + + $getListPaymentsReturn->pushInvoice($invoice1); + } + + return $getListPaymentsReturn; + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } + } + + /** + * Creates invoice with url where you can complete the payment. Request fields: + * + * price_amount (required) - the amount that users have to pay for the order stated in fiat currency. In case you do not indicate the price in crypto, our system will automatically convert this fiat amount into its crypto equivalent. + * price_currency (required) - the fiat currency in which the price_amount is specified (usd, eur, etc). + * pay_currency (optional) - the crypto currency in which the pay_amount is specified (btc, eth, etc).If not specified, can be chosen on the invoice_url + * ipn_callback_url (optional) - url to receive callbacks, should contain "http" or "https", eg. "https://nowpayments.io" + * order_id (optional) - inner store order ID, e.g. "RGDBP-21314" + * order_description (optional) - inner store order description, e.g. "Apple Macbook Pro 2019 x 1" + * success_url(optional) - url where the customer will be redirected after successful payment. + * cancel_url(optional) - url where the customer will be redirected after failed payment. + * + * @param CreateInvoice $invoice + * @return InvoiceReturn + * @throws MyException + */ + public function createInvoice(CreateInvoice $invoice): InvoiceReturn + { + try { + $httpClient = HttpClient::create(); + + $data = [ + "price_amount" => $invoice->getPriceAmount(), + "price_currency" => $invoice->getPriceCurrency(), + ]; + if ($invoice->isSetPayCurrency()) { + $data["pay_currency"] = $invoice->getPayCurrency(); + } + if ($invoice->isSetIpnCallbackUrl()) { + $data["ipn_callback_url"] = $invoice->getIpnCallbackUrl(); + } + if ($invoice->isSetOrderId()) { + $data["order_id"] = $invoice->getOrderId(); + } + if ($invoice->isSetOrderDescription()) { + $data["order_description "] = $invoice->getOrderDescription(); + } + if ($invoice->isSetSuccessUrl()) { + $data["success_url"] = $invoice->getSuccessUrl(); + } + if ($invoice->isSetCancelUrl()) { + $data["cancel_url"] = $invoice->getCancelUrl(); + } + + $response = $httpClient->request('POST', $this->url . '/invoice', [ + 'headers' => [ + 'Content-Type' => 'application/json', + 'x-api-key' => $this->apiKey + ], + 'body' => json_encode($data) + ]); + + $content = $response->getContent(); + + $invoice = json_decode($content, true); + + if (!$this->checkExistKey($invoice, "id") || !$this->checkExistKey($invoice, "order_id") || + !$this->checkExistKey($invoice, "order_description") || !$this->checkExistKey($invoice, "price_amount") || + !$this->checkExistKey($invoice, "price_currency") || !$this->checkExistKey($invoice, "pay_currency") || + !$this->checkExistKey($invoice, "ipn_callback_url") || !$this->checkExistKey($invoice, "invoice_url") || + !$this->checkExistKey($invoice, "success_url") || !$this->checkExistKey($invoice, "cancel_url") || + !$this->checkExistKey($invoice, "created_at") || !$this->checkExistKey($invoice, "updated_at")) { + throw new MyException("Invalid response"); + } + + return new InvoiceReturn($invoice["id"], $invoice["order_id"], $invoice["order_description"], $invoice["price_amount"], + $invoice["price_currency"], $invoice["pay_currency"], $invoice["ipn_callback_url"], $invoice["invoice_url"], + $invoice["success_url"], $invoice["cancel_url"], $invoice["created_at"], $invoice["updated_at"]); + } catch (ExceptionInterface $e) { + throw new MyException($e->getMessage()); + } catch (MyException $exception) { + throw new MyException($exception->getMessage()); + } + } + + /** + * @param $array + * @param $key + * @return bool + */ + public function checkExistKey($array, $key): bool + { + return array_key_exists($key, $array); + } + + /** + * @param $date + * @param string $format + * @return bool + */ + private function validateDate($date, $format = ' YYYY-MM-DD'): bool + { + $d = DateTime::createFromFormat($format, $date); + return $d && $d->format($format) == $date; + } + + /** + * @param $decode + * @return CreatePaymentReturn + * @throws MyException + */ + private function buildPaymentReturn($decode): CreatePaymentReturn + { + if ($this->checkExistKey($decode, "payment_id")) { + throw new MyException("response json don't have payment_id field"); + } + if ($this->checkExistKey($decode, "payment_status")) { + throw new MyException("response json don't have payment_status field"); + } + if ($this->checkExistKey($decode, "pay_address")) { + throw new MyException("response json don't have pay_address field"); + } + if ($this->checkExistKey($decode, "price_amount")) { + throw new MyException("response json don't have price_amount field"); + } + if ($this->checkExistKey($decode, "price_currency")) { + throw new MyException("response json don't have price_currency field"); + } + if ($this->checkExistKey($decode, "pay_amount")) { + throw new MyException("response json don't have pay_amount field"); + } + if ($this->checkExistKey($decode, "pay_currency")) { + throw new MyException("response json don't have pay_currency field"); + } + if ($this->checkExistKey($decode, "order_id")) { + throw new MyException("response json don't have order_id field"); + } + if ($this->checkExistKey($decode, "order_description")) { + throw new MyException("response json don't have order_description field"); + } + if ($this->checkExistKey($decode, "ipn_callback_url")) { + throw new MyException("response json don't have ipn_callback_url field"); + } + if ($this->checkExistKey($decode, "created_at")) { + throw new MyException("response json don't have created_at field"); + } + if ($this->checkExistKey($decode, "purchase_id")) { + throw new MyException("response json don't have purchase_id field"); + } + + return new CreatePaymentReturn( + $decode["payment_id"], $decode["payment_status"], $decode["pay_address"], $decode["price_amount"], + $decode["price_currency"], $decode["pay_amount"], $decode["pay_currency"], $decode["order_id"], + $decode["order_description"], $decode["ipn_callback_url"], $decode["created_at"], $decode["updated_at"], + $decode["purchase_id"]); + } +} diff --git a/src/PaymentStatus.php b/src/PaymentStatus.php new file mode 100644 index 0000000..ab56f78 --- /dev/null +++ b/src/PaymentStatus.php @@ -0,0 +1,51 @@ +payment_id = $payment_id; + $this->payment_status = $payment_status; + $this->pay_address = $pay_address; + $this->price_amount = $price_amount; + $this->price_currency = $price_currency; + $this->pay_amount = $pay_amount; + $this->pay_currency = $pay_currency; + $this->order_id = $order_id; + $this->order_description = $order_description; + $this->ipn_callback_url = $ipn_callback_url; + $this->created_at = $created_at; + $this->updated_at = $updated_at; + $this->purchase_id = $purchase_id; + } + + /** + * @return mixed + */ + public function getPaymentId() + { + return $this->payment_id; + } + + /** + * @param mixed $payment_id + */ + public function setPaymentId($payment_id): void + { + $this->payment_id = $payment_id; + } + + /** + * @return mixed + */ + public function getPaymentStatus() + { + return $this->payment_status; + } + + /** + * @param mixed $payment_status + */ + public function setPaymentStatus($payment_status): void + { + $this->payment_status = $payment_status; + } + + /** + * @return mixed + */ + public function getPayAddress() + { + return $this->pay_address; + } + + /** + * @param mixed $pay_address + */ + public function setPayAddress($pay_address): void + { + $this->pay_address = $pay_address; + } + + /** + * @return mixed + */ + public function getPriceAmount() + { + return $this->price_amount; + } + + /** + * @param mixed $price_amount + */ + public function setPriceAmount($price_amount): void + { + $this->price_amount = $price_amount; + } + + /** + * @return mixed + */ + public function getPriceCurrency() + { + return $this->price_currency; + } + + /** + * @param mixed $price_currency + */ + public function setPriceCurrency($price_currency): void + { + $this->price_currency = $price_currency; + } + + /** + * @return mixed + */ + public function getPayAmount() + { + return $this->pay_amount; + } + + /** + * @param mixed $pay_amount + */ + public function setPayAmount($pay_amount): void + { + $this->pay_amount = $pay_amount; + } + + /** + * @return mixed + */ + public function getPayCurrency() + { + return $this->pay_currency; + } + + /** + * @param mixed $pay_currency + */ + public function setPayCurrency($pay_currency): void + { + $this->pay_currency = $pay_currency; + } + + /** + * @return mixed + */ + public function getOrderId() + { + return $this->order_id; + } + + /** + * @param mixed $order_id + */ + public function setOrderId($order_id): void + { + $this->order_id = $order_id; + } + + /** + * @return mixed + */ + public function getOrderDescription() + { + return $this->order_description; + } + + /** + * @param mixed $order_description + */ + public function setOrderDescription($order_description): void + { + $this->order_description = $order_description; + } + + /** + * @return mixed + */ + public function getIpnCallbackUrl() + { + return $this->ipn_callback_url; + } + + /** + * @param mixed $ipn_callback_url + */ + public function setIpnCallbackUrl($ipn_callback_url): void + { + $this->ipn_callback_url = $ipn_callback_url; + } + + /** + * @return mixed + */ + public function getCreatedAt() + { + return $this->created_at; + } + + /** + * @param mixed $created_at + */ + public function setCreatedAt($created_at): void + { + $this->created_at = $created_at; + } + + /** + * @return mixed + */ + public function getUpdatedAt() + { + return $this->updated_at; + } + + /** + * @param mixed $updated_at + */ + public function setUpdatedAt($updated_at): void + { + $this->updated_at = $updated_at; + } + + /** + * @return mixed + */ + public function getPurchaseId() + { + return $this->purchase_id; + } + + /** + * @param mixed $purchase_id + */ + public function setPurchaseId($purchase_id): void + { + $this->purchase_id = $purchase_id; + } +} \ No newline at end of file diff --git a/src/response/EstimatedPriceReturn.php b/src/response/EstimatedPriceReturn.php new file mode 100644 index 0000000..c030528 --- /dev/null +++ b/src/response/EstimatedPriceReturn.php @@ -0,0 +1,92 @@ +currencyFrom = $currencyFrom; + $this->amountFrom = $amountFrom; + $this->currencyTo = $currencyTo; + $this->estimatedAmount = $estimatedAmount; + } + + /** + * @return mixed + */ + public function getCurrencyFrom() + { + return $this->currencyFrom; + } + + /** + * @param mixed $currencyFrom + */ + public function setCurrencyFrom($currencyFrom): void + { + $this->currencyFrom = $currencyFrom; + } + + /** + * @return mixed + */ + public function getAmountFrom() + { + return $this->amountFrom; + } + + /** + * @param mixed $amountFrom + */ + public function setAmountFrom($amountFrom): void + { + $this->amountFrom = $amountFrom; + } + + /** + * @return mixed + */ + public function getCurrencyTo() + { + return $this->currencyTo; + } + + /** + * @param mixed $currencyTo + */ + public function setCurrencyTo($currencyTo): void + { + $this->currencyTo = $currencyTo; + } + + /** + * @return mixed + */ + public function getEstimatedAmount() + { + return $this->estimatedAmount; + } + + /** + * @param mixed $estimatedAmount + */ + public function setEstimatedAmount($estimatedAmount): void + { + $this->estimatedAmount = $estimatedAmount; + } +} \ No newline at end of file diff --git a/src/response/GetListPaymentsReturn.php b/src/response/GetListPaymentsReturn.php new file mode 100644 index 0000000..2043f69 --- /dev/null +++ b/src/response/GetListPaymentsReturn.php @@ -0,0 +1,107 @@ +data = []; + $this->limit = $limit; + $this->page = $page; + $this->pagesCount = $pagesCount; + $this->total = $total; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param ListPaymentItem $invoice + */ + public function pushInvoice(ListPaymentItem $invoice): void + { + array_push($this->data, $invoice); + } + + /** + * @return mixed + */ + public function getLimit() + { + return $this->limit; + } + + /** + * @param mixed $limit + */ + public function setLimit($limit): void + { + $this->limit = $limit; + } + + /** + * @return mixed + */ + public function getPage() + { + return $this->page; + } + + /** + * @param mixed $page + */ + public function setPage($page): void + { + $this->page = $page; + } + + /** + * @return mixed + */ + public function getPagesCount() + { + return $this->pagesCount; + } + + /** + * @param mixed $pagesCount + */ + public function setPagesCount($pagesCount): void + { + $this->pagesCount = $pagesCount; + } + + /** + * @return mixed + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param mixed $total + */ + public function setTotal($total): void + { + $this->total = $total; + } + + +} \ No newline at end of file diff --git a/src/response/InvoiceReturn.php b/src/response/InvoiceReturn.php new file mode 100644 index 0000000..73a2093 --- /dev/null +++ b/src/response/InvoiceReturn.php @@ -0,0 +1,244 @@ +id = $id; + $this->order_id = $order_id; + $this->order_description = $order_description; + $this->price_amount = $price_amount; + $this->price_currency = $price_currency; + $this->pay_currency = $pay_currency; + $this->ipn_callback_url = $ipn_callback_url; + $this->invoice_url = $invoice_url; + $this->success_url = $success_url; + $this->cancel_url = $cancel_url; + $this->created_at = $created_at; + $this->updated_at = $updated_at; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getOrderId() + { + return $this->order_id; + } + + /** + * @param mixed $order_id + */ + public function setOrderId($order_id): void + { + $this->order_id = $order_id; + } + + /** + * @return mixed + */ + public function getOrderDescription() + { + return $this->order_description; + } + + /** + * @param mixed $order_description + */ + public function setOrderDescription($order_description): void + { + $this->order_description = $order_description; + } + + /** + * @return mixed + */ + public function getPriceAmount() + { + return $this->price_amount; + } + + /** + * @param mixed $price_amount + */ + public function setPriceAmount($price_amount): void + { + $this->price_amount = $price_amount; + } + + /** + * @return mixed + */ + public function getPriceCurrency() + { + return $this->price_currency; + } + + /** + * @param mixed $price_currency + */ + public function setPriceCurrency($price_currency): void + { + $this->price_currency = $price_currency; + } + + /** + * @return mixed + */ + public function getPayCurrency() + { + return $this->pay_currency; + } + + /** + * @param mixed $pay_currency + */ + public function setPayCurrency($pay_currency): void + { + $this->pay_currency = $pay_currency; + } + + /** + * @return mixed + */ + public function getIpnCallbackUrl() + { + return $this->ipn_callback_url; + } + + /** + * @param mixed $ipn_callback_url + */ + public function setIpnCallbackUrl($ipn_callback_url): void + { + $this->ipn_callback_url = $ipn_callback_url; + } + + /** + * @return mixed + */ + public function getInvoiceUrl() + { + return $this->invoice_url; + } + + /** + * @param mixed $invoice_url + */ + public function setInvoiceUrl($invoice_url): void + { + $this->invoice_url = $invoice_url; + } + + /** + * @return mixed + */ + public function getSuccessUrl() + { + return $this->success_url; + } + + /** + * @param mixed $success_url + */ + public function setSuccessUrl($success_url): void + { + $this->success_url = $success_url; + } + + /** + * @return mixed + */ + public function getCancelUrl() + { + return $this->cancel_url; + } + + /** + * @param mixed $cancel_url + */ + public function setCancelUrl($cancel_url): void + { + $this->cancel_url = $cancel_url; + } + + /** + * @return mixed + */ + public function getCreatedAt() + { + return $this->created_at; + } + + /** + * @param mixed $created_at + */ + public function setCreatedAt($created_at): void + { + $this->created_at = $created_at; + } + + /** + * @return mixed + */ + public function getUpdatedAt() + { + return $this->updated_at; + } + + /** + * @param mixed $updated_at + */ + public function setUpdatedAt($updated_at): void + { + $this->updated_at = $updated_at; + } +} \ No newline at end of file diff --git a/src/response/ListPaymentItem.php b/src/response/ListPaymentItem.php new file mode 100644 index 0000000..3f08726 --- /dev/null +++ b/src/response/ListPaymentItem.php @@ -0,0 +1,261 @@ +payment_id = $payment_id; + $this->payment_status = $payment_status; + $this->pay_address = $pay_address; + $this->price_amount = $price_amount; + $this->price_currency = $price_currency; + $this->pay_amount = $pay_amount; + $this->actually_paid = $actually_paid; + $this->pay_currency = $pay_currency; + $this->order_id = $order_id; + $this->order_description = $order_description; + $this->purchase_id = ""; + $this->outcome_amount = ""; + $this->outcome_currency = ""; + } + + /** + * @return mixed + */ + public function getPaymentId() + { + return $this->payment_id; + } + + /** + * @param mixed $payment_id + */ + public function setPaymentId($payment_id): void + { + $this->payment_id = $payment_id; + } + + /** + * @return mixed + */ + public function getPaymentStatus() + { + return $this->payment_status; + } + + /** + * @param mixed $payment_status + */ + public function setPaymentStatus($payment_status): void + { + $this->payment_status = $payment_status; + } + + /** + * @return mixed + */ + public function getPayAddress() + { + return $this->pay_address; + } + + /** + * @param mixed $pay_address + */ + public function setPayAddress($pay_address): void + { + $this->pay_address = $pay_address; + } + + /** + * @return mixed + */ + public function getPriceAmount() + { + return $this->price_amount; + } + + /** + * @param mixed $price_amount + */ + public function setPriceAmount($price_amount): void + { + $this->price_amount = $price_amount; + } + + /** + * @return mixed + */ + public function getPriceCurrency() + { + return $this->price_currency; + } + + /** + * @param mixed $price_currency + */ + public function setPriceCurrency($price_currency): void + { + $this->price_currency = $price_currency; + } + + /** + * @return mixed + */ + public function getPayAmount() + { + return $this->pay_amount; + } + + /** + * @param mixed $pay_amount + */ + public function setPayAmount($pay_amount): void + { + $this->pay_amount = $pay_amount; + } + + /** + * @return mixed + */ + public function getActuallyPaid() + { + return $this->actually_paid; + } + + /** + * @param mixed $actually_paid + */ + public function setActuallyPaid($actually_paid): void + { + $this->actually_paid = $actually_paid; + } + + /** + * @return mixed + */ + public function getPayCurrency() + { + return $this->pay_currency; + } + + /** + * @param mixed $pay_currency + */ + public function setPayCurrency($pay_currency): void + { + $this->pay_currency = $pay_currency; + } + + /** + * @return mixed + */ + public function getOrderId() + { + return $this->order_id; + } + + /** + * @param mixed $order_id + */ + public function setOrderId($order_id): void + { + $this->order_id = $order_id; + } + + /** + * @return mixed + */ + public function getOrderDescription() + { + return $this->order_description; + } + + /** + * @param mixed $order_description + */ + public function setOrderDescription($order_description): void + { + $this->order_description = $order_description; + } + + /** + * @return mixed + */ + public function getPurchaseId() + { + return $this->purchase_id; + } + + /** + * @param mixed $purchase_id + */ + public function setPurchaseId($purchase_id): void + { + $this->purchase_id = $purchase_id; + } + + /** + * @return mixed + */ + public function getOutcomeAmount() + { + return $this->outcome_amount; + } + + /** + * @param mixed $outcome_amount + */ + public function setOutcomeAmount($outcome_amount): void + { + $this->outcome_amount = $outcome_amount; + } + + /** + * @return mixed + */ + public function getOutcomeCurrency() + { + return $this->outcome_currency; + } + + /** + * @param mixed $outcome_currency + */ + public function setOutcomeCurrency($outcome_currency): void + { + $this->outcome_currency = $outcome_currency; + } + + +} \ No newline at end of file diff --git a/src/response/MinimumPaymentAmountResponse.php b/src/response/MinimumPaymentAmountResponse.php new file mode 100644 index 0000000..6ef1ccf --- /dev/null +++ b/src/response/MinimumPaymentAmountResponse.php @@ -0,0 +1,47 @@ +currencyForm = $currencyForm; + $this->currencyTo = $currencyTo; + $this->minAmount = $minAmount; + } + + /** + * @return mixed + */ + public function getCurrencyForm() + { + return $this->currencyForm; + } + + /** + * @return mixed + */ + public function getCurrencyTo() + { + return $this->currencyTo; + } + + /** + * @return mixed + */ + public function getMinAmount() + { + return $this->minAmount; + } +} \ No newline at end of file diff --git a/src/response/PaymentStatusReturn.php b/src/response/PaymentStatusReturn.php new file mode 100644 index 0000000..4aaea1d --- /dev/null +++ b/src/response/PaymentStatusReturn.php @@ -0,0 +1,301 @@ +payment_id = $payment_id; + $this->payment_status = $payment_status; + $this->pay_address = $pay_address; + $this->price_amount = $price_amount; + $this->price_currency = $price_currency; + $this->pay_amount = $pay_amount; + $this->actually_paid = $actually_paid; + $this->pay_currency = $pay_currency; + $this->order_id = $order_id; + $this->order_description = $order_description; + $this->purchase_id = $purchase_id; + $this->created_at = $created_at; + $this->updated_at = $updated_at; + $this->outcome_amount = $outcome_amount; + $this->outcome_currency = $outcome_currency; + } + + /** + * @return mixed + */ + public function getPaymentId() + { + return $this->payment_id; + } + + /** + * @param mixed $payment_id + */ + public function setPaymentId($payment_id): void + { + $this->payment_id = $payment_id; + } + + /** + * @return mixed + */ + public function getPaymentStatus() + { + return $this->payment_status; + } + + /** + * @param mixed $payment_status + */ + public function setPaymentStatus($payment_status): void + { + $this->payment_status = $payment_status; + } + + /** + * @return mixed + */ + public function getPayAddress() + { + return $this->pay_address; + } + + /** + * @param mixed $pay_address + */ + public function setPayAddress($pay_address): void + { + $this->pay_address = $pay_address; + } + + /** + * @return mixed + */ + public function getPriceAmount() + { + return $this->price_amount; + } + + /** + * @param mixed $price_amount + */ + public function setPriceAmount($price_amount): void + { + $this->price_amount = $price_amount; + } + + /** + * @return mixed + */ + public function getPriceCurrency() + { + return $this->price_currency; + } + + /** + * @param mixed $price_currency + */ + public function setPriceCurrency($price_currency): void + { + $this->price_currency = $price_currency; + } + + /** + * @return mixed + */ + public function getPayAmount() + { + return $this->pay_amount; + } + + /** + * @param mixed $pay_amount + */ + public function setPayAmount($pay_amount): void + { + $this->pay_amount = $pay_amount; + } + + /** + * @return mixed + */ + public function getActuallyPaid() + { + return $this->actually_paid; + } + + /** + * @param mixed $actually_paid + */ + public function setActuallyPaid($actually_paid): void + { + $this->actually_paid = $actually_paid; + } + + /** + * @return mixed + */ + public function getPayCurrency() + { + return $this->pay_currency; + } + + /** + * @param mixed $pay_currency + */ + public function setPayCurrency($pay_currency): void + { + $this->pay_currency = $pay_currency; + } + + /** + * @return mixed + */ + public function getOrderId() + { + return $this->order_id; + } + + /** + * @param mixed $order_id + */ + public function setOrderId($order_id): void + { + $this->order_id = $order_id; + } + + /** + * @return mixed + */ + public function getOrderDescription() + { + return $this->order_description; + } + + /** + * @param mixed $order_description + */ + public function setOrderDescription($order_description): void + { + $this->order_description = $order_description; + } + + /** + * @return mixed + */ + public function getPurchaseId() + { + return $this->purchase_id; + } + + /** + * @param mixed $purchase_id + */ + public function setPurchaseId($purchase_id): void + { + $this->purchase_id = $purchase_id; + } + + /** + * @return mixed + */ + public function getCreatedAt() + { + return $this->created_at; + } + + /** + * @param mixed $created_at + */ + public function setCreatedAt($created_at): void + { + $this->created_at = $created_at; + } + + /** + * @return mixed + */ + public function getUpdatedAt() + { + return $this->updated_at; + } + + /** + * @param mixed $updated_at + */ + public function setUpdatedAt($updated_at): void + { + $this->updated_at = $updated_at; + } + + /** + * @return mixed + */ + public function getOutcomeAmount() + { + return $this->outcome_amount; + } + + /** + * @param mixed $outcome_amount + */ + public function setOutcomeAmount($outcome_amount): void + { + $this->outcome_amount = $outcome_amount; + } + + /** + * @return mixed + */ + public function getOutcomeCurrency() + { + return $this->outcome_currency; + } + + /** + * @param mixed $outcome_currency + */ + public function setOutcomeCurrency($outcome_currency): void + { + $this->outcome_currency = $outcome_currency; + } +} \ No newline at end of file diff --git a/src/response/StatusReturn.php b/src/response/StatusReturn.php new file mode 100644 index 0000000..94b0cef --- /dev/null +++ b/src/response/StatusReturn.php @@ -0,0 +1,33 @@ +message = $message; + } + + /** + * @return mixed + */ + public function getMessage() + { + return $this->message; + } + + /** + * @param mixed $message + */ + public function setMessage($message): void + { + $this->message = $message; + } +} \ No newline at end of file diff --git a/src/types/CreateInvoice.php b/src/types/CreateInvoice.php new file mode 100644 index 0000000..8e0a6e3 --- /dev/null +++ b/src/types/CreateInvoice.php @@ -0,0 +1,211 @@ +priceAmount = $priceAmount; + $this->priceCurrency = $priceCurrency; + $this->payCurrency = $payCurrency; + $this->ipnCallbackUrl = $ipnCallbackUrl; + $this->orderId = $orderId; + $this->orderDescription = $orderDescription; + $this->successUrl = $successUrl; + $this->cancelUrl = $cancelUrl; + } + + /** + * @return float + */ + public function getPriceAmount(): float + { + return $this->priceAmount; + } + + /** + * @param float $priceAmount + */ + public function setPriceAmount(float $priceAmount): void + { + $this->priceAmount = $priceAmount; + } + + /** + * @return string + */ + public function getPriceCurrency(): string + { + return $this->priceCurrency; + } + + /** + * @param string $priceCurrency + */ + public function setPriceCurrency(string $priceCurrency): void + { + $this->priceCurrency = $priceCurrency; + } + + /** + * @return string + */ + public function getPayCurrency(): string + { + return $this->payCurrency; + } + + /** + * @return bool + */ + public function isSetPayCurrency(): bool { + return strlen($this->payCurrency) !== 0; + } + + /** + * @param string $payCurrency + */ + public function setPayCurrency(string $payCurrency): void + { + $this->payCurrency = $payCurrency; + } + + /** + * @return string + */ + public function getIpnCallbackUrl(): string + { + return $this->ipnCallbackUrl; + } + + /** + * @return bool + */ + public function isSetIpnCallbackUrl(): bool { + return strlen($this->ipnCallbackUrl) !== 0; + } + + /** + * @param string $ipnCallbackUrl + */ + public function setIpnCallbackUrl(string $ipnCallbackUrl): void + { + $this->ipnCallbackUrl = $ipnCallbackUrl; + } + + /** + * @return string + */ + public function getOrderId(): string + { + return $this->orderId; + } + + /** + * @return bool + */ + public function isSetOrderId(): bool { + return strlen($this->orderId) !== 0; + } + + /** + * @param string $orderId + */ + public function setOrderId(string $orderId): void + { + $this->orderId = $orderId; + } + + /** + * @return string + */ + public function getOrderDescription(): string + { + return $this->orderDescription; + } + + /** + * @return bool + */ + public function isSetOrderDescription(): bool { + return strlen($this->orderDescription) !== 0; + } + + /** + * @param string $orderDescription + */ + public function setOrderDescription(string $orderDescription): void + { + $this->orderDescription = $orderDescription; + } + + /** + * @return string + */ + public function getSuccessUrl(): string + { + return $this->successUrl; + } + + /** + * @return bool + */ + public function isSetSuccessUrl(): bool { + return strlen($this->successUrl) !== 0; + } + + /** + * @param string $successUrl + */ + public function setSuccessUrl(string $successUrl): void + { + $this->successUrl = $successUrl; + } + + /** + * @return string + */ + public function getCancelUrl(): string + { + return $this->cancelUrl; + } + + /** + * @return bool + */ + public function isSetCancelUrl(): bool { + return strlen($this->cancelUrl) !== 0; + } + + /** + * @param string $cancelUrl + */ + public function setCancelUrl(string $cancelUrl): void + { + $this->cancelUrl = $cancelUrl; + } + + +} \ No newline at end of file diff --git a/src/types/CreatePayment.php b/src/types/CreatePayment.php new file mode 100644 index 0000000..73efabd --- /dev/null +++ b/src/types/CreatePayment.php @@ -0,0 +1,290 @@ +price_amount = $price_amount; + $this->price_currency = $price_currency; + $this->pay_currency = $pay_currency; + } + + /** + * @return mixed + */ + public function getPriceAmount() + { + return $this->price_amount; + } + + /** + * @param mixed $price_amount + */ + public function setPriceAmount($price_amount): void + { + $this->price_amount = $price_amount; + } + + /** + * @return mixed + */ + public function getPriceCurrency() + { + return $this->price_currency; + } + + /** + * @param mixed $price_currency + */ + public function setPriceCurrency($price_currency): void + { + $this->price_currency = $price_currency; + } + + /** + * @return int + */ + public function getPayAmount(): int + { + return $this->pay_amount; + } + + /** + * @param int $pay_amount + */ + public function setPayAmount(int $pay_amount): void + { + $this->pay_amount = $pay_amount; + } + + /** + * @return mixed + */ + public function getPayCurrency() + { + return $this->pay_currency; + } + + + /** + * @return bool + */ + public function isSetPayCurrency(): bool { + return strlen($this->pay_currency) !== 0; + } + /** + * @param mixed $pay_currency + */ + public function setPayCurrency($pay_currency): void + { + $this->pay_currency = $pay_currency; + } + + /** + * @return string + */ + public function getIpnCallbackUrl(): string + { + return $this->ipn_callback_url; + } + + /** + * @return bool + */ + public function isSetIpnCallbackUrl(): bool { + return strlen($this->ipn_callback_url) !== 0; + } + + /** + * @param string $ipn_callback_url + */ + public function setIpnCallbackUrl(string $ipn_callback_url): void + { + $this->ipn_callback_url = $ipn_callback_url; + } + + /** + * @return string + */ + public function getOrderId(): string + { + return $this->order_id; + } + + /** + * @return bool + */ + public function isSetOrderId(): bool { + return strlen($this->order_id) !== 0; + } + + /** + * @param string $order_id + */ + public function setOrderId(string $order_id): void + { + $this->order_id = $order_id; + } + + /** + * @return string + */ + public function getOrderDescription(): string + { + return $this->order_description; + } + + /** + * @return bool + */ + public function isSetOrderDescription(): bool { + return strlen($this->order_description) !== 0; + } + + /** + * @param string $order_description + */ + public function setOrderDescription(string $order_description): void + { + $this->order_description = $order_description; + } + + /** + * @return string + */ + public function getPurchaseId(): string + { + return $this->purchase_id; + } + + /** + * @return bool + */ + public function isSetPurchaseId(): bool { + return strlen($this->purchase_id) !== 0; + } + + /** + * @param string $purchase_id + */ + public function setPurchaseId(string $purchase_id): void + { + $this->purchase_id = $purchase_id; + } + + /** + * @return string + */ + public function getPayoutAddress(): string + { + return $this->payout_address; + } + + /** + * @return bool + */ + public function isSetPayoutAddress(): bool { + return strlen($this->payout_address) !== 0; + } + + + /** + * @param string $payout_address + */ + public function setPayoutAddress(string $payout_address): void + { + $this->payout_address = $payout_address; + } + + /** + * @return string + */ + public function getPayoutCurrency(): string + { + return $this->payout_currency; + } + + /** + * @return bool + */ + public function isSetPayoutCurrency(): bool { + return strlen($this->payout_currency) !== 0; + } + + /** + * @param string $payout_currency + */ + public function setPayoutCurrency(string $payout_currency): void + { + $this->payout_currency = $payout_currency; + } + + /** + * @return string + */ + public function getPayoutExtraId(): string + { + return $this->payout_extra_id; + } + + /** + * @return bool + */ + public function isSetPayoutExtraId(): bool { + return strlen($this->payout_extra_id) !== 0; + } + + /** + * @param string $payout_extra_id + */ + public function setPayoutExtraId(string $payout_extra_id): void + { + $this->payout_extra_id = $payout_extra_id; + } + + /** + * @return string + */ + public function getFixedRate(): string + { + return $this->fixed_rate; + } + + /** + * @return bool + */ + public function isSetFixedRate(): bool { + return strlen($this->fixed_rate) !== 0; + } + + /** + * @param string $fixed_rate + */ + public function setFixedRate(string $fixed_rate): void + { + $this->fixed_rate = $fixed_rate; + } +} \ No newline at end of file diff --git a/src/types/GetEstimatePrice.php b/src/types/GetEstimatePrice.php new file mode 100644 index 0000000..b96df3b --- /dev/null +++ b/src/types/GetEstimatePrice.php @@ -0,0 +1,73 @@ +amount = $amount; + $this->currency_from = $currency_from; + $this->currency_to = $currency_to; + } + + /** + * @return int + */ + public function getAmount(): int + { + return $this->amount; + } + + /** + * @param int $amount + */ + public function setAmount(int $amount): void + { + $this->amount = $amount; + } + + /** + * @return string + */ + public function getCurrencyFrom(): string + { + return $this->currency_from; + } + + /** + * @param string $currency_from + */ + public function setCurrencyFrom(string $currency_from): void + { + $this->currency_from = $currency_from; + } + + /** + * @return string + */ + public function getCurrencyTo(): string + { + return $this->currency_to; + } + + /** + * @param string $currency_to + */ + public function setCurrencyTo(string $currency_to): void + { + $this->currency_to = $currency_to; + } +} \ No newline at end of file diff --git a/src/types/GetListPayments.php b/src/types/GetListPayments.php new file mode 100644 index 0000000..2468e04 --- /dev/null +++ b/src/types/GetListPayments.php @@ -0,0 +1,185 @@ +limit; + } + + /** + * @param int $limit + * @throws MyException + */ + public function setLimit(int $limit): void + { + if ($limit < 1 || $limit > 500) { + throw new MyException("Valid limit range [1: 500]. Current " . $limit); + } + $this->limit = $limit; + } + + /** + * @return bool + */ + public function isSetLimit(): bool + { + return $this->limit !== self::NOT_SET_INT_VALUE; + } + + /** + * @return int + */ + public function getPage(): int + { + return $this->page; + } + + /** + * @param int $page + * @throws MyException + */ + public function setPage(int $page): void + { + if ($page < 0) { + throw new MyException("Invalid page value"); + } + $this->page = $page; + } + + /** + * @return bool + */ + public function isSetPage(): bool + { + return $this->page !== self::NOT_SET_INT_VALUE; + } + + /** + * @return string + */ + public function getSortBy(): string + { + return $this->sortBy; + } + + /** + * @param string $sortBy + * @throws MyException + */ + public function setSortBy(string $sortBy): void + { + if (!in_array($sortBy, self::SORT_BY_FIELDS)) { + throw new MyException("Invalid sort fields. Valid sort fields payment_id, payment_status, pay_address, price_amount, price_currency, pay_amount, actually_paid, pay_currency, order_id, order_description, purchase_id, outcome_amount, outcome_currency"); + } + $this->sortBy = $sortBy; + } + + /** + * @return bool + */ + public function isSetSortBy(): bool + { + return strlen($this->sortBy) !== 0; + } + + /** + * @return string + */ + public function getOrderBy(): string + { + return $this->orderBy; + } + + /** + * @param string $orderBy + * @throws MyException + */ + public function setOrderBy(string $orderBy): void + { + if ($orderBy !== "asc" && $orderBy !== "desc") { + throw new MyException("Invalid order by fields. Valid value asc, desc"); + } + + $this->orderBy = $orderBy; + } + + /** + * @return bool + */ + public function isSetOrderBy(): bool + { + return strlen($this->sortBy) !== 0; + } + + /** + * @return string + */ + public function getDateFrom(): string + { + return $this->dateFrom; + } + + /** + * @param string $dateFrom + */ + public function setDateFrom(string $dateFrom): void + { + $this->dateFrom = $dateFrom; + } + + /** + * @return bool + */ + public function isSetDateFrom(): bool + { + return strlen($this->sortBy) !== 0; + } + + /** + * @return string + */ + public function getDateTo(): string + { + return $this->dateTo; + } + + /** + * @param string $dateTo + */ + public function setDateTo(string $dateTo): void + { + $this->dateTo = $dateTo; + } + + /** + * @return bool + */ + public function isSetDateTo(): bool + { + return strlen($this->sortBy) !== 0; + } +} \ No newline at end of file diff --git a/src/util/Validate.php b/src/util/Validate.php new file mode 100644 index 0000000..f3a2700 --- /dev/null +++ b/src/util/Validate.php @@ -0,0 +1,8 @@ +