Skip to content

Commit

Permalink
Fix handle callback return value
Browse files Browse the repository at this point in the history
  • Loading branch information
davc0n committed May 11, 2023
1 parent eb67f91 commit 907e571
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ModernMT.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function batchTranslate($webhook, $source, $target, $q, $hints = null, $c
* @throws ModernMTException
* @throws SignatureException
*/
public function handleCallback($data, $signature) {
public function handleCallback($body, $signature) {
// Verify callback signature
try {
$key = ModernMT::getPublicKey();
Expand All @@ -151,11 +151,11 @@ public function handleCallback($data, $signature) {
throw new SignatureException($e->getMessage());
}

if (is_string($data))
$data = json_decode($data, true);
if (is_string($body))
$body = json_decode($body, true);

$result = $data["result"];
$metadata = isset($data["metadata"]) ? $data["metadata"] : null;
$result = $body["result"];
$metadata = isset($body["metadata"]) ? $body["metadata"] : null;

$status = $result["status"];
if ($status >= 300 || $status < 200) {
Expand All @@ -165,7 +165,7 @@ public function handleCallback($data, $signature) {

throw new ModernMTException($status, $type, $message, $metadata);
} else {
return ["result" => $result["data"], "metadata" => $metadata];
return ["data" => $result["data"], "metadata" => $metadata];
}
}

Expand Down

0 comments on commit 907e571

Please sign in to comment.