Skip to content

Commit

Permalink
Merge pull request #1 from spira/feature/verify-function
Browse files Browse the repository at this point in the history
Adding validate function to SDK. Updating error response so that read…
  • Loading branch information
Jeremy Sik authored Nov 4, 2016
2 parents 25c909c + ff2a47a commit d369085
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions VoucherifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ public function redeem($code, $trackingId) {
return $this->apiRequest("POST", "/vouchers/" . urlencode($code) . "/redemption/", ["tracking_id" => $trackingId], $context);
}

/**
* @param string|array $code Voucher code or array with voucher (code), customer profile and order amount
* @param string|null $trackingId Provided tracking id
*
* Validate voucher
*
* @throws Voucherify\ClientException
*/
public function validate($code, $trackingId = NULL) {
$context = array();
if (is_array($code)) {
$context = $code;
$code = $context["voucher"];
unset($context["voucher"]);
}

return $this->apiRequest("POST", "/vouchers/" . urlencode($code) . "/validate", ["tracking_id" => $trackingId], $context);
}

/**
* @param string $redemptionId
* @param string|null $trackingId
Expand Down
4 changes: 4 additions & 0 deletions VoucherifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ protected function apiRequest($method, $endpoint, $params, $data) {
throw new ClientException($error);
} // Invalid status code
else if ($statusCode >= 400) {
$resultDecoded = json_decode($result, true);
if($resultDecoded && $resultDecoded['message']) {
throw new ClientException($resultDecoded['message']);
}
throw new ClientException("Unexpected status code: " . $statusCode . " - Details: " . $result);
}

Expand Down

0 comments on commit d369085

Please sign in to comment.