Skip to content

Commit

Permalink
Merge pull request voucherifyio#29 from rspective/publish-update
Browse files Browse the repository at this point in the history
Publish update
  • Loading branch information
LukaszWiktor authored Oct 24, 2016
2 parents 6219d95 + e965e4e commit 25c909c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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" => "[email protected]"
);

$published_voucher = $voucherify->publish($payload);
```

Using object with specific voucher code:

```php
$payload = (object) array(
"voucher" => "Summer-2016",
"channel" => "SDK Test",
"customer" => "[email protected]"
);

$published_voucher = $voucherify->publish($payload);
```


#### Disabling voucher

You can make a voucher inactive by calling `VoucherifyClient->disable` with a voucher code:
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions VoucherifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25c909c

Please sign in to comment.