zgabievi / laravel-promocodes Goto Github PK
View Code? Open in Web Editor NEWCoupons and promotional codes generator for Laravel.
License: MIT License
Coupons and promotional codes generator for Laravel.
License: MIT License
Hi,
Request support for Laravel 6.0 :)
Thanks :)
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 ?
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.
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:
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.
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
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?
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.
For example: InvalidPromocodeExceprion
, it should be InvalidPromocodeException
, matching the parent name.
Not sure if it is in purpose or not.
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:
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):
Additional context
Add any other context about the problem here.
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.
May be need add conditional: if ($promocode->isDisposable() && $promocode->users()->wherePivot(config('promocodes.related_pivot_key'), $this->id)->exists()) {
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)
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.
array $data = []
May I know whats the use case for additional data and what it use to store?
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 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.
Hello, thank you for the package. What should be done when the user wants to apply the promo code? And the display of errors is intended?
I think validation should be added with Laravel
https://laravel.com/docs/9.x/validation#custom-validation-rules
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
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?
I wonder why is_used
is commented everywhere?
Are you working on it right now?
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).
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.
Please update to support Laravel 5.6
Thanks!
Hi Author,
Can you please upgrade this package to support Laravel 7?
Thanks :)
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:
It seems it needs a little refactoring with the relationships.
Thanks!
I want to have one promocode to use it 30 times with different users.
Can I do it?
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?
Please release a new version so we can use the package with PHP v8
Thank you!
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.
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 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
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 table
promocodes (
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)
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:
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):
Additional context
-none-
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
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
I keep getting this error when i add your package
[Symfony\Component\Debug\Exception\FatalErrorException] parse error, expecting
']''`
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');
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)
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
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:
Authenticatable
Expected behavior
Any custom user model should be allowed. Perhaps use the one provided in config file for this as well.
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
Hi, your package is really good.
But what about to be able to add some properties to the promo. So we can retrieve later.
Like this package uses: https://docs.spatie.be/laravel-medialibrary/v5/advanced-usage/adding-custom-properties.
What do you think?
i change
'providers' => [
// ...
Gabievi\Promocodes\PromocodesServiceProvider::class
],
to
Gabievi\Promocodes\ServiceProvider::class,
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.