zgabievi/laravel-promocodes

Gift Card feature

Closed this issue · 1 comments

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.

This package was created to be flexible on, so that everyone should be able to use it in most (hopefully any) cases.

To achieve goal you have described, here is a snippet that should help you with that.

  1. You need to create promocodes that will be bound to specific users, either from the time of creation or after first use of them:
createPromocodes(
  count: 10,
  unlimited: true,
  multiUse: true,
  boundToUser: true,
  details: [ 'amount' => 100 ]
);

This will create 10 promocodes, with unlimited usages, ability to be used multiple times by a single user, it will be bound to the user after the first time they use it, and it will store 100 as an amount for details.

  1. Now when user applies promocode you should manually update amount in details.
$amountToSubtract = 80;

$promocode = Promocode::findByCode('AA-BB-CC')->firstOrFail();

if ($promocode->details['amount'] >= $amountToSubtract) {
  $promocode->update(['details' => ['amount' => $promocode->details['amount'] - $amountToSubtract]]);
}

// ...

This should do the trick.

P.S. Your idea is good enough to make me think of better solution, so I will try to solve it, without loosing flexibility.