diff --git a/src/app/action/controllers/ShippingTrait.php b/src/app/action/controllers/ShippingTrait.php index 62aea920752d29314934bf97ea2557111868d79e..abf8ffff3a4fde4098ea8d4b257fa3f595414c7d 100644 --- a/src/app/action/controllers/ShippingTrait.php +++ b/src/app/action/controllers/ShippingTrait.php @@ -71,7 +71,7 @@ trait ShippingTrait if (empty($contact[0])) { return ['errors' => ['Contact does not exist for attachment']]; } - if (!empty($contact['address_country']) && strtoupper(trim($contact['address_country'])) != 'FRANCE') { + if (!empty($contact[0]['address_country']) && strtoupper(trim($contact[0]['address_country'])) != 'FRANCE') { return ['errors' => ['Contact country is not France']]; } $afnorAddress = ContactController::getContactAfnor($contact[0]); @@ -119,20 +119,11 @@ trait ShippingTrait $errors[] = "Maileva sending creation failed for attachment {$attachmentId}"; continue; } - - $sendings = CurlModel::execSimple([ - 'url' => $mailevaConfig['uri'] . '/mail/v1/sendings', - 'bearerAuth' => ['token' => $token], - 'method' => 'GET' - ]); - if ($sendings['code'] != 200) { - $errors[] = "Maileva get sendings failed for attachment {$attachmentId}"; - continue; - } - - foreach ($sendings['response']['sendings'] as $sending) { - if ($sending['name'] == $sendingName) { - $sendingId = $sending['id']; + foreach ($createSending['headers'] as $header) { + if (strpos($header, 'Location:') !== false) { + $sendingId = strrchr($header, '/'); + $sendingId = substr($sendingId, 1); + break; } } if (empty($sendingId)) { diff --git a/src/app/shipping/models/ShippingModel.php b/src/app/shipping/models/ShippingModel.php index 6df206c3035fb4914e8a3055e413de801b9673e7..26a8ec2ceeef0e7ed6f54b1ae9e38026bb7c64f1 100644 --- a/src/app/shipping/models/ShippingModel.php +++ b/src/app/shipping/models/ShippingModel.php @@ -31,7 +31,7 @@ class ShippingModel 'columnsValues' => [ 'user_id' => $args['userId'], 'attachment_id' => $args['attachmentId'], - 'is_version' => $args['isVersion'], + 'is_version' => empty($args['isVersion']) ? 'false' : 'true', 'options' => $args['options'], 'fee' => $args['fee'], 'recipient_entity_id' => $args['recipientEntityId'], diff --git a/src/core/models/CurlModel.php b/src/core/models/CurlModel.php index 51a002843674aad66c21101c16556346b4c458d4..98630f7abef6a64823c5c9101bd69339652b8cd4 100644 --- a/src/core/models/CurlModel.php +++ b/src/core/models/CurlModel.php @@ -261,7 +261,7 @@ class CurlModel ValidatorModel::stringType($args, ['url', 'method', 'user', 'password']); ValidatorModel::arrayType($args, ['headers', 'body', 'queryParams', 'basicAuth', 'bearerAuth']); - $opts = [CURLOPT_RETURNTRANSFER => true]; + $opts = [CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true]; //Headers if (!empty($args['headers'])) { @@ -312,11 +312,15 @@ class CurlModel $curl = curl_init(); curl_setopt_array($curl, $opts); $rawResponse = curl_exec($curl); - $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $errors = curl_error($curl); curl_close($curl); + $headers = substr($rawResponse, 0, $headerSize); + $headers = explode("\r\n", $headers); + $response = substr($rawResponse, $headerSize); + LogsController::add([ 'isTech' => true, 'moduleId' => 'curl', @@ -324,10 +328,10 @@ class CurlModel 'tableName' => 'curl', 'recordId' => 'execSimple', 'eventType' => "Url : {$args['url']} HttpCode : {$code} Errors : {$errors}", - 'eventId' => "Response : {$rawResponse}" + 'eventId' => "Response : {$response}" ]); - return ['code' => $code, 'response' => json_decode($rawResponse, true), 'errors' => $errors]; + return ['code' => $code, 'headers' => $headers, 'response' => json_decode($response, true), 'errors' => $errors]; } private static function createMultipartFormData(array $args)