Skip to content

Commit

Permalink
Merge branches 'master', 'master', 'master', 'master' and 'master' of…
Browse files Browse the repository at this point in the history
… github.com:zgabievi/laravel-promocodes
  • Loading branch information
zgabievi committed May 30, 2019
2 parents ab11dd8 + 16f1b9b commit 2dd44f6
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Install this package via Composer:
$ composer require zgabievi/promocodes
```

> If you are using Laravel 5.5, then installation is done. Otherwise follow the next steps.
> If you are using Laravel 5.5 or later, then installation is done. Otherwise follow the next steps.
#### Open `config/app.php` and follow steps below:

Expand Down Expand Up @@ -76,6 +76,12 @@ You will get array of codes in return:
Promocodes::output($amount = 1);
```

#### Parameters

| name | type | description | required? |
| ----- | ---- | ----------- | ------- | --------- |
| $amount | number | Number of items to be generated | NO |

---

Create as many codes as you wish. Set reward (amount).
Expand All @@ -87,15 +93,26 @@ By default generated code will be multipass (several users will be able to use t
They will be saved in database and you will get collection of them in return:

```php
Promocodes::create($amount = 1, $reward = null, array $data = [], $expires_in = null);
Promocodes::create($amount = 1, $reward = null, array $data = [], $expires_in = null, $quantity = null, $is_disposable = false);
```

If you want to create code that will be used only once, here is method for you.

```php
Promocodes::createDisposable($amount = 1, $reward = null, array $data = [], $expires_in = null);
Promocodes::createDisposable($amount = 1, $reward = null, array $data = [], $expires_in = null, $quantity = null);
```

#### Parameters

| name | type | description | default | required? |
| ----- | ---- | ----------- | ------- | --------- |
| $amount | integer | Number of promocodes to generate | 1 | NO |
| $reward | float | Number of reward that user gets (ex: 30 - can be used as 30% sale on something) | null | NO |
| $data | array | Any additional information to get from promocode | [] | NO |
| $expires_in | integer | Number of days to keed promocode valid | null | NO |
| $quantity | integer | How many times can promocode be used? | null | NO |
| $is_disposable | boolean | If promocode is one-time use only | false | NO |

---

Check if given code exists, is usable and not yet expired.
Expand All @@ -108,6 +125,12 @@ Returns `Promocode` object if valid, or `false` if not.
Promocodes::check($code);
```

#### Parameters

| name | type | description | required? |
| ----- | ---- | ----------- | ------- | --------- |
| $code | string | Code to be checked for validity | YES |

---

If you want to check if user tries to use promocode for second time you can call `Promocodes::isSecondUsageAttempt` and pass `Promocode` object as an argument. As an answer you will get boolean value
Expand All @@ -127,6 +150,13 @@ Promocodes::redeem($code);
Promocodes::apply($code);
```


#### Parameters

| name | type | description | required? |
| ----- | ---- | ----------- | ------- | --------- |
| $code | string | Code to be applied by authenticated user | YES |

---

You can immediately expire code by calling *disable* function. Returning boolean status of update.
Expand All @@ -135,6 +165,12 @@ You can immediately expire code by calling *disable* function. Returning boolean
Promocodes::disable($code);
```

#### Parameters

| name | type | description | required? |
| ----- | ---- | ----------- | ------- | --------- |
| $code | string | Code to be set as invalid | YES |

---

And if you want to delete expired, or non-usable codes you can erase them.
Expand Down

0 comments on commit 2dd44f6

Please sign in to comment.