| @@ 130-185 (lines=56) @@ | ||
| 127 | * @param array $body |
|
| 128 | * @return object |
|
| 129 | */ |
|
| 130 | public function create(array $body) |
|
| 131 | { |
|
| 132 | // keys that are mandatory for this request |
|
| 133 | $needKeys = [ |
|
| 134 | 'Description', |
|
| 135 | 'FileContent', |
|
| 136 | 'FileMD5CheckSum', |
|
| 137 | 'FileName', |
|
| 138 | 'Language', |
|
| 139 | 'SigneeRefs', |
|
| 140 | 'SignJobId', |
|
| 141 | 'Title', |
|
| 142 | ]; |
|
| 143 | ||
| 144 | // keys that need to be present in each signeeref |
|
| 145 | $needSubKeys = [ |
|
| 146 | 'SigneeRefId', |
|
| 147 | 'FirstName', |
|
| 148 | 'LastName', |
|
| 149 | 'Email', |
|
| 150 | ]; |
|
| 151 | ||
| 152 | // if the body doesn't have needed fields, throw an exception |
|
| 153 | if (! array_has_all_keys($body, $needKeys)) { |
|
| 154 | throw new BadMethodCallException( |
|
| 155 | 'Missing fields in input array. Need '.implode(', ', $needKeys) |
|
| 156 | ); |
|
| 157 | } elseif (! is_array($body['SigneeRefs'])) { |
|
| 158 | throw new UnexpectedValueException('SigneeRefs key in input should be an array'); |
|
| 159 | } else { |
|
| 160 | foreach ($body['SigneeRefs'] as $ref) { |
|
| 161 | if (! is_array($ref)) { |
|
| 162 | throw new UnexpectedValueException('Each item in SigneeRefs should be an array'); |
|
| 163 | } elseif (! array_has_all_keys($ref, $needSubKeys)) { |
|
| 164 | throw new BadMethodCallException( |
|
| 165 | 'Missing fields in SigneeRefs item. Need '.implode(', ', $needSubKeys) |
|
| 166 | ); |
|
| 167 | } |
|
| 168 | } |
|
| 169 | } |
|
| 170 | ||
| 171 | // make the URL for this request |
|
| 172 | $url = $this->transformUrl(self::URI); |
|
| 173 | ||
| 174 | // get the headers for this request |
|
| 175 | $headers = $this->headers->make('POST', $url, $body, true); |
|
| 176 | ||
| 177 | // get the response |
|
| 178 | $response = $this->client->post($url, [ |
|
| 179 | 'headers' => $headers, |
|
| 180 | 'json' => $body, |
|
| 181 | ]); |
|
| 182 | ||
| 183 | // return the response |
|
| 184 | return $response; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * Creates a new document to sign, and returns |
|
| @@ 101-157 (lines=57) @@ | ||
| 98 | * @param array $body |
|
| 99 | * @return object |
|
| 100 | */ |
|
| 101 | public function createRequest(array $body) |
|
| 102 | { |
|
| 103 | // keys that are mandatory for this request |
|
| 104 | $needKeys = [ |
|
| 105 | 'Description', |
|
| 106 | 'ExternalDocumentId', |
|
| 107 | 'FileContent', |
|
| 108 | 'Filename', |
|
| 109 | 'ReturnUrlError', |
|
| 110 | 'ReturnUrlSuccess', |
|
| 111 | 'ReturnUrlUserAbort', |
|
| 112 | 'SigneeRefs', |
|
| 113 | 'Title', |
|
| 114 | ]; |
|
| 115 | ||
| 116 | // keys that need to be present in each signeeref |
|
| 117 | $needSubKeys = [ |
|
| 118 | 'UniqueRef', |
|
| 119 | 'FirstName', |
|
| 120 | 'LastName', |
|
| 121 | 'Email', |
|
| 122 | ]; |
|
| 123 | ||
| 124 | // if the body doesn't have needed fields, throw an exception |
|
| 125 | if (! array_has_all_keys($body, $needKeys)) { |
|
| 126 | throw new BadMethodCallException( |
|
| 127 | 'Missing fields in input array. Need '.implode(', ', $needKeys) |
|
| 128 | ); |
|
| 129 | } elseif (! is_array($body['SigneeRefs'])) { |
|
| 130 | throw new UnexpectedValueException('SigneeRefs key in input should be an array'); |
|
| 131 | } else { |
|
| 132 | foreach ($body['SigneeRefs'] as $ref) { |
|
| 133 | if (! is_array($ref)) { |
|
| 134 | throw new UnexpectedValueException('Each item in SigneeRefs should be an array'); |
|
| 135 | } elseif (! array_has_all_keys($ref, $needSubKeys)) { |
|
| 136 | throw new BadMethodCallException( |
|
| 137 | 'Missing fields in SigneeRefs item. Need '.implode(', ', $needSubKeys) |
|
| 138 | ); |
|
| 139 | } |
|
| 140 | } |
|
| 141 | } |
|
| 142 | ||
| 143 | // make the URL for this request |
|
| 144 | $url = $this->transformUrl(self::URI); |
|
| 145 | ||
| 146 | // get the headers for this request |
|
| 147 | $headers = $this->headers->make('POST', $url, $body, true); |
|
| 148 | ||
| 149 | // get the response |
|
| 150 | $response = $this->client->post($url, [ |
|
| 151 | 'headers' => $headers, |
|
| 152 | 'json' => $body, |
|
| 153 | ]); |
|
| 154 | ||
| 155 | // return the response |
|
| 156 | return $response; |
|
| 157 | } |
|
| 158 | ||
| 159 | /** |
|
| 160 | * Creates a app launch uri for the BankID app. |
|