diff --git a/README.md b/README.md index 6e4e566..b448207 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ You can change some properties of a voucher that has been already created: - start date - expiration date - active -- additinal info +- additional info - metadata Other fields than listed above won't be modified. Even if provided they will be silently skipped. @@ -397,6 +397,44 @@ $voucher_update = (object) array( $updated_voucher = $voucherify->update($voucher_update); ``` +#### Publishing voucher + +This method selects a voucher that is suitable for publication, adds a publish entry and returns the voucher. +A voucher is suitable for publication when it's active and has not been published more times than the redemption limit. + +Example: + +Using campaign name: + +```php +$published_voucher = $voucherify->publish("First Ride"); +``` + +Using object with campaign name: + +```php +$payload = (object) array( + "campaign" => "First Ride", + "channel" => "SDK Test", + "customer" => "alice.morgan@mail.com" +); + +$published_voucher = $voucherify->publish($payload); +``` + +Using object with specific voucher code: + +```php +$payload = (object) array( + "voucher" => "Summer-2016", + "channel" => "SDK Test", + "customer" => "alice.morgan@mail.com" +); + +$published_voucher = $voucherify->publish($payload); +``` + + #### Disabling voucher You can make a voucher inactive by calling `VoucherifyClient->disable` with a voucher code: @@ -691,6 +729,7 @@ Result: `This endpoint does not return result` ### Changelog +- **2016-09-13** - `0.11.0` - Added new API method for voucher - publish - **2016-09-13** - `0.10.0` - Added new API method for voucher - delete - **2016-09-13** - `0.9.1` - Fix to maintain builder pattern. - **2016-07-20** - `0.9.0` - Voucher code pattern. diff --git a/VoucherifyClient.php b/VoucherifyClient.php index ea76453..fa572ba 100644 --- a/VoucherifyClient.php +++ b/VoucherifyClient.php @@ -80,6 +80,27 @@ public function disable($code) { return $this->apiRequest("POST", "/vouchers/" . urlencode($code) . "/disable", NULL, NULL); } + /** + * @param $campaignName + * @return mixed + * @internal param string $code Enable voucher with given code.* + * Enable voucher with given code. + * + */ + public function publish($campaignName) { + $payload = NULL; + + if (gettype($campaignName) === "string") { + $payload = ["campaign" => $campaignName]; + } + + if (gettype($campaignName) === "object") { + $payload = $campaignName; + } + + return $this->apiRequest("POST", "/vouchers/publish", NULL, $payload); + } + /** * @param string $code * @param boolean|null $force