I want to add amount as store credit by:

-> API

-> Using Payment Method

By default store credit is added when we redeem gift card. But my requirement is to add store credit directly by customer using some payment method and also amount could be recharged using API.

The other important requirement is all amounts have Expiry Date.

For Example:

On 10 July Customer added 20$ as store credit. Then on July 20 same customer added 40$,

So now total balance will be 60$.

The expiry date should be different for 20$ and different for 40$ w.r t their creation dates.

Also when customer buys some thing the amount should be deducted from the one, which is expiring first.

The below image of table explains the logic more, I populated table as an example, using static values in Model.enter image description here

My Findings:

If we go to STORES->SALES->GIFT Cards ->Gift Card General Settings: here 'Generate Gift Card Account when Order Item is'

enter image description here

These are two observers that create Gift Card Account, in vendor at:


I want to understand store credit flow and get full control on store credit transactions to add amount using API or payment method with custom feature of expiry date.

Edit 1: I figured class which is responsible for applying store credit:


<preference for="Magento\CustomerBalance\Api\BalanceManagementInterface" type="Magento\CustomerBalance\Model\BalanceManagement" />

In class Magento\CustomerBalance\Model\BalanceManagement, I am trying by making plugin of apply() methhod as afterApply():

namespace Vendor\Module\Plugin;

use \Magento\CustomerBalance\Api\BalanceManagementInterface;

class WalletPlugin
     * @var \Magento\Quote\Api\CartRepositoryInterface
    protected $cartRepository;

     * @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
   public function __construct(
        \Magento\Quote\Api\CartRepositoryInterface $cartRepository
    ) {
        $this->cartRepository = $cartRepository;
     * {@inheritdoc}
    public function afterApply(Magento\CustomerBalance\Model\BalanceManagement $subject, $result)
        /** @var \Magento\Quote\Api\Data\CartInterface $quote */
        echo "I am here";


Edit 2: This is the class which redeems gift card


But no luck yet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.