Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.x] Implement customer balances #1216

Merged
merged 2 commits into from
Jul 5, 2021
Merged

[13.x] Implement customer balances #1216

merged 2 commits into from
Jul 5, 2021

Conversation

driesvints
Copy link
Member

@driesvints driesvints commented Jul 2, 2021

This PR implements some API's around customer balances. This will make it easier for apps to retrieve a customer's balance, apply new balance transactions and display a history of balance adjustments.

// Retrieve current balance...
$balance = $user->balance(); // $5.00

// Credit new balance...
$user->applyBalance(-500, 'Premium customer top-up.');

// Debit balance...
$user->applyBalance(300, 'Bad usage penalty.');

// Retrieve all transactions...
$transactions = $user->balanceTransactions();

// Display all transactions...
foreach ($transactions as $transaction) {
    // Specific amount of the transaction...
    $amount = $transaction->amount(); // $2.31

    // Retrieve the related invoice when available...
    $invoice = $transaction->invoice();
}

Closes #762

@taylorotwell taylorotwell merged commit 048392e into 13.x Jul 5, 2021
@taylorotwell taylorotwell deleted the balances branch July 5, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support credit against a subscription renewal
2 participants