@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | const MAX_MONEY_DECIMAL = 2; |
| 29 | 29 | const MAX_MONEY_LENGTH = 10; |
| 30 | 30 | |
| 31 | - public function __construct (array $settings) { |
|
| 31 | + public function __construct(array $settings) { |
|
| 32 | 32 | parent::__construct($settings); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function cryptoCallback (cryptoCallback $cryptoData) { |
|
| 35 | + public function cryptoCallback(cryptoCallback $cryptoData) { |
|
| 36 | 36 | $paid_amount = $cryptoData->paid_amount; |
| 37 | 37 | $user_id = $cryptoData->user_id; |
| 38 | 38 | $real_amount = $cryptoData->real_amount; |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | if ($cryptoData->status === cryptoCallbackStatus::PARTIALLY_PAID) { |
| 45 | 45 | $need_to_pay = $real_amount - $total_paid; |
| 46 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
| 46 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
| 47 | 47 | return $this->sendMessage(strReplace(['$amount' => $paid_amount, '$real_amount' => $real_amount, '$need_amount' => $need_to_pay], texts::PARTIALLY_PAID), $user_id); |
| 48 | 48 | } |
| 49 | 49 | if ($cryptoData->status === cryptoCallbackStatus::FINISHED) { |
| 50 | 50 | if ($paid_amount != $total_paid) { |
| 51 | 51 | $old_amount = $total_paid - $paid_amount; |
| 52 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
| 52 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
| 53 | 53 | return $this->sendMessage(strReplace(['$amount' => $total_paid, '$old_amount' => $old_amount, '$new_amount' => $paid_amount], texts::FINISHED_PARTIALLY), $user_id); |
| 54 | 54 | } |
| 55 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
| 55 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
| 56 | 56 | return $this->sendMessage(strReplace(['$amount' => $paid_amount], texts::FINISHED), $user_id); |
| 57 | 57 | } |
| 58 | 58 | if ($cryptoData->status === cryptoCallbackStatus::EXTRA_PAID) { |
| 59 | 59 | if ($paid_amount != $total_paid) { |
| 60 | 60 | $old_amount = $total_paid - $paid_amount; |
| 61 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
| 61 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
| 62 | 62 | return $this->sendMessage(strReplace(['$amount' => $total_paid, '$real_amount' => $real_amount, '$old_amount' => $old_amount, '$new_amount' => $paid_amount], texts::EXTRA_PAID_PARTIALLY), $user_id); |
| 63 | 63 | } |
| 64 | - mysql::update('users', ['balance' => '+=' . $paid_amount], ['id' => $user_id], 1); |
|
| 64 | + mysql::update('users', ['balance' => '+='.$paid_amount], ['id' => $user_id], 1); |
|
| 65 | 65 | return $this->sendMessage(strReplace(['$amount' => $paid_amount, '$real_amount' => $real_amount], texts::EXTRA_PAID), $user_id); |
| 66 | 66 | } |
| 67 | 67 | if ($cryptoData->status === cryptoCallbackStatus::SUCCESS) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - public function message (message $update) { |
|
| 120 | + public function message(message $update) { |
|
| 121 | 121 | $text = $update->text ?? ''; |
| 122 | 122 | |
| 123 | 123 | $user_id = $update->from->id; |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | return $this->sendMessage(strReplace(['$max_transfer' => self::MAX_TRANSFER], texts::MAX_TRANSFER), answer: true); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - mysql::update('users', ['balance' => '+=' . $text], ['id' => $user->value], 1); |
|
| 219 | + mysql::update('users', ['balance' => '+='.$text], ['id' => $user->value], 1); |
|
| 220 | 220 | $this->sendMessage(strReplace(['$amount' => $text, '$id' => $user_id], texts::MONEY_RECEIVED), $user->value); |
| 221 | 221 | |
| 222 | 222 | mysql::insert('history', ['type', 'amount', 'date', 'user_id', 'target_id'], ['transfer', $text, time(), $user_id, $user->value]); |
| 223 | 223 | |
| 224 | - mysql::update('users', ['balance' => '-=' . $text, 'step' => 'main', 'value' => ''], ['id' => $user_id], 1); |
|
| 224 | + mysql::update('users', ['balance' => '-='.$text, 'step' => 'main', 'value' => ''], ['id' => $user_id], 1); |
|
| 225 | 225 | return $this->sendMessage(texts::TRANSFER_DONE, reply_markup: keyboards::START, answer: true); |
| 226 | 226 | } |
| 227 | 227 | if ($user->step === 'deposit') { |
@@ -11,8 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | if (file_exists('vendor/autoload.php')) { |
| 13 | 13 | require 'vendor/autoload.php'; |
| 14 | -} |
|
| 15 | -else { |
|
| 14 | +} else { |
|
| 16 | 15 | if (!file_exists('BPT.phar')) { |
| 17 | 16 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
| 18 | 17 | } |
@@ -174,14 +173,12 @@ discard block |
||
| 174 | 173 | } |
| 175 | 174 | if (isset($update->user_shared)) { |
| 176 | 175 | $target_id = $update->user_shared->user_id; |
| 177 | - } |
|
| 178 | - elseif (isset($update->forward_date)) { |
|
| 176 | + } elseif (isset($update->forward_date)) { |
|
| 179 | 177 | if (!isset($update->forward_from)) { |
| 180 | 178 | return $this->sendMessage(texts::USER_FORWARD_CLOSED, answer: true); |
| 181 | 179 | } |
| 182 | 180 | $target_id = $update->forward_from->id; |
| 183 | - } |
|
| 184 | - else { |
|
| 181 | + } else { |
|
| 185 | 182 | if (!is_numeric($text) || $text != floor($text)) { |
| 186 | 183 | return $this->sendMessage(texts::ONLY_INT, answer: true); |
| 187 | 184 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @internal Only for BPT self usage , Don't use it in your source! |
| 20 | 20 | */ |
| 21 | - public static function init () { |
|
| 21 | + public static function init() { |
|
| 22 | 22 | if (settings::$multi) { |
| 23 | 23 | multi::init(); |
| 24 | 24 | } |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | lock::deleteIfExist(['BPT-MULTI-EXEC', 'BPT-MULTI-CURL', 'getUpdate', 'getUpdateHook']); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected static function setWebhook(string $url,string $secret = '') { |
|
| 41 | + protected static function setWebhook(string $url, string $secret = '') { |
|
| 42 | 42 | $res = BPT::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret); |
| 43 | 43 | if (!BPT::$status) { |
| 44 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR); |
|
| 45 | - BPT::exit(print_r($res,true)); |
|
| 44 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR); |
|
| 45 | + BPT::exit(print_r($res, true)); |
|
| 46 | 46 | } |
| 47 | - logger::write('Webhook was set successfully',loggerTypes::INFO); |
|
| 47 | + logger::write('Webhook was set successfully', loggerTypes::INFO); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | protected static function checkURL() { |
| 51 | 51 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) { |
| 52 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR); |
|
| 52 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR); |
|
| 53 | 53 | throw new bptException('WEBHOOK_NEED_URL'); |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | protected static function setURL(): string { |
| 58 | 58 | if (isset($_GET['token'])) { |
| 59 | - logger::write("You can not specify token in url",loggerTypes::ERROR); |
|
| 59 | + logger::write("You can not specify token in url", loggerTypes::ERROR); |
|
| 60 | 60 | BPT::exit("You can not specify token in url"); |
| 61 | 61 | } |
| 62 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 62 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | protected static function setCertificate() { |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | self::checkURL(); |
| 75 | 75 | self::setCertificate(); |
| 76 | 76 | $url = self::setURL(); |
| 77 | - $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':','---',settings::$token); |
|
| 78 | - self::setWebhook($url,$secret); |
|
| 77 | + $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':', '---', settings::$token); |
|
| 78 | + self::setWebhook($url, $secret); |
|
| 79 | 79 | lock::save('BPT-HOOK', md5($secret)); |
| 80 | 80 | BPT::exit('Done'); |
| 81 | 81 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | logger::write('Your file address is shared on telegram, If you didnt do it then be careful(also it counts callback urls)', loggerTypes::WARNING); |
| 88 | 88 | BPT::exit(); |
| 89 | 89 | } |
| 90 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING); |
|
| 90 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING); |
|
| 91 | 91 | self::processSetWebhook(); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return bool |
| 110 | 110 | */ |
| 111 | - public static function fastClose (int $timeout = 86400): bool { |
|
| 111 | + public static function fastClose(int $timeout = 86400): bool { |
|
| 112 | 112 | if (settings::$multi || !lock::exist('BPT-HOOK') || settings::$receiver !== \BPT\constants\receiver::WEBHOOK) { |
| 113 | 113 | return false; |
| 114 | 114 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | public static function init () { |
| 22 | 22 | if (settings::$multi) { |
| 23 | 23 | multi::init(); |
| 24 | - } |
|
| 25 | - else { |
|
| 24 | + } else { |
|
| 26 | 25 | if (!lock::exist('BPT-HOOK')) { |
| 27 | 26 | self::processSetWebhook(); |
| 28 | 27 | } |
@@ -9,15 +9,15 @@ discard block |
||
| 9 | 9 | use BPT\tools\tools; |
| 10 | 10 | |
| 11 | 11 | class callback { |
| 12 | - public static function encodeData (array $data): string { |
|
| 12 | + public static function encodeData(array $data): string { |
|
| 13 | 13 | return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash']; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public static function decodeData (string $data): array { |
|
| 16 | + public static function decodeData(string $data): array { |
|
| 17 | 17 | return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public static function process () { |
|
| 20 | + public static function process() { |
|
| 21 | 21 | if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) { |
| 22 | 22 | return false; |
| 23 | 23 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | return false; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public static function callHandler (string $handler_name, $input) { |
|
| 42 | + public static function callHandler(string $handler_name, $input) { |
|
| 43 | 43 | if (method_exists(BPT::$handler, $handler_name)) { |
| 44 | 44 | BPT::$handler->$handler_name($input); |
| 45 | 45 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $ip = $ip ?? tools::remoteIP(); |
| 36 | 36 | if (!tools::isTelegram($ip)) { |
| 37 | 37 | if (!callback::process()) { |
| 38 | - logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING); |
|
| 38 | + logger::write('not authorized access denied. IP : '.$ip ?? 'unknown', loggerTypes::WARNING); |
|
| 39 | 39 | BPT::exit(); |
| 40 | 40 | } |
| 41 | 41 | die('callback handler stole the process :('); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - protected static function processUpdate(string|stdClass|update $update = null): void { |
|
| 46 | + protected static function processUpdate(string | stdClass | update $update = null): void { |
|
| 47 | 47 | if (!is_object($update)) { |
| 48 | 48 | $update = json_decode($update ?? file_get_contents('php://input')); |
| 49 | 49 | if (!$update) { |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if (settings::$use_types_classes && !is_a($update,'update')) { |
|
| 61 | + if (settings::$use_types_classes && !is_a($update, 'update')) { |
|
| 62 | 62 | $update = new update($update); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | db::save(); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - protected static function setMessageExtra (stdClass|update &$update): void { |
|
| 72 | + protected static function setMessageExtra(stdClass | update & $update): void { |
|
| 73 | 73 | if (!isset($update->message->text) && !isset($update->edited_message->text)) { |
| 74 | 74 | return; |
| 75 | 75 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | BPT::$handler->something_else(BPT::$update); |
| 146 | 146 | } |
| 147 | 147 | else { |
| 148 | - logger::write('Update received but handlers are not set',loggerTypes::WARNING); |
|
| 148 | + logger::write('Update received but handlers are not set', loggerTypes::WARNING); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | private static CurlHandle $session; |
| 40 | 40 | |
| 41 | - public static function init (string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
| 41 | + public static function init(string $api_key = '', string $ipn_secret = '', int $round_decimal = 4): void { |
|
| 42 | 42 | self::$api_key = settings::$pay['crypto']['api_key'] ?? $api_key; |
| 43 | 43 | self::$ipn_secret = settings::$pay['crypto']['ipn_secret'] ?? $ipn_secret; |
| 44 | 44 | self::$round_decimal = settings::$pay['crypto']['round_decimal'] ?? $round_decimal; |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYPEER, 1); |
| 48 | 48 | curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2); |
| 49 | 49 | curl_setopt(self::$session, CURLOPT_HTTPHEADER, [ |
| 50 | - 'X-API-KEY: ' . self::$api_key, |
|
| 50 | + 'X-API-KEY: '.self::$api_key, |
|
| 51 | 51 | 'Content-Type: application/json' |
| 52 | 52 | ]); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private static function execute (string $method, string $endpoint, string|array $data = '') { |
|
| 55 | + private static function execute(string $method, string $endpoint, string | array $data = '') { |
|
| 56 | 56 | if (is_array($data)) { |
| 57 | 57 | foreach ($data as $key => $value) { |
| 58 | 58 | if (empty($value)) { |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | switch ($method) { |
| 67 | 67 | case 'GET': |
| 68 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint . (!empty($data) && is_array($data) ? ('?' . http_build_query($data)) : '')); |
|
| 68 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint.(!empty($data) && is_array($data) ? ('?'.http_build_query($data)) : '')); |
|
| 69 | 69 | break; |
| 70 | 70 | case 'POST': |
| 71 | 71 | curl_setopt($session, CURLOPT_POST, true); |
| 72 | 72 | curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data)); |
| 73 | - curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint); |
|
| 73 | + curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint); |
|
| 74 | 74 | break; |
| 75 | 75 | default: |
| 76 | 76 | return false; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * This is a method to get information about the current state of the API. Receive true if its ok and false in otherwise |
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | - public static function status (): bool { |
|
| 85 | + public static function status(): bool { |
|
| 86 | 86 | return self::execute('GET', 'status')->message === 'OK'; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return estimatePriceInterface|errorResponseInterface|mixed |
| 99 | 99 | */ |
| 100 | - public static function getEstimatePrice (int|float $amount, string $currency_from, string $currency_to) { |
|
| 100 | + public static function getEstimatePrice(int | float $amount, string $currency_from, string $currency_to) { |
|
| 101 | 101 | return self::execute('GET', 'estimate', [ |
| 102 | 102 | 'amount' => $amount, |
| 103 | 103 | 'currency_from' => $currency_from, |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
| 126 | 126 | */ |
| 127 | - public static function createPayment (int|float $price_amount, string $price_currency, string $pay_currency, int|float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
| 127 | + public static function createPayment(int | float $price_amount, string $price_currency, string $pay_currency, int | float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null, bool $is_fee_paid_by_user = null) { |
|
| 128 | 128 | return self::execute('POST', 'payment', [ |
| 129 | 129 | 'price_amount' => $price_amount, |
| 130 | 130 | 'price_currency' => $price_currency, |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return invoicePaymentInterface|errorResponseInterface|mixed |
| 158 | 158 | */ |
| 159 | - public static function createInvoicePayment (string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
| 159 | + public static function createInvoicePayment(string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) { |
|
| 160 | 160 | return self::execute('POST', 'invoice-payment', [ |
| 161 | 161 | 'iid' => $iid, |
| 162 | 162 | 'pay_currency' => $pay_currency, |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return estimateUpdateInterface|errorResponseInterface|mixed |
| 179 | 179 | */ |
| 180 | - public static function updateEstimatePrice (int $paymentID) { |
|
| 181 | - return self::execute('POST', 'payment/' . $paymentID . '/update-merchant-estimate'); |
|
| 180 | + public static function updateEstimatePrice(int $paymentID) { |
|
| 181 | + return self::execute('POST', 'payment/'.$paymentID.'/update-merchant-estimate'); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @return paymentInterface|errorResponseInterface|mixed |
| 190 | 190 | */ |
| 191 | - public static function getPaymentStatus (int $paymentID) { |
|
| 192 | - return self::execute('GET', 'payment/' . $paymentID); |
|
| 191 | + public static function getPaymentStatus(int $paymentID) { |
|
| 192 | + return self::execute('GET', 'payment/'.$paymentID); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * |
| 201 | 201 | * @return float |
| 202 | 202 | */ |
| 203 | - public static function getMinimumPaymentAmount (string $currency_from, string $currency_to): float { |
|
| 203 | + public static function getMinimumPaymentAmount(string $currency_from, string $currency_to): float { |
|
| 204 | 204 | return self::execute('GET', 'min-amount', [ |
| 205 | 205 | 'currency_from' => $currency_from, |
| 206 | 206 | 'currency_to' => $currency_to |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return invoiceResponseInterface|errorResponseInterface|mixed |
| 223 | 223 | */ |
| 224 | - public static function createInvoice (int|float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
| 224 | + public static function createInvoice(int | float $price_amount, string $price_currency, string $pay_currency = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) { |
|
| 225 | 225 | return self::execute('POST', 'invoice', [ |
| 226 | 226 | 'price_amount' => $price_amount, |
| 227 | 227 | 'price_currency' => $price_currency, |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return array |
| 241 | 241 | */ |
| 242 | - public static function getCurrencies (): array { |
|
| 242 | + public static function getCurrencies(): array { |
|
| 243 | 243 | return self::execute('GET', 'currencies')->currencies; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | - public static function getFullCurrencies (): array { |
|
| 251 | + public static function getFullCurrencies(): array { |
|
| 252 | 252 | return self::execute('GET', 'full-currencies')->currencies; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @return array |
| 260 | 260 | */ |
| 261 | - public static function getAvailableCheckedCurrencies (): array { |
|
| 261 | + public static function getAvailableCheckedCurrencies(): array { |
|
| 262 | 262 | return self::execute('GET', 'merchant/coins')->currencies; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return bool |
| 278 | 278 | */ |
| 279 | - public static function isIPNRequestValid (): bool { |
|
| 279 | + public static function isIPNRequestValid(): bool { |
|
| 280 | 280 | if (empty($_SERVER['HTTP_X_NOWPAYMENTS_SIG'])) { |
| 281 | 281 | return false; |
| 282 | 282 | } |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | * |
| 299 | 299 | * @return ipnDataInterface|mixed |
| 300 | 300 | */ |
| 301 | - public static function getIPN () { |
|
| 301 | + public static function getIPN() { |
|
| 302 | 302 | if (!self::isIPNRequestValid()) { |
| 303 | 303 | return false; |
| 304 | 304 | } |
| 305 | 305 | return json_decode(file_get_contents('php://input')); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - protected static function createOrder (float|int $amount, int $user_id, string $description): int|string { |
|
| 308 | + protected static function createOrder(float | int $amount, int $user_id, string $description): int | string { |
|
| 309 | 309 | if (!mysql::getMysqli()) { |
| 310 | 310 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
| 311 | 311 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | return mysql::insertId(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - protected static function getOrder (int $order_id): bool|object { |
|
| 319 | + protected static function getOrder(int $order_id): bool | object { |
|
| 320 | 320 | if (!mysql::getMysqli()) { |
| 321 | 321 | logger::write("crypto::ezPay function used\ncreating order needed mysql connection in our mysql class", loggerTypes::ERROR); |
| 322 | 322 | throw new bptException('MYSQL_CONNECTION_NEEDED'); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * @return bool|string |
| 348 | 348 | * @throws bptException |
| 349 | 349 | */ |
| 350 | - public static function ezPay (float|int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool|string { |
|
| 350 | + public static function ezPay(float | int $amount, int $user_id = null, string $currency = 'usd', string $description = 'Invoice created by BPT library', bool $direct_url = false, bool $one_time_url = true): bool | string { |
|
| 351 | 351 | if (empty(self::$ipn_secret)) { |
| 352 | 352 | logger::write("crypto::ezPay function used\nyou must set ipn_secret to use this", loggerTypes::ERROR); |
| 353 | 353 | return false; |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | $user_id = $user_id ?? request::catchFields(fields::USER_ID); |
| 360 | 360 | $order_id = self::createOrder($amount, $user_id, $description); |
| 361 | 361 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::CALLBACK, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
| 362 | - $callback_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
| 362 | + $callback_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
| 363 | 363 | |
| 364 | 364 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::SUCCESS, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
| 365 | - $success_url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
| 365 | + $success_url = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
| 366 | 366 | |
| 367 | 367 | $invoice_id = self::createInvoice($amount, $currency, null, $callback_url, $order_id, $description, $success_url)->id; |
| 368 | 368 | |
@@ -381,17 +381,17 @@ discard block |
||
| 381 | 381 | ], ['id' => $order_id], 1); |
| 382 | 382 | |
| 383 | 383 | if ($direct_url) { |
| 384 | - return 'https://nowpayments.io/payment/?iid='. $invoice_id; |
|
| 384 | + return 'https://nowpayments.io/payment/?iid='.$invoice_id; |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | $data = ['type' => callbackTypes::CRYPTO, 'action_type' => cryptoCallbackActionTypes::REDIRECT, 'amount' => $amount, 'currency' => $currency, 'user_id' => $user_id, 'order_id' => $order_id]; |
| 388 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '?data='.urlencode(callback::encodeData($data)); |
|
| 388 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?data='.urlencode(callback::encodeData($data)); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
| 392 | 392 | * @internal Only for BPT self usage , Don't use it in your source! |
| 393 | 393 | */ |
| 394 | - public static function callbackProcess (array $data) { |
|
| 394 | + public static function callbackProcess(array $data) { |
|
| 395 | 395 | if (!isset($data['action_type'])) { |
| 396 | 396 | return false; |
| 397 | 397 | } |
@@ -411,16 +411,16 @@ discard block |
||
| 411 | 411 | BPT::exit('This link is one time only, Receive another link'); |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | - $url = 'https://nowpayments.io/payment/?iid='. $extra_info->invoice_id; |
|
| 414 | + $url = 'https://nowpayments.io/payment/?iid='.$extra_info->invoice_id; |
|
| 415 | 415 | |
| 416 | - @header('Location: ' . $url); |
|
| 416 | + @header('Location: '.$url); |
|
| 417 | 417 | die("<meta http-equiv='refresh' content='0; url=$url' /><script>window.location.href = '$url';</script>"); |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | if ($action_type === cryptoCallbackActionTypes::CALLBACK) { |
| 421 | 421 | $ipn = self::getIPN(); |
| 422 | 422 | |
| 423 | - if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID ) { |
|
| 423 | + if ($ipn->payment_status !== cryptoStatus::FINISHED && $ipn->payment_status !== cryptoStatus::PARTIALLY_PAID) { |
|
| 424 | 424 | die(); |
| 425 | 425 | } |
| 426 | 426 | |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | die(); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal); |
|
| 445 | + $paid = round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal); |
|
| 446 | 446 | $extra_info['related_payments'][$payment_id] = $paid; |
| 447 | 447 | $extra_info['total_paid'] += $paid; |
| 448 | 448 | mysql::update('orders', ['extra_info' => json_encode($extra_info)], ['id' => $order_id], 1); |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | 'description' => $order->description, |
| 505 | 505 | 'real_amount' => $order->amount, |
| 506 | 506 | 'currency' => $extra_info->currency, |
| 507 | - 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid/$payment->pay_amount*$payment->price_amount, self::$round_decimal), |
|
| 507 | + 'paid_amount' => round(isset($payment->actually_paid_at_fiat) && $payment->actually_paid_at_fiat > 0 ? $payment->actually_paid_at_fiat : $payment->actually_paid / $payment->pay_amount * $payment->price_amount, self::$round_decimal), |
|
| 508 | 508 | 'total_paid' => $extra_info->total_paid |
| 509 | 509 | ]; |
| 510 | 510 | $callback_data = object(...$callback_data); |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
| 19 | 19 | */ |
| 20 | - public static function init (int $log_size = 10): void { |
|
| 20 | + public static function init(int $log_size = 10): void { |
|
| 21 | 21 | self::$log_size = $log_size; |
| 22 | 22 | $log_file = realpath(settings::$name.'BPT.log'); |
| 23 | 23 | $mode = file_exists($log_file) && !(filesize($log_file) > self::$log_size * 1024 * 1024) ? 'a' : 'w'; |
| 24 | 24 | self::$handler = fopen(settings::$name.'BPT.log', $mode); |
| 25 | 25 | if ($mode === 'w') { |
| 26 | - fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 26 | + fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n"); |
|
| 27 | 27 | } |
| 28 | 28 | if (self::$waited_logs != []) { |
| 29 | 29 | foreach (self::$waited_logs as $log) { |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | 45 | public static function write(string $data, string $type = loggerTypes::NONE): void { |
| 46 | - $text = date('Y/m/d H:i:s') . ($type !== loggerTypes::NONE ? " : ⤵\n$type" : '') . " : $data\n\n"; |
|
| 46 | + $text = date('Y/m/d H:i:s').($type !== loggerTypes::NONE ? " : ⤵\n$type" : '')." : $data\n\n"; |
|
| 47 | 47 | if (!is_null(self::$handler)) { |
| 48 | 48 | fwrite(self::$handler, $text); |
| 49 | 49 | } |
@@ -46,8 +46,7 @@ |
||
| 46 | 46 | $text = date('Y/m/d H:i:s') . ($type !== loggerTypes::NONE ? " : ⤵\n$type" : '') . " : $data\n\n"; |
| 47 | 47 | if (!is_null(self::$handler)) { |
| 48 | 48 | fwrite(self::$handler, $text); |
| 49 | - } |
|
| 50 | - else { |
|
| 49 | + } else { |
|
| 51 | 50 | self::$waited_logs[] = $text; |
| 52 | 51 | } |
| 53 | 52 | } |
@@ -20,18 +20,18 @@ |
||
| 20 | 20 | public string $description; |
| 21 | 21 | |
| 22 | 22 | /** @var int|float Real amount or known as requested amount */ |
| 23 | - public int|float $real_amount; |
|
| 23 | + public int | float $real_amount; |
|
| 24 | 24 | |
| 25 | 25 | /** @var string Fiat currency(aka usd, euro, ...) */ |
| 26 | 26 | public string $currency; |
| 27 | 27 | |
| 28 | 28 | /** @var int|float Paid amount in this payment */ |
| 29 | - public int|float $paid_amount; |
|
| 29 | + public int | float $paid_amount; |
|
| 30 | 30 | |
| 31 | 31 | /** @var int|float Total paid amount for the order id */ |
| 32 | - public int|float $total_paid; |
|
| 32 | + public int | float $total_paid; |
|
| 33 | 33 | |
| 34 | - public function __construct(stdClass|null $object = null) { |
|
| 34 | + public function __construct(stdClass | null $object = null) { |
|
| 35 | 35 | if ($object != null) { |
| 36 | 36 | parent::__construct($object, self::subs); |
| 37 | 37 | } |
@@ -17,17 +17,17 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @internal Only for BPT self usage , Don't use it in your source! |
| 19 | 19 | */ |
| 20 | - public static function init(string $method,array $data) { |
|
| 20 | + public static function init(string $method, array $data) { |
|
| 21 | 21 | $info = self::getInfo($data); |
| 22 | 22 | $data = $info['data']; |
| 23 | 23 | $handler = $info['handler']; |
| 24 | - self::setTimeout($data,$handler,$method); |
|
| 24 | + self::setTimeout($data, $handler, $method); |
|
| 25 | 25 | self::setData($data); |
| 26 | 26 | $data['method'] = $method; |
| 27 | 27 | curl_setopt($handler, CURLOPT_POSTFIELDS, $data); |
| 28 | 28 | $result = curl_exec($handler); |
| 29 | 29 | if (curl_errno($handler)) { |
| 30 | - logger::write(curl_error($handler),loggerTypes::WARNING); |
|
| 30 | + logger::write(curl_error($handler), loggerTypes::WARNING); |
|
| 31 | 31 | } |
| 32 | 32 | if ($info['token'] != settings::$token) { |
| 33 | 33 | curl_close($handler); |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 45 | 45 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 46 | 46 | } |
| 47 | - else{ |
|
| 47 | + else { |
|
| 48 | 48 | $token = settings::$token; |
| 49 | - if (!isset(self::$curl_handler)){ |
|
| 49 | + if (!isset(self::$curl_handler)) { |
|
| 50 | 50 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
| 51 | 51 | curl_setopt(self::$curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 52 | 52 | curl_setopt(self::$curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | ]; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - private static function setTimeout(array &$data , CurlHandle $curl_handler,string $method): void { |
|
| 65 | + private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method): void { |
|
| 66 | 66 | if (isset($data['forgot'])) { |
| 67 | 67 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 68 | 68 | unset($data['forgot']); |
| 69 | 69 | } |
| 70 | - elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
| 70 | + elseif ($method === 'getUpdates' || $method === 'setWebhook') { |
|
| 71 | 71 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 72 | 72 | } |
| 73 | 73 | elseif (settings::$base_timeout > 0) { |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | private static function setData(array &$data): void { |
| 79 | - foreach ($data as &$value){ |
|
| 80 | - if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){ |
|
| 79 | + foreach ($data as &$value) { |
|
| 80 | + if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) { |
|
| 81 | 81 | $value = json_encode($value); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | $curl_handler = curl_init(settings::$base_url."/bot$token/"); |
| 44 | 44 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
| 45 | 45 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
| 46 | - } |
|
| 47 | - else{ |
|
| 46 | + } else{ |
|
| 48 | 47 | $token = settings::$token; |
| 49 | 48 | if (!isset(self::$curl_handler)){ |
| 50 | 49 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
@@ -66,11 +65,9 @@ discard block |
||
| 66 | 65 | if (isset($data['forgot'])) { |
| 67 | 66 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
| 68 | 67 | unset($data['forgot']); |
| 69 | - } |
|
| 70 | - elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
| 68 | + } elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
| 71 | 69 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
| 72 | - } |
|
| 73 | - elseif (settings::$base_timeout > 0) { |
|
| 70 | + } elseif (settings::$base_timeout > 0) { |
|
| 74 | 71 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$base_timeout); |
| 75 | 72 | } |
| 76 | 73 | } |
@@ -825,30 +825,30 @@ discard block |
||
| 825 | 825 | 'getGameHighScores' => ['BPT\types\gameHighScore'] |
| 826 | 826 | ]; |
| 827 | 827 | |
| 828 | - public static function __callStatic (string $name, array $arguments) { |
|
| 828 | + public static function __callStatic(string $name, array $arguments) { |
|
| 829 | 829 | if (!$action = self::methodAction($name)) { |
| 830 | - logger::write("$name method is not supported",loggerTypes::ERROR); |
|
| 830 | + logger::write("$name method is not supported", loggerTypes::ERROR); |
|
| 831 | 831 | throw new bptException('METHOD_NOT_FOUND'); |
| 832 | 832 | } |
| 833 | 833 | self::checkArguments($arguments); |
| 834 | - self::keysName($action,$arguments); |
|
| 835 | - self::readyFile($action,$arguments); |
|
| 834 | + self::keysName($action, $arguments); |
|
| 835 | + self::readyFile($action, $arguments); |
|
| 836 | 836 | self::cleanArguments($arguments); |
| 837 | - self::setDefaults($action,$arguments); |
|
| 837 | + self::setDefaults($action, $arguments); |
|
| 838 | 838 | |
| 839 | 839 | if (isset($arguments['answer']) && $arguments['answer'] === true) { |
| 840 | 840 | unset($arguments['answer']); |
| 841 | 841 | if (!answer::isAnswered()) { |
| 842 | - return answer::init($action,$arguments); |
|
| 842 | + return answer::init($action, $arguments); |
|
| 843 | 843 | } |
| 844 | - logger::write('you can use answer mode only once for each webhook update, Others will be called like normal',loggerTypes::WARNING); |
|
| 844 | + logger::write('you can use answer mode only once for each webhook update, Others will be called like normal', loggerTypes::WARNING); |
|
| 845 | 845 | } |
| 846 | - $result = curl::init($action,$arguments); |
|
| 846 | + $result = curl::init($action, $arguments); |
|
| 847 | 847 | if (!is_object($result)) { |
| 848 | - logger::write("Telegram $action method failed : " . $result, loggerTypes::WARNING); |
|
| 848 | + logger::write("Telegram $action method failed : ".$result, loggerTypes::WARNING); |
|
| 849 | 849 | return false; |
| 850 | 850 | } |
| 851 | - return self::processResponse($action,$result); |
|
| 851 | + return self::processResponse($action, $result); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | private static function checkArguments(array &$arguments): void { |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - private static function keysName (string $name, array &$arguments): void { |
|
| 860 | + private static function keysName(string $name, array &$arguments): void { |
|
| 861 | 861 | foreach ($arguments as $key => $argument) { |
| 862 | 862 | if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) { |
| 863 | 863 | $arguments[self::METHODS_KEYS[$name][$key]] = $argument; |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - private static function methodAction(string $name): string|false { |
|
| 869 | + private static function methodAction(string $name): string | false { |
|
| 870 | 870 | return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false; |
| 871 | 871 | } |
| 872 | 872 | |
@@ -902,11 +902,11 @@ discard block |
||
| 902 | 902 | } |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - private static function methodFile(string $name): array|false { |
|
| 905 | + private static function methodFile(string $name): array | false { |
|
| 906 | 906 | return self::METHODS_WITH_FILE[$name] ?? false; |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - private static function methodReturn(string $name,stdClass $response) { |
|
| 909 | + private static function methodReturn(string $name, stdClass $response) { |
|
| 910 | 910 | if (!settings::$use_types_classes) { |
| 911 | 911 | return $response; |
| 912 | 912 | } |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | $defaults = self::METHODS_EXTRA_DEFAULTS[$name] ?? []; |
| 929 | 929 | foreach ($defaults as $key => $default) { |
| 930 | 930 | if (is_numeric($key)) { |
| 931 | - if (!isset($arguments[$default])){ |
|
| 931 | + if (!isset($arguments[$default])) { |
|
| 932 | 932 | $arguments[$default] = self::catchFields($default); |
| 933 | 933 | } |
| 934 | 934 | } |
| 935 | 935 | elseif (isset(BPT::$update->$key) || $key === 'other') { |
| 936 | 936 | foreach ($default as $def) { |
| 937 | - if (!isset($arguments[$def])){ |
|
| 937 | + if (!isset($arguments[$def])) { |
|
| 938 | 938 | $arguments[$def] = self::catchFields($def); |
| 939 | 939 | } |
| 940 | 940 | } |
@@ -953,14 +953,14 @@ discard block |
||
| 953 | 953 | self::$status = $response->ok; |
| 954 | 954 | self::$pure_response = $response; |
| 955 | 955 | if (!$response->ok) { |
| 956 | - logger::write("Telegram $name method failed : " . json_encode($response), loggerTypes::WARNING); |
|
| 956 | + logger::write("Telegram $name method failed : ".json_encode($response), loggerTypes::WARNING); |
|
| 957 | 957 | unset($response->ok); |
| 958 | 958 | return new responseError($response); |
| 959 | 959 | } |
| 960 | - return self::methodReturn($name,$response); |
|
| 960 | + return self::methodReturn($name, $response); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - private static function cleanArguments (array &$arguments): void { |
|
| 963 | + private static function cleanArguments(array &$arguments): void { |
|
| 964 | 964 | foreach ($arguments as $key => $argument) { |
| 965 | 965 | if ($argument == [] || $argument === null) { |
| 966 | 966 | unset($arguments[$key]); |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | * |
| 976 | 976 | * @return int|string|bool |
| 977 | 977 | */ |
| 978 | - public static function catchFields (string $field): int|string|bool { |
|
| 978 | + public static function catchFields(string $field): int | string | bool { |
|
| 979 | 979 | switch ($field) { |
| 980 | 980 | case fields::CHAT_ID : |
| 981 | 981 | case fields::FROM_CHAT_ID : |
@@ -1122,13 +1122,13 @@ discard block |
||
| 1122 | 1122 | default => false |
| 1123 | 1123 | }; |
| 1124 | 1124 | case fields::URL : |
| 1125 | - return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
|
| 1125 | + return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
|
| 1126 | 1126 | default: |
| 1127 | 1127 | return false; |
| 1128 | 1128 | } |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | - public static function fileLink (string|null $file_id = null): bool|string { |
|
| 1131 | + public static function fileLink(string | null $file_id = null): bool | string { |
|
| 1132 | 1132 | $file = request::getFile($file_id); |
| 1133 | 1133 | if (!isset($file->file_path)) { |
| 1134 | 1134 | return false; |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | * |
| 1151 | 1151 | * @return bool |
| 1152 | 1152 | */ |
| 1153 | - public static function downloadFile (string $destination, string|null $file_id = null): bool { |
|
| 1153 | + public static function downloadFile(string $destination, string | null $file_id = null): bool { |
|
| 1154 | 1154 | return tools::downloadFile(self::fileLink($file_id), $destination); |
| 1155 | 1155 | } |
| 1156 | 1156 | |
@@ -1168,10 +1168,10 @@ discard block |
||
| 1168 | 1168 | * |
| 1169 | 1169 | * @return message|bool|responseError |
| 1170 | 1170 | */ |
| 1171 | - public static function sendFile (string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message|bool|responseError { |
|
| 1171 | + public static function sendFile(string $file_id, int | string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup | replyKeyboardMarkup | replyKeyboardRemove | forceReply | stdClass | array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message | bool | responseError { |
|
| 1172 | 1172 | $type = tools::fileType($file_id); |
| 1173 | 1173 | return match ($type) { |
| 1174 | - fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false,null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
|
| 1174 | + fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
|
| 1175 | 1175 | fileTypes::VIDEO_NOTE => request::sendVideoNote($file_id, $chat_id, $message_thread_id, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
| 1176 | 1176 | fileTypes::ANIMATION => request::sendAnimation($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |
| 1177 | 1177 | fileTypes::AUDIO => request::sendAudio($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, null, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer), |