Overview

Packages

  • exceptions
  • messages
  • operations
  • PHP
  • service
  • types

Classes

  • PartnerAPIService
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Partner API Library
  4:  * 
  5:  * @copyright Copyright (c) 2020 Asseco Data Systems SA
  6:  * @license license.txt
  7:  */
  8: 
  9: /**
 10:  * This class represents a Partner API WebService.
 11:  * 
 12:  * When constructing an object of this type you have to pass proper
 13:  * user name and password as arguments. Optionally, you may specify a URL
 14:  * for a WSDL file of a web service as the third argument. The fourth argument
 15:  * can be used to specify a language used for some localized texts.
 16:  * 
 17:  * @package service
 18:  */
 19: class PartnerAPIService {
 20: 
 21:     /**
 22:      * A constant field containing URL to a WSDL file in a testing web service
 23:      * 
 24:      * @var string
 25:      */
 26:     const WSDL_TEST = 'https://gs.test.certum.pl/service/PartnerApi.wsdl';
 27:     
 28:     /**
 29:      * A constant field containing URL to a WSDL file in a production web service
 30:      * 
 31:      * @var string
 32:      */
 33:     const WSDL_PROD = 'https://gs.certum.pl/service/PartnerApi.wsdl';
 34:     
 35:     /**
 36:      * List of available languages used for some localized messages.
 37:      * 
 38:      * It is a list of two-letter language codes joined with a semicolon.
 39:      * Currently only two languages are supported: English and Polish.
 40:      * 
 41:      * @var string
 42:      */
 43:     const LANGS = 'en;pl';
 44:     
 45:     //const METHOD_SOAP = "soap";
 46:     //const METHOD_CURL = "curl";
 47: 
 48:     /**
 49:      * A URL of currently used web service.
 50:      * 
 51:      * @var string
 52:      */
 53:     private $_wsdl = NULL;
 54:     
 55:     /**
 56:      * A current language code.
 57:      * 
 58:      * @var string
 59:      */
 60:     private $_lang = NULL;
 61:     
 62:     /**
 63:      * A user name used for authentication in the Partner API Service.
 64:      * 
 65:      * @var string
 66:      */
 67:     private $_userName = '';
 68:     
 69:     /**
 70:      * A password used for authentication in the Partner API Service.
 71:      * 
 72:      * @var string
 73:      */
 74:     private $_password = '';
 75:     
 76:     //private $_method = NULL;
 77:     
 78:     /**
 79:      * Indicates if SoapFault exceptions should be passed or catched.
 80:      * If they are catched they are rethrown as PartnerAPIException.
 81:      * 
 82:      * @var boolean
 83:      */
 84:     private $_catchSoapFault = FALSE;
 85: 
 86:     /**
 87:      * Indicates if debugging information should be writeten to a file.
 88:      * 
 89:      * If set to NULL, no debugging information will be stored anywhere.
 90:      * Otherwise, $_debugFile should contain a file name or a URL supported by PHP.
 91:      * 
 92:      * @var string
 93:      */
 94:     private $_debugFile = NULL;
 95:     
 96:     // ========================================================================
 97: 
 98:     /**
 99:      * The constructor.
100:      * 
101:      * The $userName and $password arguments are required. They are used
102:      * as credentials data in the Partner API WebService.
103:      * So, creating an object of this class you have to pass your user name
104:      * and password for the service.
105:      * The third argument $wsdl is optional and if it is NULL the object connects
106:      * to the testing web service using the URL defined in the WSDL_TEST field.
107:      * The fourth argument $lang is also optional. If given it must match one
108:      * of language codes in the LANGS constant field. Otherwise 'en' is used.
109:      * 
110:      * @param string $userName
111:      * @param string $password
112:      * @param string|null $wsdl Default: NULL
113:      * @param string $lang Default: en
114:      */
115:     public function __construct($userName = '', $password = '', $wsdl = NULL, $lang = 'en') {
116:         $this->setUserName($userName);
117:         $this->setPassword($password);
118:         $this->setWSDL($wsdl);
119:         $this->setLang($lang);
120:         /*
121:         if (class_exists('SoapClient')) {
122:             $this->_method = PartnerAPIService::METHOD_SOAP;
123:         } elseif (function_exists('curl_init')) {
124:             throw new PartnerAPIException("jakis tekst");
125:             $this->_method = PartnerAPIService::METHOD_CURL;
126:         } else {
127:             throw new PartnerAPIException("jakis tekst"); // w one click mają "Unable to start communication, no SoapClient or Curl availible"
128:         }
129:         */
130:     }
131: 
132:     // ========================================================================
133: 
134:     /**
135:      * Returns the user name
136:      * 
137:      * @return string
138:      */
139:     public function getUserName() {
140:         return $this->_userName;
141:     }
142:     
143:     /**
144:      * Sets the user name to be used for authentication in a web service.
145:      * 
146:      * @param string $userName
147:      * @return PartnerAPIService The object being called
148:      */
149:     public function setUserName($userName) {
150:         $this->_userName = (string) $userName;
151:         return $this;
152:     }
153:     
154:     /**
155:      * Returns the password
156:      * 
157:      * @return string
158:      */
159:     public function getPassword() {
160:         return $this->_password;
161:     }
162:     
163:     /**
164:      * Sets the password to be used for authentication in a web service.
165:      * 
166:      * @param string $password
167:      * @return PartnerAPIService The object being called
168:      */
169:     public function setPassword($password) {
170:         $this->_password = (string) $password;
171:         return $this;
172:     }
173: 
174:     /**
175:      * Returns current language
176:      * 
177:      * @return string
178:      */
179:     public function getLang() {
180:         return $this->_lang;
181:     }
182:     
183:     /**
184:      * Sets the current language
185:      * 
186:      * @param string $lang
187:      * @return PartnerAPIService The object being called
188:      */
189:     public function setLang($lang) {
190:         $langarray = explode(';', PartnerAPIService::LANGS);
191:         if (! in_array($lang, $langarray))
192:             $lang = 'en';
193:         $this->_lang = $lang;
194:         return $this;
195:     }
196:     
197:     /**
198:      * Returns current URL for a WSDL file.
199:      * 
200:      * @return string
201:      */
202:     public function getWSDL() {
203:         return $this->_wsdl;
204:     }
205:     
206:     /**
207:      * Sets the current URL for a WSDL file.
208:      * 
209:      * @param string|null $wsdl
210:      * @return PartnerAPIService The object being called
211:      */
212:     public function setWSDL($wsdl) {
213:         if (is_null($wsdl))
214:             $this->_wsdl = PartnerAPIService::WSDL_TEST;
215:         else
216:             $this->_wsdl = (string) $wsdl;
217:         return $this;
218:     }
219: 
220:     /**
221:      * Configures the service to pass or to catch SoapFault exceptions.
222:      * 
223:      * If SoapFault exceptions are catched they are rethrown as PartnerAPIException.
224:      * 
225:      * @param boolean $yes_or_no
226:      * @return PartnerAPIService
227:      */
228:     public function setCatchSoapFault($yes_or_no) {
229:         $this->_catchSoapFault = (bool) $yes_or_no;
230:         return $this;
231:     }
232:     
233:     /**
234:      * Tells if SoapFault exceptions are passed or catched.
235:      * 
236:      * @return boolean True if SoapFault exceptions are catched, False otherwise
237:      */
238:     public function getCatchSoapFault() {
239:         return $this->_catchSoapFault;
240:     }
241: 
242:     /**
243:      * Sets a file for storing debug information.
244:      *
245:      * The argument $fname should be null or a string containing a file name.
246:      * If it is null, no debug information will be stored anywhere.
247:      * Otherwise, it must be anything acceptable by the PHP function fopen() as the first argument.
248:      *
249:      * @param string|null $fname
250:      * @return PartnerAPIService
251:      * @throws PartnerAPIException
252:      */
253:     public function setDebugFile($fname = NULL) {
254:         if (! (is_null($fname) || is_string($fname))) {
255:             require_once 'certumPartnerAPI/exceptions/exceptions.php';
256:             throw new PartnerAPIException("Invalid file name. It should be a string or null.");
257:         }
258:         if (is_string($fname) && file_exists($fname) && ! is_writable($fname)) {
259:             require_once 'certumPartnerAPI/exceptions/exceptions.php';
260:             throw new PartnerAPIException("File '$fname' is not writable.");
261:         }
262:         $this->_debugFile = $fname;
263:         return $this;
264:     }
265:     
266:     /**
267:      * Return a file name for writing debug information.
268:      * 
269:      * It can also return null if no file name has been set.
270:      * 
271:      * @return string|null A file name
272:      */
273:     public function getDebugFile() {
274:         return $this->_debugFile;
275:     }
276:     
277:     /*  future implementation will also support CURL
278:     public function getMethod() {
279:         return $this->_method;
280:     }
281:     
282:     public function setMethod($method) {
283:         if ($method == PartnerAPIService::METHOD_SOAP) {
284:             if (class_exists('SoapClient'))
285:                 $this->_method = PartnerAPIService::METHOD_SOAP;
286:             else
287:                 throw new PartnerAPIException("nie można");
288:             return;
289:         }
290:         if ($method == PartnerAPIService::METHOD_CURL) {
291:             if (function_exists('curl_init'))
292:                 $this->_method = PartnerAPIService::METHOD_CURL;
293:             else
294:                 throw new PartnerAPIException;
295:             return;
296:         }
297:         throw new PartnerAPIException("jakis tekst"); // w one click mają "Unable to start communication, no SoapClient or Curl availible"
298:     }
299:     */
300: 
301:     // ========================================================================
302: 
303:     /**
304:      * Returns an object representing the validateOrderParameters operation.
305:      * 
306:      * @return PartnerAPIOperationValidateOrderParameters
307:      */
308:     public function operationValidateOrderParameters() {
309:         require_once 'certumPartnerAPI/operations/operationValidateOrderParameters.php';
310:         $operation = new PartnerAPIOperationValidateOrderParameters();
311:         $operation->setService($this);
312:         return $operation;
313:     }
314: 
315:     /**
316:      * Returns an object representing the quickOrder operation.
317:      * 
318:      * @return PartnerAPIOperationQuickOrder
319:      */
320:     public function operationQuickOrder() {
321:         require_once 'certumPartnerAPI/operations/operationQuickOrder.php';
322:         $operation = new PartnerAPIOperationQuickOrder();
323:         $operation->setService($this);
324:         return $operation;
325:     }
326: 
327:     /**
328:      * Returns an object representing the getOrderByOrderID operation.
329:      * 
330:      * @return PartnerAPIOperationGetOrderByOrderID
331:      */
332:     public function operationGetOrderByOrderID() {
333:         require_once 'certumPartnerAPI/operations/operationGetOrderByOrderID.php';
334:         $operation = new PartnerAPIOperationGetOrderByOrderID();
335:         $operation->setService($this);
336:         return $operation;
337:     }
338: 
339:     /**
340:      * Returns an object representing the getOrderByOrderID operation.
341:      * 
342:      * @return PartnerAPIOperationGetOrderByOrderID
343:      */
344:     public function operationGetOrdersByDateRange() {
345:         require_once 'certumPartnerAPI/operations/operationGetOrdersByDateRange.php';
346:         $operation = new PartnerAPIOperationGetOrdersByDateRange();
347:         $operation->setService($this);
348:         return $operation;
349:     }
350: 
351:     /**
352:      * Returns an object representing the getModifiedOrders operation.
353:      * 
354:      * @return PartnerAPIOperationGetModifiedOrders
355:      */
356:     public function operationGetModifiedOrders() {
357:         require_once 'certumPartnerAPI/operations/operationGetModifiedOrders.php';
358:         $operation = new PartnerAPIOperationGetModifiedOrders();
359:         $operation->setService($this);
360:         return $operation;
361:     }
362: 
363:     /**
364:      * Returns an object representing the cancelOrder operation.
365:      * 
366:      * @return PartnerAPIOperationCancelOrder
367:      */
368:     public function operationCancelOrder() {
369:         require_once 'certumPartnerAPI/operations/operationCancelOrder.php';
370:         $operation = new PartnerAPIOperationCancelOrder();
371:         $operation->setService($this);
372:         return $operation;
373:     }
374: 
375:     /**
376:      * Returns an object representing the getProductList operation.
377:      * 
378:      * @return PartnerAPIOperationGetProductList
379:      */
380:     public function operationGetProductList() {
381:         require_once 'certumPartnerAPI/operations/operationGetProductList.php';
382:         $operation = new PartnerAPIOperationGetProductList();
383:         $operation->setService($this);
384:         return $operation;
385:     }
386: 
387:     /**
388:      * Returns an object representing the getConfiguration operation.
389:      * 
390:      * @return PartnerAPIOperationGetConfiguration
391:      */
392:     public function operationGetConfiguration() {
393:         require_once 'certumPartnerAPI/operations/operationGetConfiguration.php';
394:         $operation = new PartnerAPIOperationGetConfiguration();
395:         $operation->setService($this);
396:         return $operation;
397:     }
398: 
399:     /**
400:      * Returns an object representing the getCertificate operation.
401:      * 
402:      * @return PartnerAPIOperationGetCertificate
403:      */
404:     public function operationGetCertificate() {
405:         require_once 'certumPartnerAPI/operations/operationGetCertificate.php';
406:         $operation = new PartnerAPIOperationGetCertificate();
407:         $operation->setService($this);
408:         return $operation;
409:     }
410: 
411:     /**
412:      * Returns an object representing the renewCertificate operation.
413:      * 
414:      * @return PartnerAPIOperationRenewCertificate
415:      */
416:     public function operationRenewCertificate() {
417:         require_once 'certumPartnerAPI/operations/operationRenewCertificate.php';
418:         $operation = new PartnerAPIOperationRenewCertificate();
419:         $operation->setService($this);
420:         return $operation;
421:     }
422: 
423:     /**
424:      * Returns an object representing the revokeCertificate operation.
425:      * 
426:      * @return PartnerAPIOperationRevokeCertificate
427:      */
428:     public function operationRevokeCertificate() {
429:         require_once 'certumPartnerAPI/operations/operationRevokeCertificate.php';
430:         $operation = new PartnerAPIOperationRevokeCertificate();
431:         $operation->setService($this);
432:         return $operation;
433:     }
434:     
435:     /**
436:      * Returns an object representing the getExpiringCertificates operation.
437:      *
438:      * @return PartnerAPIOperationGetExpiringCertificates
439:      */
440:     public function operationGetExpiringCertificates() {
441:         require_once 'certumPartnerAPI/operations/operationGetExpiringCertificates.php';
442:         $operation = new PartnerAPIOperationGetExpiringCertificates();
443:         $operation->setService($this);
444:         return $operation;
445:     }
446:     
447:     /**
448:      * Returns an object representing the verifyOrder operation.
449:      *
450:      * @return PartnerAPIOperationVerifyOrder
451:      */
452:     public function operationVerifyOrder() {
453:         require_once 'certumPartnerAPI/operations/operationVerifyOrder.php';
454:         $operation = new PartnerAPIOperationVerifyOrder();
455:         $operation->setService($this);
456:         return $operation;
457:     }
458: 
459:     /**
460:      * Returns an object representing the orderSNICertificate operation.
461:      *
462:      * @return PartnerAPIOperationOrderSNICertificate
463:      */
464:     public function operationOrderSNICertificate() {
465:         require_once 'certumPartnerAPI/operations/operationOrderSNICertificate.php';
466:         $operation = new PartnerAPIOperationOrderSNICertificate();
467:         $operation->setService($this);
468:         return $operation;
469:     }
470:     
471:     /**
472:      * Returns an object representing the modifySNICertificate operation.
473:      *
474:      * @return PartnerAPIOperationModifySNICertificate
475:      */
476:     public function operationModifySNICertificate() {
477:         require_once 'certumPartnerAPI/operations/operationModifySNICertificate.php';
478:         $operation = new PartnerAPIOperationModifySNICertificate();
479:         $operation->setService($this);
480:         return $operation;
481:     }
482: 
483:     /**
484:      * Returns an object representing the getEmailVerification operation.
485:      *
486:      * @return PartnerAPIOperationGetEmailVerification
487:      */
488:     public function operationGetEmailVerification() {
489:         require_once 'certumPartnerAPI/operations/operationGetEmailVerification.php';
490:         $operation = new PartnerAPIOperationGetEmailVerification();
491:         $operation->setService($this);
492:         return $operation;
493:     }
494: 
495:     /**
496:      * Returns an object representing the reissueCertificate operation.
497:      *
498:      * @return PartnerAPIOperationReissueCertificate
499:      */
500:     public function operationReissueCertificate() {
501:         require_once 'certumPartnerAPI/operations/operationReissueCertificate.php';
502:         $operation = new PartnerAPIOperationReissueCertificate();
503:         $operation->setService($this);
504:         return $operation;
505:     }
506:     
507:     /**
508:      * Returns an object representing the getOrderState operation.
509:      *
510:      * @return PartnerAPIOperationGetOrderState
511:      */
512:     public function operationGetOrderState() {
513:         require_once 'certumPartnerAPI/operations/operationGetOrderState.php';
514:         $operation = new PartnerAPIOperationGetOrderState();
515:         $operation->setService($this);
516:         return $operation;
517:     }
518: 
519:     /**
520:      * Returns an object representing the getSanVerificationState operation.
521:      *
522:      * @return PartnerAPIOperationGetSanVerificationState
523:      */
524:     public function operationGetSanVerificationState() {
525:         require_once 'certumPartnerAPI/operations/operationGetSanVerificationState.php';
526:         $operation = new PartnerAPIOperationGetSanVerificationState();
527:         $operation->setService($this);
528:         return $operation;
529:     }
530: 
531:     /**
532:      * Returns an object representing the performSanVerification operation.
533:      *
534:      * @return PartnerAPIOperationPerformSanVerification
535:      */
536:     public function operationPerformSanVerification() {
537:         require_once 'certumPartnerAPI/operations/operationPerformSanVerification.php';
538:         $operation = new PartnerAPIOperationPerformSanVerification();
539:         $operation->setService($this);
540:         return $operation;
541:     }
542: 
543:     /**
544:      * Returns an object representing the addSanVerification operation.
545:      *
546:      * @return PartnerAPIOperationAddSanVerification
547:      */
548:     public function operationAddSanVerification() {
549:         require_once 'certumPartnerAPI/operations/operationAddSanVerification.php';
550:         $operation = new PartnerAPIOperationAddSanVerification();
551:         $operation->setService($this);
552:         return $operation;
553:     }
554: 
555:     /**
556:      * Returns an object representing the addEmailVerification operation.
557:      *
558:      * @return PartnerAPIOperationAddEmailVerification
559:      */
560:     public function operationAddEmailVerification() {
561:         require_once 'certumPartnerAPI/operations/operationAddEmailVerification.php';
562:         $operation = new PartnerAPIOperationAddEmailVerification();
563:         $operation->setService($this);
564:         return $operation;
565:     }
566: 
567:     // ========================================================================
568:     
569:     /**
570:      * This method invokes a given operation in the Partner API WebService
571:      * 
572:      * This method is used for communication with the service. It sends the data
573:      * passed in the $data argument to the service and invokes the operation specified
574:      * in the $operation argument. It uses a WSDL file defined as the current WSDL file
575:      * in the constructor or by calling the setWSDL() method.
576:      * The $operation argument is simply a string.
577:      * The $data argument is an array in which keys are parts' names (according to WSDL)
578:      * and values are subsequent arrays. The subsequent arrays contain all passed elements.
579:      * A subsequent array's key is an element's name and value is a scalar value,
580:      * an array of scalar values or an array of further elements.
581:      * 
582:      * This method can write debugging information to a file (see the setDebugFile() method).
583:      * This information is stored in a file only after a successful call to a service.
584:      * 
585:      * Although it is possible, it is not intended this method to be called directly
586:      * by a user. It is invoked by operation objects.
587:      * 
588:      * It returns an object containg all returned data from the service.
589:      * 
590:      * @param string $operation The operations to be called
591:      * @param array $data The data to be passed to the operation
592:      * @return object
593:      * @throws SoapFault
594:      * @throws PartnerAPIException
595:      */
596:     public function call($operation = 'unspecified', $data = array()) {
597:         $client = new SoapClient($this->_wsdl,
598:             array('trace' => true, 'exceptions' => true, 'connection_timeout' => 30));
599:         if ($this->_catchSoapFault) {
600:             try {
601:                 $r = $client->__soapCall($operation, $data);
602:             } catch (SoapFault $e) {
603:                 require_once 'certumPartnerAPI/exceptions/exceptions.php';
604:                 $ex = new PartnerAPIException($e->getMessage(), (int) $e->getCode());
605:                 throw $ex;
606:             }
607:         } else {
608:             $r = $client->__soapCall($operation, $data);
609:         }
610:         $this->writeDebugData($operation, $data, $r, $client);
611:         return $r;
612:     }
613:     
614:     /**
615:      * Writes debugging information to a file.
616:      * 
617:      * @param string $operation Operation invoked
618:      * @param array $data Data sent
619:      * @param array|string|object $r Response data
620:      * @param SoapClient $client Client object
621:      */
622:     protected function writeDebugData($operation, $data, $r, $client) {
623:         if (! is_null($this->_debugFile)) {
624:             $f = fopen($this->_debugFile, 'a');
625:             fwrite($f, "======================================================================\n");
626:             fwrite($f, "DEBUGGING INFORMATION FOR A 'PARTNER API SERVICE' REQUEST\n");
627:             fwrite($f, "======================================================================\n");
628:             fwrite($f, "TIME: ".date("Y-m-d H:i:s")."\n");
629:             fwrite($f, "SERVICE USED: ".$this->_wsdl."\n");
630:             fwrite($f, "OPERATION INVOKED: ".$operation."\n");
631:             if (is_soap_fault($r)) {
632:                 fwrite($f, "AN ERROR OCCURED:\n");
633:                 fwrite($f, "SOAP FAULT CODE: ".$r->faultcode."\n");
634:                 fwrite($f, "SOAP FAULT MESSAGE: ".$r->faultstring."\n");
635:             }
636:             fwrite($f, "----------\nDATA SENT:\n----------\n".print_r($data, true)."\n");
637:             fwrite($f, "--------------\nDATA RETURNED:\n--------------\n".print_r($r, true)."\n");
638:             fwrite($f, "----------------\nREQUEST HEADERS:\n----------------\n".$client->__getLastRequestHeaders()."\n");
639:             fwrite($f, "--------\nREQUEST:\n--------\n".$client->__getLastRequest()."\n");
640:             fwrite($f, "-----------------\nRESPONSE HEADERS:\n-----------------\n".$client->__getLastResponseHeaders()."\n");
641:             fwrite($f, "---------\nRESPONSE:\n---------\n".$client->__getLastResponse()."\n");
642:             fwrite($f, "===========\nEND\n===========\n");
643:             fclose($f);
644:         }
645:     }
646:     
647: }
648: 
API documentation generated by ApiGen 2.8.0