Page 1 of 2

Custom gift voucher feature

Posted: 18 Jan 2018, 10:14
by techgeekh
Hello, I am currently trying to implement a gift voucher feature where every user will have a virtual wallet attached to their account.

I am trying to get an idea if there is a better way or a built in way to do this.

Note : We are using React.js on the frontend and using aimeos as a backend via the REST API.

My way of thinking is to create for example 4 products with a custom type "Voucher"
- 100 £ Voucher
- 50 £ Voucher
- 25 £ Voucher
- 10 £ Voucher

At first when the user purchases the gift voucher let's say for example a "100 £" voucher, during the purchase process, the user will not get asked to enter a shipping address and will not have the ability to pay for the voucher with their account balance.

For this I was thinking of implementing a separate process to pay for vouchers and not use the default cart behaviour process, so that the user can choose the voucher and directly pay for it.

After the payment process is complete, the user will get an email that contains the voucher code, he can then either apply the voucher to their account or send it to a friend.

For this I was thinking of creating a separate table in the database to store a randomly generated voucher code that we are going to generate on the backend and the voucher value and a boolean so that the code can only be used one time only.

After the voucher code is applied on an account, the account balance will change accordingly to the voucher value.

To hold the account balance I was thinking of creating another table in the database that is linked to the user id.

When the user tries to purchase products from the site, and if the account balance is greater or equal to the cart total, the user can use their account balance as a payment method and pay for their cart.

For this I was thinking of creating a custom payment service named for Example "Account Balance" so that when we create an order we set the payment method to that service.

Re: Custom gift voucher feature

Posted: 19 Jan 2018, 11:32
by aimeos
We would suggest that solution:
- Create a new product type "voucher"
- Implement a decorator for the basket controller like the existing ones that handles the new voucher products (https://github.com/aimeos/ai-controller ... /Decorator)
- Generate the voucher codes in that decorator and add them as order product attributes
- Often, customers will have mixed baskets with voucher+articles so they should be able to buy them together
- Extend the payment related e-mail to show the voucher codes if the order has been payed (same as downloads)
- Add a new table e.g. "users_balance" that will contain the amounts that have been bought and redeemed (like a bank account with contains each "transaction"), the reason and the voucher code
- Implement some code so users can add vouchers resp. their amounts to their account balance. There you can check if a voucher has already been redeemed
- Implement a new payment service provider (e.g. AccountBalance) that calculates the latest balance
- Customers should be able to pay partly with their balance if the have not enough. This requires Aimeos 2018.01 because there it's possible to have multiple payments per order
- Create a pull request with your changes to get them into the Aimeos Core :-)

Re: Custom gift voucher feature

Posted: 18 Mar 2019, 11:05
by Moritz
At the moment I am trying to implement such a virtual wallet for users.
Therefore I created the new product type "balance".
Now I want that when buying such a product (after successful payment) the value is stored in the table user_balance.
Where is the best place to do that? Should I implement a special controller for the new product type?

Re: Custom gift voucher feature

Posted: 19 Mar 2019, 09:43
by aimeos
The gift card / voucher feature is part of the core since at least 2018.10, so you only have to create a product of type "Voucher" and run the job controller for "order/email/voucher" regularly:
https://aimeos.org/docs/Laravel/Configu ... jobs#Setup

Re: Custom gift voucher feature

Posted: 19 Mar 2019, 09:54
by Moritz
I don't want to use the voucher feature.
Our customer needs a very special contingent/wallet feature.
To archive that I should know the place where I can execute code for a special product after successfully payment.

Re: Custom gift voucher feature

Posted: 20 Mar 2019, 10:48
by aimeos
You can either create a new job controller that loads the order and performs the actions to need. In that case you have to make sure that the actions are only performed once per order: https://aimeos.org/docs/Developers/Cont ... controller

The better alternative might be to create a delivery service decorator which receives the order item only once so you don't have to care about duplicate actions because the order/service/delivery job controller does that for you: https://aimeos.org/docs/Developers/Library/Service

Re: Custom gift voucher feature

Posted: 21 Mar 2019, 08:26
by Moritz
But can I also use a decorator if the user select "Prepay" as payment method and the admin sets the payment status to "received" in the backend later?

Re: Custom gift voucher feature

Posted: 21 Mar 2019, 13:02
by aimeos
Setting the order payment status in the backend doesn't call the payment provider and its decorators. It only marks the order for being ready to process by the delivery service provider and its decorators.

Re: Custom gift voucher feature

Posted: 22 Mar 2019, 11:57
by Moritz
Thanks for your help!
That solves my problem.

Re: Custom gift voucher feature

Posted: 22 Oct 2019, 07:28
by Stefan80
Hello,

I have a question to the gift card / voucher feature: the voucher product(s) should not have a shipping cost, but when its mixed with a regular product the shipping cost should be 4,95€ (DHL).

How can I solve this?

thanks