GithubHelp home page GithubHelp logo

laravel-promocodes's People

Contributors

zgabievi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-promocodes's Issues

Installation error: Dependencies

I'm trying to install your package, but get this:

  Problem 1
    - zgabievi/promocodes[8.1.0, ..., 8.1.1] require doctrine/dbal ^2.10 -> found doctrine/dbal[v2.10.0, ..., 2.12.x-dev] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires zgabievi/promocodes ^8.1 -> satisfiable by zgabievi/promocodes[8.1.0, 8.1.1].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Any suggestions ?

Gift Card feature

When users purchase vouchers, the user can use that same voucher more than 1 time (Partial usage of voucher in case cart value is less than voucher value). Every time he uses the voucher, the amount will deduct from the voucher and the remaining amount will be stored as the current voucher amount. (gift cards feature)

How to create promo codes with flat discounts or percentage-wise discounts.

apply promocode facade does not use the column name specified in config file

Describe the bug
If i change the 'foreign_pivot_key' => 'promocode_id' (default) to 'foreign_pivot_key' => 'promo_code_id', then apply promoccode gives the error "promocode_id column not found in pivot table"

To Reproduce
Steps to reproduce the behavior:

  1. Install this package
  2. Goto promocodes.php config file and set 'foreign_pivot_key' => 'promo_code_id'
  3. Generate any promocode and try to apply with the authenticated user.
  4. See error ("promocode_id column not found in pivot table")

please refer to the funccitonal below:

/**
* Apply promocode to user that it's used from now.
*
* @param string $code
*
* @return bool|Promocode
* @throws AlreadyUsedException
* @throws UnauthenticatedException
*/
public function apply($code)
{
if (!auth()->check()) {
throw new UnauthenticatedException;
}

    if ($promocode = $this->check($code)) {
        if ($this->isSecondUsageAttempt($promocode)) {
            throw new AlreadyUsedException;
        }

        $promocode->users()->attach(auth()->id(), [
            'promocode_id' => $promocode->id,
            'used_at' => Carbon::now(),
        ]);

        if (!is_null($promocode->quantity)) {
            $promocode->quantity -= 1;
            $promocode->save();
        }

        return $promocode->load('users');
    }

    return false;
}

In the above function, promocode_id is hardcoded which should be readable from config file.

No way to check if this is a second usage of promocode

Hi,

Currently there is no way to check if this is a second usage of promo code for a particular user, even though there is a function available, it can't be used as it is private.

If we can change it to be a public function this will help in checking the usage. We can update the documentation too.

Pull request: #32

How to use this? theres little documentation on this

I've installed the package, I wanted to start using it but theres little to no documentation for that.. How can I use this in an admin page? I want to add/remove codes but I don't know which model I should import and so on...

Can someone explain please?

Flexible subscription discounts

Hi,

I think this package is great as it is for one-off payments.

I'm however working on a client (SDK) for a subscription payment service and looking for coupon discount solutions.

Are there any plans for supporting subscriptions (sequential transactions)? When looking at Stripe for example, they support these use cases:

Coupons in Stripe provide discounts on recurring charges. Like subscriptions, coupons allow for great flexibility in how you define and use them. They can:

  • Apply to every invoice, just one invoice, or for a certain length of time
  • Reduce invoices by a percentage or a flat amount
  • Apply to every subscription a customer has or only specific ones

You can even define a coupon that must be redeemed by a certain date or is limited to a set number of redemptions (across all of your customers).

It would be great to have a coupon package that supports cases like these.

Typo in Exception names

For example: InvalidPromocodeExceprion, it should be InvalidPromocodeException, matching the parent name.

Not sure if it is in purpose or not.

Relation table migration

Describe the bug
If I define user_model that is, say, Customer model in config file, the table migration doesn't use the config file value to create the related table.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'promocodes.php
  2. Modify 'user_model' to use a different table. I use Customer instead of default User table.
  3. When you run 'php artisan migrate' after that, the promocode_user table still refers to Users table in the relationship (fk).

Expected behavior
Migration file should use the 'user_model' property from config("user_model").

