| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Dokobit\Gateway\Query\Signing; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Dokobit\Gateway\Query\QueryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Dokobit\Gateway\Result\ResultInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Dokobit\Gateway\Result\Signing\SealResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Dokobit\Gateway\SigningPurposeProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Validator\Constraints as Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Seal a document with an e-seal. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @see https://gateway-sandbox.dokobit.com/api/doc#_api_signing_seal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class Seal implements QueryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** @var string signing token */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** @var string name displayed to users in signing view */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** @var string signing purpose */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private $signing_purpose; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var array PDF-specific options */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param string $token signing token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param string $name name displayed to users in signing view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @param string|null $signing_purpose signing purpose (optional) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @param array|null $params Optional parameters per file type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      *        Currently only PDF annotation parameters are supported. Example: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      *        [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      *            annotation => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      *                'page' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      *                'top' => 100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      *                'left' => 100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      *                ... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      *            ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      *        ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         string $token, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         string $name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ?string $signing_purpose = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ?array $params = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->token = $token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->name = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->signing_purpose = $signing_purpose; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->params = $params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Field and values association used in query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function getFields(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $return = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'token' => $this->token, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             'name' => $this->name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         if ($this->signing_purpose !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             $return['signing_purpose'] = $this->signing_purpose; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         if ($this->params !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $return['pdf'] = $this->params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Validation constraints for request data validation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @return Assert\Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function getValidationConstraints(): Assert\Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return new Assert\Collection([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             'token' => new Assert\Required([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'name' => new Assert\Required([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             'signing_purpose' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 new Assert\Choice([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                     'choices' => SigningPurposeProvider::getAllSigningPurposes(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'pdf' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 new Assert\Collection([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     'annotation' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                         new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                         new Assert\Collection([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                             'page' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                                 new Assert\Type([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                                     'type' => 'numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                             'top' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                                 new Assert\Type([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                                     'type' => 'numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                             'left' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                                 new Assert\Type([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                                     'type' => 'numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                                 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                             'width' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                                 new Assert\Type([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                                     'type' => 'numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                                 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                             'height' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                                 new Assert\Type([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                                     'type' => 'numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                                 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                             'text' => new Assert\Optional([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                                 new Assert\NotBlank(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                         ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                     ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * Result object for this query result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @return SealResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     public function createResult(): ResultInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         return new SealResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * API action name, part of full API request url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |     public function getAction(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |         return "signing/{$this->token}/seal"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * HTTP method to use | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     public function getMethod(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         return QueryInterface::POST; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 168 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 169 |  |  |  |