├── .idea ├── .gitignore ├── encodings.xml ├── modules.xml ├── php-parasut-api-v4.iml └── vcs.xml ├── README.md ├── composer.json ├── src ├── Accounts.php ├── Authorization.php ├── Contacts.php ├── Exception.php ├── Invoices.php ├── Products.php ├── Request.php └── authorization.ini └── tests ├── ContactsTest.php ├── InvoicesTest.php └── ProductsTest.php /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/php-parasut-api-v4.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Parasut API PHP 2 | 3 | **Kaynak : https://apidocs.parasut.com** 4 | 5 | ## Kurulum 6 | ``` 7 | composer require inpinos/php-parasut-api-v4 8 | ``` 9 | 10 | ## Kullanımı 11 | 12 | ```php 13 | true, //development mode 20 | "client_id" => "YOUR_CLIENT_ID", 21 | "client_secret" => "YOUR_CLIENT_SECRET", 22 | "username" => "YOUR_EMAIL", 23 | "password" => "YOUR_PASSWORD", 24 | "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob", 25 | "company_id" => "YOUR_COMPANY_ID" 26 | ]); 27 | } catch (\Parasut\API\Exception $e) { 28 | echo "Error code : " . $e->getCode()."
"; 29 | echo "Error message : " . $e->getMessage(); 30 | die; 31 | } 32 | ``` 33 | 34 | ### Müşteri İşlemleri 35 | ```php 36 | $contacts = new \Parasut\API\Contacts($parasutAuthorization); 37 | ``` 38 | 39 | - Müşteri listesi 40 | ```php 41 | $contactList = $contacts->list_contacts(); 42 | ``` 43 | 44 | - Müşteri görüntüleme 45 | ```php 46 | $contact_id = 123456; 47 | $showContact = $contacts->show($contact_id); 48 | ``` 49 | 50 | - Müşteri arama 51 | ```php 52 | $searchContactData1 = [ 53 | "name" => "XXXX" 54 | ]; 55 | 56 | $searchContactData2 = [ 57 | "name" => "XXXX", 58 | "email" => "XXXX" 59 | ]; 60 | 61 | $searchContactData3 = [ 62 | "name" => "XXXX", 63 | "email" => "XXXX", 64 | "tax_number" => "XXXX", 65 | "tax_office" => "XXXX", 66 | "city" => "XXXX", 67 | "account_type" => "customer" //customer, supplier 68 | ]; 69 | $searchContact1 = $contacts->search($searchContactData1); 70 | $searchContact2 = $contacts->search($searchContactData2); 71 | $searchContact3 = $contacts->search($searchContactData3); 72 | ``` 73 | 74 | - Yeni müşteri oluşturma 75 | ```php 76 | $createContactData = [ 77 | "data" => [ 78 | "type" => "contacts", 79 | "attributes" => [ 80 | "name" => "XXXX", //*zorunlu //ad soyad 81 | "email" => "XXXX", //e-posta 82 | "contact_type" => "person", //company, person (tüzel kişi, gerçek kişi) 83 | "tax_office" => "XXX", //vergi dairesi 84 | "tax_number" => "XXX", //vergi numarası 85 | "district" => "XXX", //ilçe 86 | "city" => "XXX", //il 87 | "address" => "XXX", //adres 88 | "phone" => "0XXXXXXXXXX", //tel no 89 | "account_type" => "customer" //customer, supplier 90 | ] 91 | ] 92 | ]; 93 | $createContact = $contacts->create($createContactData); 94 | ``` 95 | 96 | - Müşteri düzenleme 97 | ```php 98 | $contact_id = 123456; //integer 99 | $editContactData = [ 100 | "data" => [ 101 | "type" => "contacts", 102 | "attributes" => [ 103 | "name" => "XXXX", //*required //ad soyad 104 | "email" => "XXXX", //e-posta 105 | "contact_type" => "person", //company, person (tüzel kişi, gerçek kişi) 106 | "tax_office" => "XXX", //vergi dairesi 107 | "tax_number" => "XXX", //vergi numarası 108 | "district" => "XXX", //ilçe 109 | "city" => "XXX", //il 110 | "address" => "XXX", //adres 111 | "phone" => "0XXXXXXXXXX", //tel no 112 | "account_type" => "customer" //customer, supplier 113 | ] 114 | ] 115 | ]; 116 | $editContact = $contacts->edit($contact_id, $editContactData); 117 | ``` 118 | 119 | - Müşteri silme 120 | ```php 121 | $contact_id = 123456; //integer 122 | $deleteContact = $contacts->delete($contact_id); 123 | ``` 124 | 125 | ### Fatura İşlemleri 126 | ```php 127 | $invoices = new \Parasut\API\Invoices($parasutAuthorization); 128 | ``` 129 | 130 | - Satış faturası listesi 131 | ```php 132 | $invoiceList = $invoices->list_invoices(); 133 | ``` 134 | 135 | - Satış faturası görüntüleme 136 | ```php 137 | $invoice_id = 123456; //integer 138 | $showInvoice = $invoices->show($invoice_id); //active_e_document,contact parametreleri ile beraber gelir 139 | ``` 140 | 141 | - Satış faturası arama 142 | ```php 143 | $searchInvoiceData1 = [ 144 | "invoice_id" => "XXXX" 145 | ]; 146 | 147 | $searchInvoiceData2 = [ 148 | "invoice_id" => "XXXX", 149 | "contact_id" => "XXXX" 150 | ]; 151 | 152 | $searchInvoiceData3 = [ 153 | "issue_date" => "XXXX", 154 | "due_date" => "XXXX", 155 | "contact_id" => "XXXX", 156 | "invoice_id" => "XXXX", 157 | "invoice_series" => "XXXX", 158 | "item_type" => "invoice", 159 | "print_status" => "printed", //printed, not_printed, invoices_not_sent, e_invoice_sent, e_archive_sent, e_smm_sent 160 | "payment_status" => "paid" //overdue, not_due, unscheduled, paid 161 | ]; 162 | $searchInvoice1 = $invoices->search($searchInvoiceData1); 163 | $searchInvoice2 = $invoices->search($searchInvoiceData2); 164 | $searchInvoice3 = $invoices->search($searchInvoiceData3); 165 | ``` 166 | 167 | - Satış faturası oluşturma 168 | ```php 169 | $createInvoiceData = [ 170 | "data" => [ 171 | "type" => "sales_invoices", 172 | "attributes" => [ 173 | "item_type" => "invoice", 174 | "description" => "XXXX XXXX XXXX", //fatura açıklaması 175 | "issue_date" => "YYYY-MM-DD", //düzenleme tarihi 176 | "due_date" => "YYYY-MM-DD", //son tahsilat tarihi 177 | "invoice_series" => "XXX", //fatura seri no 178 | "invoice_id" => "XXX", //fatura sıra no 179 | "currency" => "TRL", //döviz tipi // TRL, USD, EUR, GBP 180 | "shipment_included" => false, //irsaliye 181 | ], 182 | "relationships" => [ 183 | "details" => [ 184 | "data" => [ 185 | 0 => [ 186 | "type" => "sales_invoice_details", 187 | "attributes" => [ 188 | "quantity" => 1, //birim adedi 189 | "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 190 | "vat_rate" => 18, //kdv oranı 191 | "description" => "XXXXX" //ürün açıklaması 192 | ], 193 | "relationships" => [ 194 | "product" => [ 195 | "data" => [ 196 | "id" => 123456, //ürün id 197 | "type" => "products" 198 | ] 199 | ] 200 | ] 201 | ] 202 | ] 203 | ], 204 | "contact" => [ 205 | "data" => [ 206 | "type" => "contacts", 207 | "id" => 123456 //müşteri id 208 | ] 209 | ] 210 | ] 211 | ] 212 | ]; 213 | $createInvoice = $invoices->create($createInvoiceData); 214 | ``` 215 | 216 | - Satış faturası düzenleme 217 | ```php 218 | $editInvoiceData = [ 219 | "data" => [ 220 | "type" => "sales_invoices", 221 | "attributes" => [ 222 | "item_type" => "invoice", 223 | "description" => "XXXX XXXX XXXX", //fatura açıklaması 224 | "issue_date" => "YYYY-MM-DD", //düzenleme tarihi 225 | "due_date" => "YYYY-MM-DD", //son tahsilat tarihi 226 | "invoice_series" => "XXX", //fatura seri no 227 | "invoice_id" => "XXX", //fatura sıra no 228 | "currency" => "TRL", //döviz tipi // TRL, USD, EUR, GBP 229 | "shipment_included" => false, //irsaliye 230 | ], 231 | "relationships" => [ 232 | "details" => [ 233 | "data" => [ 234 | 0 => [ 235 | "type" => "sales_invoice_details", 236 | "attributes" => [ 237 | "quantity" => 1, //birim adedi 238 | "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 239 | "vat_rate" => 18, //kdv oranı 240 | "description" => "XXXXX" //ürün açıklaması 241 | ], 242 | "relationships" => [ 243 | "product" => [ 244 | "data" => [ 245 | "id" => 123456, //ürün id 246 | "type" => "products" 247 | ] 248 | ] 249 | ] 250 | ] 251 | ] 252 | ], 253 | "contact" => [ 254 | "data" => [ 255 | "type" => "contacts", 256 | "id" => 123456 //müşteri id 257 | ] 258 | ] 259 | ] 260 | ] 261 | ]; 262 | 263 | $invoice_id = 123456; 264 | $editInvoice = $invoices->edit($invoice_id, $editInvoiceData); 265 | ``` 266 | 267 | - Satış faturası silme 268 | ```php 269 | $invoice_id = 123456; 270 | $deleteInvoice = $invoices->delete($invoice_id); 271 | ``` 272 | 273 | - Satış faturası iptal etme 274 | ```php 275 | $invoice_id = 123456; 276 | $cancelInvoice = $invoices->cancel($invoice_id); 277 | ``` 278 | 279 | - Satış faturasına tahsilat ekleme 280 | ```php 281 | $invoice_id = 123456; 282 | $payInvoiceData = [ 283 | "data" => [ 284 | "type" => "payments", 285 | "attributes" => [ 286 | "account_id" => 1234, // Kasa veya Banka id 287 | "date" => "YYYY-MM-DD", //ödeme tarihi 288 | "amount" => 123 //ödeme tutarı 289 | ] 290 | ] 291 | ]; 292 | $invoices->pay($invoice_id, $payInvoiceData); 293 | ``` 294 | 295 | - Satış faturasını resmileştirme 296 | ```php 297 | /* 298 | * VKN e-fatura sistemine kayıtlıysa resmileştirme işleminde e-fatura olarak işlem yapılır 299 | * değilse e-arşive olarak işlem yapılır 300 | */ 301 | $vkn = 12345678912; 302 | $checkVKNType = $invoices->check_vkn_type($vkn); 303 | 304 | //VKN e-fatura sistemine kayıtlı değil 305 | if (empty($checkVKNType->result)) 306 | { 307 | $eArchiveData = [ 308 | "data" => [ 309 | "type" => "e_archives", 310 | "relationships" => [ 311 | "sales_invoice" => [ 312 | "data" => [ 313 | "id" => 123456, //invoice_id 314 | "type" => "sales_invoices" 315 | ] 316 | ] 317 | ] 318 | ] 319 | ]; 320 | $createEArchive = $invoices->create_e_archive($eArchiveData); 321 | } 322 | //VKN e-fatura sistemine kayıtlı 323 | else 324 | { 325 | $vkn = 12345678912; 326 | $checkVKNType = $invoices->check_vkn_type($vkn); 327 | $eInvoiceAddress = $checkVKNType->result->data[0]->attributes->e_invoice_address; 328 | 329 | $eInvoiceData = [ 330 | "data" => [ 331 | "type" => "e_invoices", 332 | "attributes" => [ 333 | 'scenario' => 'basic', // basic veya commercial (temel veya ticari) 334 | 'to' => $eInvoiceAddress 335 | ], 336 | "relationships" => [ 337 | "invoice" => [ 338 | "data" => [ 339 | "id" => 123456, //invoice_id 340 | "type" => "sales_invoices" 341 | ] 342 | ] 343 | ] 344 | ] 345 | ]; 346 | $createEInvoice = $invoices->create_e_invoice($eInvoiceData); 347 | } 348 | ``` 349 | 350 | - E-Arşiv görüntüleme 351 | ```php 352 | $e_archive_id = 123456; //invoice_id değildir. 353 | $showEArchive = $invoices->show_e_archive($e_archive_id); 354 | ``` 355 | 356 | - E-Arşiv PDF olarak görüntüleme 357 | ```php 358 | $e_archive_id = 123456; //invoice_id değildir. 359 | $pdfEArchive = $invoices->pdf_e_archive($e_archive_id); 360 | ``` 361 | 362 | - E-Fatura görüntüleme 363 | ```php 364 | $e_invoice_id = 123456; //invoice_id değildir. 365 | $showEArchive = $invoices->show_e_invoice($e_invoice_id); 366 | ``` 367 | 368 | - E-Fatura PDF olarak görüntüleme 369 | ```php 370 | $e_invoice_id = 123456; //invoice_id değildir. 371 | $pdfEArchive = $invoices->pdf_e_invoice($e_invoice_id); 372 | ``` 373 | 374 | ### Ürün İşlemleri 375 | ```php 376 | $products = new \Parasut\API\Products($parasutAuthorization); 377 | ``` 378 | 379 | - Ürün listesi 380 | ```php 381 | $productList = $products->list_products(); 382 | ``` 383 | 384 | - Ürün görüntüleme 385 | ```php 386 | $product_id = 123456; 387 | $showProduct = $products->show($product_id); 388 | ``` 389 | 390 | - Ürün arama 391 | ```php 392 | $searchProductData1 = [ 393 | "name" => "XXXX" 394 | ]; 395 | 396 | $searchProductData2 = [ 397 | "name" => "XXXX", 398 | "code" => "XXXX" 399 | ]; 400 | 401 | $searchProduct1 = $products->search($searchProductData1); 402 | $searchProduct2 = $products->search($searchProductData2); 403 | ``` 404 | 405 | - Yeni ürün oluşturma 406 | ```php 407 | $productData = [ 408 | "data" => [ 409 | "type" => "products", 410 | "attributes" => [ 411 | "name" => "XXXX", //ürün adı 412 | "vat_rate" => 18, //KDV oranı 413 | "unit" => "Adet", //birim 414 | "currency" => "TRL", //döviz tipi 415 | "inventory_tracking" => true, //stok durumu 416 | "initial_stock_count" => 100 //stok adedi 417 | ] 418 | ] 419 | ]; 420 | $createProduct = $products->create($productData); 421 | ``` 422 | 423 | - Ürün düzenleme 424 | ```php 425 | $productData = [ 426 | "data" => [ 427 | "type" => "products", 428 | "attributes" => [ 429 | "name" => "XXXX", //ürün adı 430 | "vat_rate" => 18, //KDV oranı 431 | "unit" => "Adet", //birim 432 | "currency" => "TRL", //döviz tipi 433 | "inventory_tracking" => true, //stok durumu 434 | "initial_stock_count" => 100 //stok adedi 435 | ] 436 | ] 437 | ]; 438 | 439 | $product_id = 123456; 440 | $editProduct = $products->edit($product_id, $productData); 441 | ``` 442 | 443 | - Ürün silme 444 | ```php 445 | $product_id = 123456; 446 | $deleteProduct = $products->delete($product_id); 447 | ``` 448 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inpinos/php-parasut-api-v4", 3 | "description": "Parasut API Version 4", 4 | "type": "library", 5 | "license": "MIT", 6 | "minimum-stability": "stable", 7 | "authors": [ 8 | { 9 | "name": "Esat Köseoğlu", 10 | "email": "ekoseoglu22@gmail.com" 11 | } 12 | ], 13 | "autoload": { 14 | "psr-4": { 15 | "Parasut\\API\\": "src" 16 | } 17 | }, 18 | "require": { 19 | "php": ">=5.6", 20 | "ext-json": "*", 21 | "ext-curl": "*" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Accounts.php: -------------------------------------------------------------------------------- 1 | connector = $connector; 15 | } 16 | 17 | /** 18 | * @param int $page 19 | * @param int $size 20 | * @return array|\stdClass 21 | */ 22 | public function list_accounts($page = 1, $size = 25) 23 | { 24 | return $this->connector->request( 25 | "accounts?page[number]=$page&page[size]=$size", 26 | [], 27 | "GET" 28 | ); 29 | } 30 | 31 | /** 32 | * @param $account_id 33 | * @return array|\stdClass 34 | */ 35 | public function show($account_id) 36 | { 37 | return $this->connector->request( 38 | 'accounts/' . $account_id, 39 | [], 40 | "GET" 41 | ); 42 | } 43 | 44 | /** 45 | * @param array $data 46 | * @return array|\stdClass 47 | */ 48 | public function search($data) 49 | { 50 | $filter = null; 51 | foreach ($data as $key => $value) 52 | { 53 | if (end($data) == $value) 54 | $filter .= "filter[$key]=".urlencode($value); 55 | else 56 | $filter .= "filter[$key]=".urlencode($value)."&"; 57 | } 58 | 59 | return $this->connector->request( 60 | 'accounts?'.$filter, 61 | [], 62 | "GET" 63 | ); 64 | } 65 | 66 | /** 67 | * @param $data 68 | * @return array|\stdClass 69 | */ 70 | public function create($data) 71 | { 72 | return $this->connector->request( 73 | 'accounts', 74 | $data, 75 | "POST" 76 | ); 77 | } 78 | 79 | /** 80 | * @param $account_id 81 | * @param array $data 82 | * @return array|\stdClass 83 | */ 84 | public function edit($account_id, $data = []) 85 | { 86 | return $this->connector->request( 87 | 'accounts/' . $account_id, 88 | $data, 89 | "PUT" 90 | ); 91 | } 92 | 93 | /** 94 | * @param $account_id 95 | * @return array|\stdClass 96 | */ 97 | public function delete($account_id) 98 | { 99 | return $this->connector->request( 100 | 'accounts/' . $account_id, 101 | [], 102 | "DELETE" 103 | ); 104 | } 105 | 106 | /** 107 | * @param $account_id 108 | * @return array|\stdClass 109 | */ 110 | public function list_transactions($account_id) 111 | { 112 | return $this->connector->request( 113 | 'accounts/' . $account_id . '/transactions?include=debit_account,credit_account', 114 | [], 115 | "GET" 116 | ); 117 | } 118 | 119 | /** 120 | * @param $account_id 121 | * @param $data 122 | * @return array|\stdClass 123 | */ 124 | public function import_transactions($account_id, $data) 125 | { 126 | return $this->connector->request( 127 | 'accounts/' . $account_id . '/debit_transactions', 128 | $data, 129 | "POST" 130 | ); 131 | } 132 | 133 | /** 134 | * @param $account_id 135 | * @param $data 136 | * @return array|\stdClass 137 | */ 138 | public function export_transactions($account_id, $data) 139 | { 140 | return $this->connector->request( 141 | 'accounts/' . $account_id . '/credit_transactions', 142 | $data, 143 | "POST" 144 | ); 145 | } 146 | 147 | /** 148 | * @param $transaction_id 149 | * @return array|\stdClass 150 | */ 151 | public function show_transactions($transaction_id) 152 | { 153 | return $this->connector->request( 154 | 'transactions/' . $transaction_id, 155 | [], 156 | "GET" 157 | ); 158 | } 159 | 160 | /** 161 | * @param $transaction_id 162 | * @return array|\stdClass 163 | */ 164 | public function delete_transactions($transaction_id) 165 | { 166 | return $this->connector->request( 167 | 'transactions/' . $transaction_id, 168 | [], 169 | "DELETE" 170 | ); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/Authorization.php: -------------------------------------------------------------------------------- 1 | checkConfigData($config); 28 | 29 | $authorizationFile = __DIR__."/".$this->authorization_file_name; 30 | 31 | //if not exists authorization.ini 32 | if (!file_exists($authorizationFile)) 33 | file_put_contents($authorizationFile, ""); 34 | 35 | //configuration variables 36 | $this->config = $config; 37 | $this->api_url = (isset($config["development"]) && $config["development"]) ? $this->DEMO_URL : $this->LIVE_URL; //demo or live 38 | $this->company_id = $this->config["company_id"]; 39 | $this->config["grant_type"] = $this->grant_type; 40 | $this->ini_file = $authorizationFile; 41 | 42 | //check authorize 43 | $this->checkAuthorization(); 44 | } 45 | 46 | /** 47 | * Check the configuration data 48 | * @throws Exception 49 | */ 50 | private function checkConfigData($config) 51 | { 52 | if (!isset($config["client_id"])) 53 | throw new \Parasut\API\Exception("`client_id` parameter missing", 400); 54 | 55 | if (!isset($config["redirect_uri"])) 56 | throw new \Parasut\API\Exception("`redirect_uri` parameter missing", 400); 57 | 58 | if (!isset($config["company_id"])) 59 | throw new \Parasut\API\Exception("`company_id` parameter missing", 400); 60 | 61 | if (!isset($config["username"])) 62 | throw new \Parasut\API\Exception("`username` parameter missing",400); 63 | 64 | if (!isset($config["password"])) 65 | throw new \Parasut\API\Exception("`password` parameter missing", 400); 66 | } 67 | 68 | /** 69 | * Check Authorization 70 | * @return void 71 | * @throws \Parasut\API\Exception 72 | */ 73 | private function checkAuthorization() 74 | { 75 | $tokens = parse_ini_file($this->ini_file); 76 | 77 | if (empty($tokens)) { 78 | $this->accessAuthorization(); 79 | return; 80 | } 81 | 82 | if (isset($tokens['company_id']) && md5($tokens['company_id']) !== md5($this->company_id)) 83 | { 84 | $this->accessAuthorization(); 85 | return; 86 | } 87 | 88 | if (!isset($tokens['access_token'])) { 89 | $this->accessAuthorization(); 90 | return; 91 | } 92 | 93 | if (!isset($tokens['created_at']) || time() - intval($tokens['created_at']) > 7200) { 94 | $this->accessAuthorization(); 95 | return; 96 | } 97 | 98 | $this->access_token = $tokens['access_token']; 99 | } 100 | 101 | /** 102 | * Access Authorization 103 | * @throws \Parasut\API\Exception 104 | */ 105 | private function accessAuthorization() 106 | { 107 | $ch = curl_init(); 108 | curl_setopt($ch, CURLOPT_URL, $this->api_url.'/oauth/token'); 109 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 110 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 111 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 112 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 113 | curl_setopt($ch, CURLOPT_HEADER, false); 114 | curl_setopt($ch, CURLOPT_POST, "POST"); 115 | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->config); 116 | $jsonData = curl_exec($ch); 117 | $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 118 | $responseData = json_decode($jsonData, true); 119 | curl_close($ch); 120 | 121 | if ($responseCode === 200) 122 | { 123 | $authorizationText = null; 124 | foreach ($responseData as $key => $value) 125 | $authorizationText .= $key.'='.$value."\n"; 126 | 127 | $authorizationText .= "company_id=".md5($this->company_id)."\n"; 128 | file_put_contents($this->ini_file, $authorizationText); 129 | 130 | $this->access_token = $responseData['access_token']; 131 | } 132 | else 133 | { 134 | throw new \Parasut\API\Exception($responseData["error_description"], $responseCode); 135 | } 136 | } 137 | 138 | /** 139 | * @param $path 140 | * @param null $params 141 | * @param $method 142 | * @return array|\stdClass 143 | */ 144 | public function request($path, $params = null, $method) 145 | { 146 | $curlURI = $this->api_url.'/'.$this->version.'/'.$this->company_id.'/'.$path; 147 | 148 | $response = []; 149 | if ($method === "GET") 150 | $response = $this->__getRequest($curlURI, $params, $this->access_token); 151 | 152 | if ($method === "POST") 153 | $response = $this->__postRequest($curlURI, $params, $this->access_token); 154 | 155 | if ($method === "PUT") 156 | $response = $this->__putRequest($curlURI, $params, $this->access_token); 157 | 158 | if ($method === "DELETE") 159 | $response = $this->__deleteRequest($curlURI, $params, $this->access_token); 160 | 161 | return $response; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/Contacts.php: -------------------------------------------------------------------------------- 1 | connector = $connector; 15 | } 16 | 17 | /** 18 | * @param int $page 19 | * @param int $size 20 | * @return array|\stdClass 21 | */ 22 | public function list_contacts($page = 1, $size = 25) 23 | { 24 | return $this->connector->request( 25 | "contacts?page[number]=$page&page[size]=$size", 26 | [], 27 | "GET" 28 | ); 29 | } 30 | 31 | /** 32 | * Contact total count 33 | * @return integer 34 | */ 35 | public function count_contacts() 36 | { 37 | return $this->connector->request( 38 | "contacts?page[number]=1&page[size]=2", 39 | [], 40 | "GET" 41 | )->result->meta->total_count; 42 | } 43 | 44 | /** 45 | * Show contact 46 | * @param $contact_id 47 | * @return array|\stdClass 48 | */ 49 | public function show($contact_id) 50 | { 51 | return $this->connector->request( 52 | "contacts/$contact_id", 53 | [], 54 | "GET" 55 | ); 56 | } 57 | 58 | /** 59 | * Search contact with params 60 | * @param array $data 61 | * @return array|\stdClass 62 | */ 63 | public function search($data = []) 64 | { 65 | $filter = null; 66 | foreach ($data as $key => $value) 67 | { 68 | if (end($data) == $value) 69 | $filter .= "filter[$key]=".urlencode($value); 70 | else 71 | $filter .= "filter[$key]=".urlencode($value)."&"; 72 | } 73 | 74 | return $this->connector->request( 75 | "contacts?$filter", 76 | [], 77 | "GET" 78 | ); 79 | } 80 | 81 | /** 82 | * Create contact 83 | * @param $data 84 | * @return array|\stdClass 85 | */ 86 | public function create($data) 87 | { 88 | return $this->connector->request( 89 | "contacts", 90 | $data, 91 | "POST" 92 | ); 93 | } 94 | 95 | /** 96 | * Edit contact 97 | * @param $contact_id 98 | * @param array $data 99 | * @return array|\stdClass 100 | */ 101 | public function edit($contact_id , $data = []) 102 | { 103 | return $this->connector->request( 104 | "contacts/$contact_id", 105 | $data, 106 | "PUT" 107 | ); 108 | } 109 | 110 | /** 111 | * Delete contact 112 | * @param $contact_id 113 | * @return array|\stdClass 114 | */ 115 | public function delete($contact_id) 116 | { 117 | return $this->connector->request( 118 | "contacts/$contact_id", 119 | [], 120 | "DELETE" 121 | ); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/Exception.php: -------------------------------------------------------------------------------- 1 | connector = $connector; 15 | } 16 | 17 | /** 18 | * @param int $page 19 | * @param int $size 20 | * @return array|\stdClass 21 | */ 22 | public function list_invoices($page = 1, $size = 25) 23 | { 24 | return $this->connector->request( 25 | "sales_invoices/?page[number]=$page&page[size]=$size", 26 | [], 27 | 'GET' 28 | ); 29 | } 30 | 31 | /** 32 | * @return mixed 33 | */ 34 | public function count_sales_invoices() 35 | { 36 | return $this->connector->request( 37 | "sales_invoices/?page[size]=1", 38 | [], 39 | 'GET' 40 | )->result->meta->total_count; 41 | } 42 | 43 | /** 44 | * @param int $page 45 | * @param int $size 46 | * @return array|\stdClass 47 | */ 48 | public function list_e_invoices($page = 1, $size = 25) 49 | { 50 | return $this->connector->request( 51 | "e_invoices/?page[number]=$page&page[size]=$size", 52 | [], 53 | 'GET' 54 | ); 55 | } 56 | 57 | /** 58 | * @return mixed 59 | */ 60 | public function count_e_invoices() 61 | { 62 | return $this->connector->request( 63 | "e_invoices/?page[number]=1&page[size]=2", 64 | [], 65 | 'GET' 66 | )->result->meta->total_count; 67 | } 68 | 69 | /** 70 | * @param array $data 71 | * @return array|\stdClass 72 | */ 73 | public function search($data = []) 74 | { 75 | $filter = null; 76 | foreach ($data as $key => $value) 77 | { 78 | if (end($data) == $value) 79 | $filter .= "filter[$key]=".urlencode($value); 80 | else 81 | $filter .= "filter[$key]=".urlencode($value)."&"; 82 | } 83 | 84 | return $this->connector->request( 85 | "sales_invoices?$filter", 86 | [], 87 | 'GET' 88 | ); 89 | } 90 | 91 | /** 92 | * @param $invoice_id 93 | * @return array|\stdClass 94 | */ 95 | public function show($invoice_id) 96 | { 97 | return $this->connector->request( 98 | "sales_invoices/$invoice_id?include=active_e_document,contact,details.product", 99 | [], 100 | 'GET' 101 | ); 102 | } 103 | 104 | 105 | /** 106 | * @param $data 107 | * @return array|\stdClass 108 | */ 109 | public function create($data) 110 | { 111 | return $this->connector->request( 112 | "sales_invoices?include=active_e_document", 113 | $data, 114 | 'POST' 115 | ); 116 | } 117 | 118 | /** 119 | * @param $invoice_id 120 | * @param $data 121 | * @return array|\stdClass 122 | */ 123 | public function edit($invoice_id, $data) 124 | { 125 | return $this->connector->request( 126 | "sales_invoices/$invoice_id", 127 | $data, 128 | 'POST' 129 | ); 130 | } 131 | 132 | /** 133 | * @param $invoice_id 134 | * @return array|\stdClass 135 | */ 136 | public function delete($invoice_id) 137 | { 138 | return $this->connector->request( 139 | "sales_invoices/$invoice_id", 140 | [], 141 | 'DELETE' 142 | ); 143 | } 144 | 145 | /** 146 | * @param $invoice_id 147 | * @return array|\stdClass 148 | */ 149 | public function cancel($invoice_id) 150 | { 151 | return $this->connector->request( 152 | "sales_invoices/$invoice_id/cancel", 153 | [], 154 | 'DELETE' 155 | ); 156 | } 157 | 158 | /** 159 | * @param $invoice_id 160 | * @param $data 161 | * @return array|\stdClass 162 | */ 163 | public function pay($invoice_id, $data) 164 | { 165 | return $this->connector->request( 166 | "sales_invoices/$invoice_id/payments", 167 | $data, 168 | 'POST' 169 | ); 170 | } 171 | 172 | /** 173 | * @param $vkn 174 | * @return array|\stdClass 175 | */ 176 | public function check_vkn_type($vkn) 177 | { 178 | return $this->connector->request( 179 | "e_invoice_inboxes?filter[vkn]=$vkn", 180 | [], 181 | 'GET' 182 | ); 183 | } 184 | 185 | /** 186 | * @param $data 187 | * @return array|\stdClass 188 | */ 189 | public function create_e_archive($data) 190 | { 191 | return $this->connector->request( 192 | 'e_archives', 193 | $data, 194 | 'POST' 195 | ); 196 | } 197 | 198 | /** 199 | * @param $e_archive_id 200 | * @return array|\stdClass 201 | */ 202 | public function show_e_archive($e_archive_id) 203 | { 204 | return $this->connector->request( 205 | 'e_archives/'.$e_archive_id, 206 | [], 207 | 'GET' 208 | ); 209 | 210 | } 211 | 212 | /** 213 | * @param $e_archive_id 214 | * @return array|\stdClass 215 | */ 216 | public function pdf_e_archive($e_archive_id) 217 | { 218 | return $this->connector->request( 219 | "e_archives/$e_archive_id/pdf", 220 | [], 221 | 'GET' 222 | ); 223 | } 224 | 225 | /** 226 | * @param $data 227 | * @return array|\stdClass 228 | */ 229 | public function create_e_invoice($data) 230 | { 231 | return $this->connector->request( 232 | 'e_invoices', 233 | $data, 234 | "POST" 235 | ); 236 | } 237 | 238 | /** 239 | * @param $e_invoice_id 240 | * @return array|\stdClass 241 | */ 242 | public function show_e_invoice($e_invoice_id) 243 | { 244 | return $this->connector->request( 245 | 'e_invoices/'.$e_invoice_id, 246 | [], 247 | "GET" 248 | ); 249 | } 250 | 251 | /** 252 | * @param $e_invoice_id 253 | * @return array|\stdClass 254 | */ 255 | public function pdf_e_invoice($e_invoice_id) 256 | { 257 | return $this->connector->request( 258 | "e_invoices/$e_invoice_id/pdf", 259 | [], 260 | "GET" 261 | ); 262 | } 263 | 264 | /** 265 | * @param $url 266 | * @param $path 267 | * @return bool 268 | */ 269 | public function upload_pdf($url, $path) 270 | { 271 | if (!function_exists("file_put_contents")) 272 | return false; 273 | 274 | if (!function_exists("file_get_contents")) 275 | return false; 276 | 277 | $getPDF = @file_get_contents($url); 278 | 279 | if (!$getPDF) 280 | return false; 281 | 282 | $upload = @file_put_contents($path, $getPDF); 283 | 284 | if (!$upload) 285 | return false; 286 | 287 | return true; 288 | } 289 | 290 | /** 291 | * @param $trackable_id 292 | * @return array|\stdClass 293 | */ 294 | public function trackable_jobs($trackable_id) 295 | { 296 | return $this->connector->request( 297 | "trackable_jobs/$trackable_id", 298 | [], 299 | "GET" 300 | ); 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /src/Products.php: -------------------------------------------------------------------------------- 1 | connector = $connector; 15 | } 16 | 17 | /** 18 | * @param int $page 19 | * @param int $size 20 | * @return array|\stdClass 21 | */ 22 | public function list_products($page = 1, $size = 25) 23 | { 24 | return $this->connector->request( 25 | "products?page[number]=$page&page[size]=$size", 26 | [], 27 | "GET" 28 | ); 29 | } 30 | 31 | /** 32 | * @return mixed 33 | */ 34 | public function count_products() 35 | { 36 | return $this->connector->request( 37 | "products?page[number]=1&page[size]=2", 38 | [], 39 | "GET" 40 | )->result->meta->total_count; 41 | } 42 | 43 | /** 44 | * @param $product_id 45 | * @return array|\stdClass 46 | */ 47 | public function show($product_id) 48 | { 49 | return $this->connector->request( 50 | "products/$product_id?include=inventory_levels,category", 51 | [], 52 | "GET" 53 | ); 54 | } 55 | 56 | /** 57 | * @param array $data 58 | * @return array|\stdClass 59 | */ 60 | public function search($data) 61 | { 62 | $filter = null; 63 | foreach ($data as $key => $value) 64 | { 65 | if (end($data) == $value) 66 | $filter .= "filter[$key]=".urlencode($value); 67 | else 68 | $filter .= "filter[$key]=".urlencode($value)."&"; 69 | } 70 | 71 | return $this->connector->request( 72 | "products?$filter", 73 | [], 74 | "GET" 75 | ); 76 | } 77 | 78 | /** 79 | * @param $data 80 | * @return array|\stdClass 81 | */ 82 | public function create($data) 83 | { 84 | return $this->connector->request( 85 | "products", 86 | $data, 87 | "POST" 88 | ); 89 | } 90 | 91 | /** 92 | * @param $product_id 93 | * @param array $data 94 | * @return array|\stdClass 95 | */ 96 | public function edit($product_id, $data = []) 97 | { 98 | return $this->connector->request( 99 | "products/$product_id", 100 | $data, 101 | "PUT" 102 | ); 103 | } 104 | 105 | /** 106 | * @param $product_id 107 | * @return array|\stdClass 108 | */ 109 | public function delete($product_id) 110 | { 111 | return $this->connector->request( 112 | "products/$product_id", 113 | [], 114 | "DELETE" 115 | ); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Request.php: -------------------------------------------------------------------------------- 1 | 0) { 9 | $URL .= '?'.http_build_query($params); 10 | } 11 | 12 | $ch = curl_init(); 13 | curl_setopt($ch, CURLOPT_URL, $URL); 14 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->__curlHeader($accessToken)); 15 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 16 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 17 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 18 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 19 | curl_setopt($ch, CURLOPT_HEADER, false); 20 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 21 | 22 | $jsonData = curl_exec($ch); 23 | $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 24 | $responseData = json_decode($jsonData); 25 | curl_close($ch); 26 | 27 | return $this->_responseFormat($responseCode, $responseData); 28 | } 29 | 30 | protected function __postRequest($URL, $params, $accessToken) 31 | { 32 | $ch = curl_init(); 33 | curl_setopt($ch, CURLOPT_URL, $URL); 34 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->__curlHeader($accessToken)); 35 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 36 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 37 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 38 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 39 | curl_setopt($ch, CURLOPT_HEADER, false); 40 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 41 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 42 | 43 | $jsonData = curl_exec($ch); 44 | $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 45 | $responseData = json_decode($jsonData); 46 | curl_close($ch); 47 | 48 | return $this->_responseFormat($responseCode, $responseData); 49 | } 50 | 51 | protected function __putRequest($URL, $params, $accessToken) 52 | { 53 | $ch = curl_init(); 54 | curl_setopt($ch, CURLOPT_URL, $URL); 55 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->__curlHeader($accessToken)); 56 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 57 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 58 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 59 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 60 | curl_setopt($ch, CURLOPT_HEADER, false); 61 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 62 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 63 | 64 | $jsonData = curl_exec($ch); 65 | $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 66 | $responseData = json_decode($jsonData); 67 | curl_close($ch); 68 | 69 | return $this->_responseFormat($responseCode, $responseData); 70 | } 71 | 72 | protected function __deleteRequest($URL, $params, $accessToken) 73 | { 74 | $ch = curl_init(); 75 | curl_setopt($ch, CURLOPT_URL, $URL); 76 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->__curlHeader($accessToken)); 77 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 78 | curl_setopt($ch, CURLOPT_TIMEOUT, 90); 79 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 80 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 81 | curl_setopt($ch, CURLOPT_HEADER, false); 82 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); 83 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 84 | 85 | $jsonData = curl_exec($ch); 86 | $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 87 | $responseData = json_decode($jsonData); 88 | curl_close($ch); 89 | 90 | return $this->_responseFormat($responseCode, $responseData); 91 | } 92 | 93 | private function __curlHeader($accessToken) 94 | { 95 | return [ 96 | 'Accept: application/json', 97 | 'Content-Type: application/json', 98 | 'Authorization: Bearer '.$accessToken 99 | ]; 100 | } 101 | 102 | private function _responseFormat($responseCode, $responseData) 103 | { 104 | if ($responseCode >= 200 && $responseCode < 400) 105 | { 106 | $return = new \stdClass(); 107 | $return->code = $responseCode; 108 | $return->result = isset($responseData) ? $responseData : null; 109 | return $return; 110 | } 111 | else 112 | { 113 | $return = new \stdClass(); 114 | 115 | $return->code = $responseCode; 116 | switch ($responseCode) { 117 | case '400': 118 | if (isset($responseData->error)) 119 | { 120 | $return->error_title = null; 121 | $return->error_message = "Bad Request: ". $responseData->error; 122 | } 123 | elseif (isset($responseData->errors)) 124 | { 125 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 126 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 127 | $return->error_message = "Bad Request: ". $errorDetail; 128 | } 129 | break; 130 | case '401': 131 | if (isset($responseData->error)) 132 | { 133 | $return->error_title = null; 134 | $return->error_message = "Unauthorized: ". $responseData->error; 135 | } 136 | elseif (isset($responseData->errors)) 137 | { 138 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 139 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 140 | $return->error_message = "Unauthorized: ". $errorDetail; 141 | } 142 | break; 143 | case '403': 144 | if (isset($responseData->error)) 145 | { 146 | $return->error_title = null; 147 | $return->error_message = "Forbidden: ". $responseData->error; 148 | } 149 | elseif (isset($responseData->errors)) 150 | { 151 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 152 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 153 | $return->error_message = "Forbidden: ". $errorDetail; 154 | } 155 | break; 156 | case '404': 157 | if (isset($responseData->error)) 158 | { 159 | $return->error_title = null; 160 | $return->error_message = "Not Found: ". $responseData->error; 161 | } 162 | elseif (isset($responseData->errors)) 163 | { 164 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 165 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 166 | $return->error_message = "Not Found: ". $errorDetail; 167 | } 168 | break; 169 | case '422': 170 | if (isset($responseData->error)) 171 | { 172 | $return->error_title = null; 173 | $return->error_message = "Unprocessable Entity: ". $responseData->error; 174 | } 175 | elseif (isset($responseData->errors)) 176 | { 177 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 178 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 179 | $return->error_message = "Unprocessable Entity: ". $errorDetail; 180 | } 181 | break; 182 | case '429': 183 | if (isset($responseData->error)) 184 | { 185 | $return->error_title = null; 186 | $return->error_message = "Too many requests: ". $responseData->error; 187 | } 188 | elseif (isset($responseData->errors)) 189 | { 190 | $return->error_title = isset($responseData->errors[0]->title) ? $responseData->errors[0]->title : null; 191 | $errorDetail = isset($responseData->errors[0]->detail) ? $responseData->errors[0]->detail : null; 192 | $return->error_message = "Too many requests: ". $errorDetail; 193 | } 194 | break; 195 | default: 196 | break; 197 | } 198 | 199 | return $return; 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/authorization.ini: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/ContactsTest.php: -------------------------------------------------------------------------------- 1 | true, //development mode 5 | "client_id" => "YOUR_CLIENT_ID", 6 | "client_secret" => "YOUR_CLIENT_SECRET", 7 | "username" => "YOUR_EMAIL", 8 | "password" => "YOUR_PASSWORD", 9 | "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob", 10 | "company_id" => "YOUR_COMPANY_ID" 11 | ]); 12 | } catch (\Parasut\API\Exception $e) { 13 | echo "Error code : " . $e->getCode()."
"; 14 | echo "Error message : " . $e->getMessage(); 15 | die; 16 | } 17 | 18 | $contacts = new \Parasut\API\Contacts($parasutAuthorization); 19 | 20 | //contact list 21 | $contactList = $contacts->list_contacts(); 22 | //contact list 23 | 24 | //show contact 25 | $contact_id = 123456; //integer 26 | $showContact = $contacts->show($contact_id); 27 | //show contact 28 | 29 | //search contact 30 | $searchContactData1 = [ 31 | "name" => "XXXX" 32 | ]; 33 | 34 | $searchContactData2 = [ 35 | "name" => "XXXX", 36 | "email" => "XXXX" 37 | ]; 38 | 39 | $searchContactData3 = [ 40 | "name" => "XXXX", 41 | "email" => "XXXX", 42 | "tax_number" => "XXXX", 43 | "tax_office" => "XXXX", 44 | "city" => "XXXX", 45 | "account_type" => "customer" //customer, supplier 46 | ]; 47 | $searchContact1 = $contacts->search($searchContactData1); 48 | $searchContact2 = $contacts->search($searchContactData2); 49 | $searchContact3 = $contacts->search($searchContactData3); 50 | //search contact 51 | 52 | //create contact 53 | $createContactData = [ 54 | "data" => [ 55 | "type" => "contacts", 56 | "attributes" => [ 57 | "name" => "XXXX", //*required //ad soyad 58 | "email" => "XXXX", //e-posta 59 | "contact_type" => "person", //company, person (tüzel kişi, gerçek kişi) 60 | "tax_office" => "XXX", //vergi dairesi 61 | "tax_number" => "XXX", //vergi numarası 62 | "district" => "XXX", //ilçe 63 | "city" => "XXX", //il 64 | "address" => "XXX", //adres 65 | "phone" => "0XXXXXXXXXX", //tel no 66 | "account_type" => "customer" //customer, supplier 67 | ] 68 | ] 69 | ]; 70 | $createContact = $contacts->create($createContactData); 71 | //create contact 72 | 73 | //edit contact 74 | $contact_id = 123456; //integer 75 | $editContactData = [ 76 | "data" => [ 77 | "type" => "contacts", 78 | "attributes" => [ 79 | "name" => "XXXX", //*required //ad soyad 80 | "email" => "XXXX", //e-posta 81 | "contact_type" => "person", //company, person (tüzel kişi, gerçek kişi) 82 | "tax_office" => "XXX", //vergi dairesi 83 | "tax_number" => "XXX", //vergi numarası 84 | "district" => "XXX", //ilçe 85 | "city" => "XXX", //il 86 | "address" => "XXX", //adres 87 | "phone" => "0XXXXXXXXXX", //tel no 88 | "account_type" => "customer" //customer, supplier 89 | ] 90 | ] 91 | ]; 92 | $editContact = $contacts->edit($contact_id, $editContactData); 93 | //edit contact 94 | 95 | //delete contact 96 | $contact_id = 123456; //integer 97 | $deleteContact = $contacts->delete($contact_id); 98 | //delete contact 99 | 100 | -------------------------------------------------------------------------------- /tests/InvoicesTest.php: -------------------------------------------------------------------------------- 1 | true, //development mode 5 | "client_id" => "YOUR_CLIENT_ID", 6 | "client_secret" => "YOUR_CLIENT_SECRET", 7 | "username" => "YOUR_EMAIL", 8 | "password" => "YOUR_PASSWORD", 9 | "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob", 10 | "company_id" => "YOUR_COMPANY_ID" 11 | ]); 12 | } catch (\Parasut\API\Exception $e) { 13 | echo "Error code : " . $e->getCode()."
"; 14 | echo "Error message : " . $e->getMessage(); 15 | die; 16 | } 17 | 18 | $invoices = new \Parasut\API\Invoices($parasutAuthorization); 19 | 20 | //invoice list 21 | $invoiceList = $invoices->list_invoices(); 22 | //invoice list 23 | 24 | //show invoice 25 | $invoice_id = 123456; //integer 26 | $showInvoice = $invoices->show($invoice_id); //active_e_document,contact parametreleri ile beraber gelir 27 | //show invoice 28 | 29 | //search invoice 30 | $searchInvoiceData1 = [ 31 | "invoice_id" => "XXXX" 32 | ]; 33 | 34 | $searchInvoiceData2 = [ 35 | "invoice_id" => "XXXX", 36 | "contact_id" => "XXXX" 37 | ]; 38 | 39 | $searchInvoiceData3 = [ 40 | "issue_date" => "XXXX", 41 | "due_date" => "XXXX", 42 | "contact_id" => "XXXX", 43 | "invoice_id" => "XXXX", 44 | "invoice_series" => "XXXX", 45 | "item_type" => "invoice", 46 | "print_status" => "printed", //printed, not_printed, invoices_not_sent, e_invoice_sent, e_archive_sent, e_smm_sent 47 | "payment_status" => "paid" //overdue, not_due, unscheduled, paid 48 | ]; 49 | $searchInvoice1 = $invoices->search($searchInvoiceData1); 50 | $searchInvoice2 = $invoices->search($searchInvoiceData2); 51 | $searchInvoice3 = $invoices->search($searchInvoiceData3); 52 | //search invoice 53 | 54 | //create invoice 55 | $createInvoiceData = [ 56 | "data" => [ 57 | "type" => "sales_invoices", 58 | "attributes" => [ 59 | "item_type" => "invoice", 60 | "description" => "XXXX XXXX XXXX", //fatura açıklaması 61 | "issue_date" => "YYYY-MM-DD", //düzenleme tarihi 62 | "due_date" => "YYYY-MM-DD", //son tahsilat tarihi 63 | "invoice_series" => "XXX", //fatura seri no 64 | "invoice_id" => "XXX", //fatura sıra no 65 | "currency" => "TRL", //döviz tipi // TRL, USD, EUR, GBP 66 | "shipment_included" => false, //irsaliye 67 | ], 68 | "relationships" => [ 69 | "details" => [ 70 | "data" => [ 71 | 0 => [ 72 | "type" => "sales_invoice_details", 73 | "attributes" => [ 74 | "quantity" => 1, //birim adedi 75 | "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 76 | "vat_rate" => 18, //kdv oranı 77 | "description" => "XXXXX" //ürün açıklaması 78 | ], 79 | "relationships" => [ 80 | "product" => [ 81 | "data" => [ 82 | "id" => 123456, //ürün id 83 | "type" => "products" 84 | ] 85 | ] 86 | ] 87 | ], 88 | // 1 => [ 89 | // "type" => "sales_invoice_details", 90 | // "attributes" => [ 91 | // "quantity" => 1, //birim adedi 92 | // "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 93 | // "vat_rate" => 18, //kdv oranı 94 | // "description" => "XXXXX" //ürün açıklaması 95 | // ], 96 | // "relationships" => [ 97 | // "product" => [ 98 | // "data" => [ 99 | // "id" => 123456, //ürün id 100 | // "type" => "products" 101 | // ] 102 | // ] 103 | // ] 104 | // ] 105 | ] 106 | ], 107 | "contact" => [ 108 | "data" => [ 109 | "type" => "contacts", 110 | "id" => 123456 //müşteri id 111 | ] 112 | ] 113 | ] 114 | ] 115 | ]; 116 | $createInvoice = $invoices->create($createInvoiceData); 117 | //create invoice 118 | 119 | //edit invoice 120 | $editInvoiceData = [ 121 | "data" => [ 122 | "type" => "sales_invoices", 123 | "attributes" => [ 124 | "item_type" => "invoice", 125 | "description" => "XXXX XXXX XXXX", //fatura açıklaması 126 | "issue_date" => "YYYY-MM-DD", //düzenleme tarihi 127 | "due_date" => "YYYY-MM-DD", //son tahsilat tarihi 128 | "invoice_series" => "XXX", //fatura seri no 129 | "invoice_id" => "XXX", //fatura sıra no 130 | "currency" => "TRL", //döviz tipi // TRL, USD, EUR, GBP 131 | "shipment_included" => false, //irsaliye 132 | ], 133 | "relationships" => [ 134 | "details" => [ 135 | "data" => [ 136 | 0 => [ 137 | "type" => "sales_invoice_details", 138 | "attributes" => [ 139 | "quantity" => 1, //birim adedi 140 | "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 141 | "vat_rate" => 18, //kdv oranı 142 | "description" => "XXXXX" //ürün açıklaması 143 | ], 144 | "relationships" => [ 145 | "product" => [ 146 | "data" => [ 147 | "id" => 123456, //ürün id 148 | "type" => "products" 149 | ] 150 | ] 151 | ] 152 | ], 153 | // 1 => [ 154 | // "type" => "sales_invoice_details", 155 | // "attributes" => [ 156 | // "quantity" => 1, //birim adedi 157 | // "unit_price" => 100, //birim fiyatı (kdv'siz fiyatı) 158 | // "vat_rate" => 18, //kdv oranı 159 | // "description" => "XXXXX" //ürün açıklaması 160 | // ], 161 | // "relationships" => [ 162 | // "product" => [ 163 | // "data" => [ 164 | // "id" => 123456, //ürün id 165 | // "type" => "products" 166 | // ] 167 | // ] 168 | // ] 169 | // ] 170 | ] 171 | ], 172 | "contact" => [ 173 | "data" => [ 174 | "type" => "contacts", 175 | "id" => 123456 //müşteri id 176 | ] 177 | ] 178 | ] 179 | ] 180 | ]; 181 | 182 | $invoice_id = 123456; 183 | $editInvoice = $invoices->edit($invoice_id, $editInvoiceData); 184 | //edit invoice 185 | 186 | //delete invoice 187 | $invoice_id = 123456; 188 | $deleteInvoice = $invoices->delete($invoice_id); 189 | //delete invoice 190 | 191 | //cancel invoice 192 | $invoice_id = 123456; 193 | $cancelInvoice = $invoices->cancel($invoice_id); 194 | //cancel invoice 195 | 196 | //pay invoice 197 | $invoice_id = 123456; 198 | $payInvoiceData = [ 199 | "data" => [ 200 | "type" => "payments", 201 | "attributes" => [ 202 | "account_id" => 1234, // Kasa veya Banka id 203 | "date" => "YYYY-MM-DD", //ödeme tarihi 204 | "amount" => 123 //ödeme tutarı 205 | ] 206 | ] 207 | ]; 208 | $invoices->pay($invoice_id, $payInvoiceData); 209 | //pay invoice 210 | 211 | //check vkn type (vkn'nin e-fatura sistemine kayıtlı olup olmadığını sorgular) 212 | $vkn = 12345678912; 213 | $checkVKNType = $invoices->check_vkn_type($vkn); 214 | //check vkn type 215 | 216 | //create e archive (vkn e-fatura sistemine kayıtlı ise e-arşiv olarak kesilir) 217 | $eArchiveData = [ 218 | "data" => [ 219 | "type" => "e_archives", 220 | "relationships" => [ 221 | "sales_invoice" => [ 222 | "data" => [ 223 | "id" => 123456, //invoice_id 224 | "type" => "sales_invoices" 225 | ] 226 | ] 227 | ] 228 | ] 229 | ]; 230 | $createEArchive = $invoices->create_e_archive($eArchiveData); 231 | //create e archive 232 | 233 | //show e archive 234 | $e_archive_id = 123456; //invoice_id değildir. 235 | $showEArchive = $invoices->show_e_archive($e_archive_id); 236 | //show e archive 237 | 238 | //pdf e archive (resmileşen faturayı PDF olarak görüntüleme) 239 | $e_archive_id = 123456; //invoice_id değildir. 240 | $pdfEArchive = $invoices->pdf_e_archive($e_archive_id); 241 | //pdf e archive 242 | 243 | //create e invoice (vkn e-fatura sistemine kayıtlı değil ise e-fatura olarak kesilir) 244 | $vkn = 12345678912; 245 | $checkVKNType = $invoices->check_vkn_type($vkn); 246 | $eInvoiceAddress = $checkVKNType->result->data[0]->attributes->e_invoice_address; 247 | 248 | $eInvoiceData = [ 249 | "data" => [ 250 | "type" => "e_invoices", 251 | "attributes" => [ 252 | 'scenario' => 'basic', // basic veya commercial (temel veya ticari) 253 | 'to' => $eInvoiceAddress 254 | ], 255 | "relationships" => [ 256 | "invoice" => [ 257 | "data" => [ 258 | "id" => 123456, //invoice_id 259 | "type" => "sales_invoices" 260 | ] 261 | ] 262 | ] 263 | ] 264 | ]; 265 | $createEInvoice = $invoices->create_e_invoice($eInvoiceData); 266 | //create e invoice 267 | 268 | //show e invoice 269 | $e_invoice_id = 123456; //invoice_id değildir. 270 | $showEArchive = $invoices->show_e_invoice($e_invoice_id); 271 | //show e invoice 272 | 273 | //pdf e invoice (resmileşen faturayı PDF olarak görüntüleme) 274 | $e_invoice_id = 123456; //invoice_id değildir. 275 | $pdfEArchive = $invoices->pdf_e_invoice($e_invoice_id); 276 | //pdf e invoice 277 | 278 | //upload PDF from URL 279 | $pdfURL = "PDF_URL"; 280 | $uploadPath = "data/xxxxx.pdf"; 281 | $uploadPDF = $invoices->upload_pdf($pdfURL, $uploadPath); //bool : true or false 282 | //upload PDF from URL 283 | 284 | //check trackable jobs (resmileşen faturayı sorgular) 285 | $trackable_id = "xxxxxxxxxxxx"; 286 | $checkTrackableJobs = $invoices->trackable_jobs($trackable_id); 287 | //check trackable jobs 288 | -------------------------------------------------------------------------------- /tests/ProductsTest.php: -------------------------------------------------------------------------------- 1 | true, //development mode 5 | "client_id" => "YOUR_CLIENT_ID", 6 | "client_secret" => "YOUR_CLIENT_SECRET", 7 | "username" => "YOUR_EMAIL", 8 | "password" => "YOUR_PASSWORD", 9 | "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob", 10 | "company_id" => "YOUR_COMPANY_ID" 11 | ]); 12 | } catch (\Parasut\API\Exception $e) { 13 | echo "Error code : " . $e->getCode()."
"; 14 | echo "Error message : " . $e->getMessage(); 15 | die; 16 | } 17 | 18 | $products = new \Parasut\API\Products($parasutAuthorization); 19 | 20 | //product list 21 | $productList = $products->list_products(); 22 | //product list 23 | 24 | //show product 25 | $product_id = 123456; 26 | $showProduct = $products->show($product_id); 27 | //show product 28 | 29 | //search product 30 | $searchProductData1 = [ 31 | "name" => "XXXX" 32 | ]; 33 | 34 | $searchProductData2 = [ 35 | "name" => "XXXX", 36 | "code" => "XXXX" 37 | ]; 38 | 39 | $searchProduct1 = $products->search($searchProductData1); 40 | $searchProduct2 = $products->search($searchProductData2); 41 | //search product 42 | 43 | //create contact 44 | $productData = [ 45 | "data" => [ 46 | "type" => "products", 47 | "attributes" => [ 48 | "name" => "XXXX", //ürün adı 49 | "vat_rate" => 18, //KDV oranı 50 | "unit" => "Adet", //birim 51 | "currency" => "TRL", //döviz tipi 52 | "inventory_tracking" => true, //stok durumu 53 | "initial_stock_count" => 100 //stok adedi 54 | ] 55 | ] 56 | ]; 57 | 58 | $createProduct = $products->create($productData); 59 | //create contact 60 | 61 | //edit contact 62 | $productData = [ 63 | "data" => [ 64 | "type" => "products", 65 | "attributes" => [ 66 | "name" => "XXXX", //ürün adı 67 | "vat_rate" => 18, //KDV oranı 68 | "unit" => "Adet", //birim 69 | "currency" => "TRL", //döviz tipi 70 | "inventory_tracking" => true, //stok durumu 71 | "initial_stock_count" => 100 //stok adedi 72 | ] 73 | ] 74 | ]; 75 | 76 | $product_id = 123456; 77 | $editProduct = $products->edit($product_id, $productData); 78 | //edit contact 79 | 80 | //delete contact 81 | $product_id = 123456; 82 | $deleteProduct = $products->delete($product_id); 83 | //delete contact 84 | 85 | --------------------------------------------------------------------------------