| @@ 152-207 (lines=56) @@ | ||
| 149 | * @param array $body |
|
| 150 | * @return object |
|
| 151 | */ |
|
| 152 | public function create(array $body) |
|
| 153 | { |
|
| 154 | // keys that are mandatory for this request |
|
| 155 | $needKeys = [ |
|
| 156 | 'Description', |
|
| 157 | 'FileContent', |
|
| 158 | 'FileMD5CheckSum', |
|
| 159 | 'FileName', |
|
| 160 | 'Language', |
|
| 161 | 'SigneeRefs', |
|
| 162 | 'SignJobId', |
|
| 163 | 'Title', |
|
| 164 | ]; |
|
| 165 | ||
| 166 | // keys that need to be present in each signeeref |
|
| 167 | $needSubKeys = [ |
|
| 168 | 'SigneeRefId', |
|
| 169 | 'FirstName', |
|
| 170 | 'LastName', |
|
| 171 | 'Email', |
|
| 172 | ]; |
|
| 173 | ||
| 174 | // if the body doesn't have needed fields, throw an exception |
|
| 175 | if (! array_has_all_keys($body, $needKeys)) { |
|
| 176 | throw new BadMethodCallException( |
|
| 177 | 'Missing fields in input array. Need '.implode(', ', $needKeys) |
|
| 178 | ); |
|
| 179 | } elseif (! is_array($body['SigneeRefs'])) { |
|
| 180 | throw new UnexpectedValueException('SigneeRefs key in input should be an array'); |
|
| 181 | } else { |
|
| 182 | foreach ($body['SigneeRefs'] as $ref) { |
|
| 183 | if (! is_array($ref)) { |
|
| 184 | throw new UnexpectedValueException('Each item in SigneeRefs should be an array'); |
|
| 185 | } elseif (! array_has_all_keys($ref, $needSubKeys)) { |
|
| 186 | throw new BadMethodCallException( |
|
| 187 | 'Missing fields in SigneeRefs item. Need '.implode(', ', $needSubKeys) |
|
| 188 | ); |
|
| 189 | } |
|
| 190 | } |
|
| 191 | } |
|
| 192 | ||
| 193 | // make the URL for this request |
|
| 194 | $url = $this->transformUrl(self::URI); |
|
| 195 | ||
| 196 | // get the headers for this request |
|
| 197 | $headers = $this->headers->make('POST', $url, $body, true); |
|
| 198 | ||
| 199 | // get the response |
|
| 200 | $response = $this->client->post($url, [ |
|
| 201 | 'headers' => $headers, |
|
| 202 | 'json' => $body, |
|
| 203 | ]); |
|
| 204 | ||
| 205 | // return the response |
|
| 206 | return $response; |
|
| 207 | } |
|
| 208 | ||
| 209 | /** |
|
| 210 | * Creates a new document to sign, and returns |
|
| @@ 127-183 (lines=57) @@ | ||
| 124 | * @param array $body |
|
| 125 | * @return object |
|
| 126 | */ |
|
| 127 | public function createRequest(array $body) |
|
| 128 | { |
|
| 129 | // keys that are mandatory for this request |
|
| 130 | $needKeys = [ |
|
| 131 | 'Description', |
|
| 132 | 'ExternalDocumentId', |
|
| 133 | 'FileContent', |
|
| 134 | 'Filename', |
|
| 135 | 'ReturnUrlError', |
|
| 136 | 'ReturnUrlSuccess', |
|
| 137 | 'ReturnUrlUserAbort', |
|
| 138 | 'SigneeRefs', |
|
| 139 | 'Title', |
|
| 140 | ]; |
|
| 141 | ||
| 142 | // keys that need to be present in each signeeref |
|
| 143 | $needSubKeys = [ |
|
| 144 | 'UniqueRef', |
|
| 145 | 'FirstName', |
|
| 146 | 'LastName', |
|
| 147 | 'Email', |
|
| 148 | ]; |
|
| 149 | ||
| 150 | // if the body doesn't have needed fields, throw an exception |
|
| 151 | if (! array_has_all_keys($body, $needKeys)) { |
|
| 152 | throw new BadMethodCallException( |
|
| 153 | 'Missing fields in input array. Need '.implode(', ', $needKeys) |
|
| 154 | ); |
|
| 155 | } elseif (! is_array($body['SigneeRefs'])) { |
|
| 156 | throw new UnexpectedValueException('SigneeRefs key in input should be an array'); |
|
| 157 | } else { |
|
| 158 | foreach ($body['SigneeRefs'] as $ref) { |
|
| 159 | if (! is_array($ref)) { |
|
| 160 | throw new UnexpectedValueException('Each item in SigneeRefs should be an array'); |
|
| 161 | } elseif (! array_has_all_keys($ref, $needSubKeys)) { |
|
| 162 | throw new BadMethodCallException( |
|
| 163 | 'Missing fields in SigneeRefs item. Need '.implode(', ', $needSubKeys) |
|
| 164 | ); |
|
| 165 | } |
|
| 166 | } |
|
| 167 | } |
|
| 168 | ||
| 169 | // make the URL for this request |
|
| 170 | $url = $this->transformUrl(self::URI); |
|
| 171 | ||
| 172 | // get the headers for this request |
|
| 173 | $headers = $this->headers->make('POST', $url, $body, true); |
|
| 174 | ||
| 175 | // get the response |
|
| 176 | $response = $this->client->post($url, [ |
|
| 177 | 'headers' => $headers, |
|
| 178 | 'json' => $body, |
|
| 179 | ]); |
|
| 180 | ||
| 181 | // return the response |
|
| 182 | return $response; |
|
| 183 | } |
|
| 184 | ||
| 185 | /** |
|
| 186 | * Creates a app launch uri for the BankID app. |
|