This line(35) needs to be updated:
$table->foreign('user_id')->references('id')->on('user);

Versions (please complete the following information):

  • Laravel: [e.g. 5.6]
  • PHP [e.g. 7.2]

Additional context
Add any other context about the problem here.

Would it be nice if we let user specify the Promocode model in the config file?

Is your feature request related to a problem? Please describe.
I wanted to modify the Promocode model but the package uses the vendor model directly. Which reduces the scope for extension. Like, I modified the migration and included timestamps, but it was turned off at model level.

Describe the solution you'd like
I would like you have the Promocode model specified in the config file same as User model was specified.

Wrong Disposable promo codes

if ($promocode->users()->wherePivot(config('promocodes.related_pivot_key'), $this->id)->exists()) {

When I want to apply promo code to user twice throw AlreadyUsedException but promo code can use much time...

May be need add conditional: if ($promocode->isDisposable() && $promocode->users()->wherePivot(config('promocodes.related_pivot_key'), $this->id)->exists()) {

Custom Promocodes

Is it possible to have custom Promo codes like OFF20 or SALE50 or similar,
The use case is that these codes will be used on mobile applications mostly.

I couldn't find something like this in the documentation but analyzing the code it seems possible using the model directly (which I feel like is a hacky way to do it)

Add doctrine/dbal 3.0.0

Is your feature request related to a problem? Please describe.
I can't upgrade to doctrine/dbal 3.0.0 because of the dependency on ^2.10 from this package.

Describe the solution you'd like
Add ^3 as a version constraint.

Feature request + Question

Question:
I am using Promocode::check($code) to check if promocode is available or not? But it is throwing InvalidPromocodeException exception, shouldn't it ideally return false, as that is the whole point of this function to check if code is valid or not?

Feature request:

  • I don't see an option to let same user use same promo code multiple times say 2 or 3, how we do this?
  • How do we generate user specific promocodes? Promo code applicable only for a particular user?

Can you give me an idea about something?

I have a question. I wonder how I define the code variable for Laravel Nova. I could not find any kind of correct identification method. Sorry, I apologize for writing here.

Promocodes error in laravel 5.1

Promocodes error in Laravel Vertion 5.1

Following the README.md file instruction installation
after the i created the controller and put the code Promocodes::output($amount = 1).
it gives me error. but i tried in laravel version 5.2 it's works

FatalErrorException in Promocodes.php line 30:
Call to a member function toArray() on string

Able to add reward as percentage

Is the reward able to discount in percentage? With both discount type by amount and also by percentage.
If yes, any doc on how to achieve that?

is_used

I wonder why is_used is commented everywhere?
Are you working on it right now?

Unable to install package

I can't get the package installed for laravel 9. Below is the error:
[InvalidArgumentException]
Could not find a matching version of package zgabievi/laravel-promocodes. Check the package spelling, your version
constraint and that the package is available in a stability which matches your minimum-stability (dev).

Promocode can be used more than once

I believe this package is the best in the category. I noticed one anamoly, calling Promocodes::apply($code) doesn't insert into pivot table and so, a user can use a promocode more than once.

While reading the definition of apply method, i think this line isn't working as it must.

$promocode->users()->attach(auth()->user()->id,[
'used_at' => Carbon::now(),
]);

I'm working to find a fix but I think you would have a better idea.

Promo code for multiple usage

Hi @zgabievi

I like your package and was thinking about using it myself, but I do have one question, because it seems to not be implemented yet:

  • How would you approach the situation if you needed a promo code (like a coupon) that many users should be able to apply to their account? For instance, I send out a marketing campaign saying, "Act now and retrieve 20% off your total bill".

It seems it needs a little refactoring with the relationships.

Thanks!

List all Promocodes method should be there?

There should be one more method which will return all the available promocodes from database.
This method would be used where developer create a UI for code generation, edit, delete etc.

Is anyone there, who feel need for this?

Release new version

Please release a new version so we can use the package with PHP v8

Thank you!

Monetary value?

Hi, thanks for this awesome package. I have plans to include this in a project am working on but I want to understand how can i tweak your code if i want the generated codes to be attached to monetary value. Say how itunes gift card work.

Feature request: Entering own promo codes and promos codes like lyft

Can we enter our own promo codes and as well as pre-generated ones.

Secondly was wondering if you can create the promo codes like LYFT. They give a 50$ coupon, where 5$ is applied per ride till 50 is done so 10 rides.

Or any way you think I can use your packaged to do that ?

And can you please change "Amount" to "number" - I got super confused as to what the diff between amount and reward was

What is the date format for

What is the date format for additional data $expires_in?

my format is like this "2019-01-07 22:45:00", however using the
Promocodes::createDisposable($amount = 1, $reward = null, array $data = [], $expires_in = null);
the date store in different value

promocode migration

Am getting this error while trying to run php artisan migrate after installation:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1064 Y ou have an error in your SQL syntax; check the manual tha t corresponds to your MySQL server version for the right syntax to use near 'json null, is_usedtinyint(1) not n ull default '0') default character set utf8' at line 1 (S QL: create tablepromocodes (idint unsigned not null auto_increment primary key,user_idint unsigned null, codevarchar(32) not null,rewarddouble(10, 2) null ,datajson null,is_usedtinyint(1) not null default '0') default character set utf8mb4 collate utf8mb4_unico de_ci)

promocode_user not getting inserted

Describe the bug
I'm having issue with the promocode_user table which is not inserted once successfully redeem using Redeemable applyCode. Empty data on users

To Reproduce
Steps to reproduce the behavior:

  1. Default setting on fresh laravel 5.8 install

Expected behavior
After redeem, expect the user_id and promocode_id is added intopromocode_user and users response is not empty

Screenshots
{ "success": true, "data": { "id": 1, "code": "T3YT-HS8C", "reward": 30, "quantity": 86, "data": { "restaurant_id": "1" }, "is_disposable": false, "expires_at": "2020-05-28 00:00:00", "created_at": null, "updated_at": "2020-05-27 16:18:26", "users": [] }, "message": "Successfully redeem the promo code" }

Versions (please complete the following information):

  • Laravel: [5.8]
  • PHP [7.4]

Additional context
-none-

Request Feature to get Valid and not Valid Promocodes

i cannot show all promocodes valid and not valid in my dashboard because Promocodes returns just valid
so i suggest to add

Promocodes::all(); // return valid and not valid
Promocodes::valid(); // return valid promocodes
Promocodes::unValid(); // return unvalid 

You have changed an important behavior: Throw AlreadyUsedException when user used it twice but other user can still use it

Unfortunately with this change you have removed an important behaviour:

/** @test */
public function it_throws_exception_coupon_was_used_before()
{
    $this->signIn();

    Coupon::redeem($this->coupon['code']);

    $this->expectException('\Exception');
    $this->expectExceptionMessage(__('vue/checkout.coupon already used'));

    Coupon::redeem($this->coupon['code']);
}

This test is now with the update failing for me. It used to catch the error AlreadyUsedException, but even when is_disposable was set to false.

This is important for this use-case: "Every user gets to use a Promocode, but every user only once'.

The first test and this second test need to be true so that Promocode is working again.

/** @test */
public function multiple_users_can_use_the_same_promocode()
{
    $this->signIn();

    $this->assertInstanceOf('Gabievi\Promocodes\Models\Promocode', Coupon::redeem($this->coupon['code']));

    $this->signIn(); // second user
    
    $this->assertInstanceOf('Gabievi\Promocodes\Models\Promocode', Coupon::redeem($this->coupon['code']));
}

I know that the alternative would be to use isSecondUsageAttempt.

If you don't want to change the code, please update the readme file since it still says Also if authenticated user will try to apply code twice, it will throw an exception

Installation Problem

I keep getting this error when i add your package

[Symfony\Component\Debug\Exception\FatalErrorException] parse error, expecting']''`

Add cascade on delete in database migration.

Describe the bug
In promocode_user table, it has 2 foreign keys to user_id and promocode_id, they should be cascade on delete. Or otherwise, the database throws an exception when trying to delete a user or promocode when a promocode_user entry exists.

Expected behavior
Add ->onDelete('cascade') in 2016_05_17_221000_create_promocodes_table.php

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('promocode_id')->references('id')->on(config('promocodes.table', 'promocodes'))->onDelete('cascade');

Cusom Authetication Model

I am using a different authentication model, it throws an exception saying the App\User cant be found.

[2017-10-02 02:15:10] local.ERROR: Class 'App\User' not found {"userId":1,"email":"[email protected]","exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class 'App\User' not found at /opt/lampp/htdocs/sendchow/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:506)
[stacktrace]
#0 /opt/lampp/htdocs/sendchow/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php(310): Illuminate\Database\Eloquent\Model->newRelatedInstance('App\\User')
#1 /opt/lampp/htdocs/sendchow/vendor/zgabievi/promocodes/src/Models/Promocode.php(60): Illuminate\Database\Eloquent\Model->belongsToMany('App\\User', 'promocode_user')
#2 /opt/lampp/htdocs/sendchow/vendor/zgabievi/promocodes/src/Promocodes.php(133): Gabievi\Promocodes\Models\Promocode->users()
#3 /opt/lampp/htdocs/sendchow/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Gabievi\Promocodes\Promocodes->check('9BNY-K3SW')
#4 /opt/lampp/htdocs/sendchow/vendor/zgabievi/promocodes/src/Traits/Rewardable.php(36): Illuminate\Support\Facades\Facade::__callStatic('check', Array)
#5 /opt/lampp/htdocs/sendchow/vendor/zgabievi/promocodes/src/Traits/Rewardable.php(75): SendChow\Modules\Authentication\Model\UserMock->applyCode('9BNY-K3SW', NULL)
#6 /opt/lampp/htdocs/sendchow/SendChow/Modules/Authentication/Web/Controller/AuthenticationController.php(27): SendChow\Modules\Authentication\Model\UserMock->redeemCode('9BNY-K3SW')
#7 [internal function]: SendChow\Modules\Authentication\Web\Controller\AuthenticationController->login(Object(SendChow\Modules\Authentication\Request\LoginRequest))
#8 /opt/lampp/htdocs/sendchow/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#9 /opt/lampp/htdocs/sendchow/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('login', Array)

Redeem code on a user seems wrong

I just set up the library and gave it a try. Generated few promo codes, and tried redeeming one of the code, but it threw exception and made it clear that it is doing everything wrong.

Errors I noticed:

The users and promocode_user tables relation is defined wrong. Query it is executing is for promocode id 12 and user id 41:
select * from `users` inner join `promocode_user` on `users`.`id` = `promocode_user`.`user_id` where `promocode_user`.`user_id` = 12 and `promocode_user`.`user_id` = 41)

while it should have been:
select * from `users` inner join `promocode_user` on `users`.`id` = `promocode_user`.`user_id` where `promocode_user`.`promocode_id` = 12 and `promocode_user`.`user_id` = 41)

as a result of this, it was saving the wrong details in promocode_user table, instead of saving the user id in user_id column, it was trying to save promocode id in it.

created a pull-request #28 for the fix

Typehint causing issues with custom user model

Describe the bug
On methods such as user() on Promocodes.php, it is typehinted with Illuminate\Foundation\Auth\User, but if you are using a custom User model which doesn't use the default Authenticatable (e.g eloquent uuid pkg), then you can't really use any of this functionality or anything that takes User as a parameter since it's been typehinted this way.

To Reproduce
Steps to reproduce the behavior:

  1. Don't use default Authenticatable
  2. Try pass user as a param to any function in this pkg.

Expected behavior
Any custom user model should be allowed. Perhaps use the one provided in config file for this as well.

Non-global prefix on coupon creation.

Is your feature request related to a problem? Please describe.
I wanted to make a coupon code for an event, and wanted to code having a prefix of the event, e.g. PAXG-XXXX. This is different from the global prefix config because this is used once here only.

Describe the solution you'd like
Add an optional parameter prefix on creating Promocodes::create().

Describe alternatives you've considered
NA

Additional context
NA

Any plans to improve the code quality of the package?

Hello, @zgabievi!

The package looks nice, but a bit outdated.
I faced some problems using it in production, had to override the main class.

What you'll say if I'll send the PR of a more modern typed version of the package, and probably with the option to point out the model to use? It will require PHP 8 and probably Laravel 8.x.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.