Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/payscript/example_scripts/tax_optimisation.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
trigger = "transaction"; // Trigger definition - The automation will trigger on specified transactions.

// Define the parameters required
def reserveId = ${reserveId:String}; // The reserve where tax will be sent to
def taxFactor = ${taxFactor:decimal}; // What portion of the payment is owed in taxes


// Basic validation
if (taxFactor <= BigDecimal.ZERO || taxFactor > BigDecimal.ONE) {
throw new IllegalArgumentException("Invalid taxFactor: ${taxFactor}. Must be > 0 and ≤ 1.");
}


// Unpack values from the payment event that triggered this script.
def eventPaymentId = event[paymentId:string];
def eventPaymentInfo = getPaymentInfo(eventPaymentId);
def eventPaymentAmount = eventPaymentInfo.amountInfo.amount;


// Calculate the tax amount to be saved
def saveTaxAmount = eventPaymentAmount.multiply(taxFactor);

// Add funds to reserve
addFundsToReserve(eventPaymentInfo.payee.identifier, reserveId, saveTaxAmount, "Automated tax optimisation");

// Log useful information
println("Saving tax completed successfully to reserve: ${reserveId}");
16 changes: 16 additions & 0 deletions docs/payscript/example_scripts/tax_optimisation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Tax Optimisation
parent: Example Scripts
layout: page
---

# Reserve Funds
This script triggers on incoming transactions to set aside a percentage of the transaction into a reserve, for the purposes of saving it for tax payments.

<div style="text-align: center;" markdown="1">
[Download](tax_optimisation.groovy){: .btn }
</div>

{% highlight groovy %}
{% include_relative tax_optimisation.groovy %}
{% endhighlight %}
2 changes: 1 addition & 1 deletion docs/payscript/example_scripts/topup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def account_parent = ${account_parent:scan};
def account_child = ${account_child:scan};
def topUpGoal = ${topUpGoal:decimal};

balance = getBalance(account_child);
balance = getBalance(account_child).getAvailableBalance();

if (balance < topUpGoal) {
def payment = PaymentInfo.builder()
Expand Down
7 changes: 5 additions & 2 deletions docs/tutorials/tutorial_reserves.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ nav_order: 4
---

# Reserves
Reserves are an abstract segregation of funds that can be used to help manage an account's funds. Funds that are moved to a reserve are still in that acconut, and count toward its total balance, however they won't count towards their available balance and won't be able to be used until it is moved out of the reserve.
Reserves are an abstract segregation of funds that can be used to help manage an account's funds. Funds that are moved to a reserve are still in that acconut, and count toward its total balance, however they won't count towards their available balance and won't be able to be used until they are moved out of the reserve. Reserves also keep a history of the transactions made to and from them.


<div style="text-align: center;">
<img src="/assets/images/tutorial3/reserves.png" width="90%">
</div>

Reserves also keep a history of the transactions made to and from them.
{% highlight groovy %}
{% include payscript/example_scripts/tax_optimisation.groovy %}
{% endhighlight %}
Loading