Let's say I want to build a product that let companies settle cross-border payments for invoices using DAI (https://makerdao.com/en/dai/) as medium of exchange to ensure stable value of the transaction.
I already started building a Prototyp but got stuck at some point. The idea is the following:
- Biller creates an invoice that is stored on a smart contract
- Receiver interacts with dapp to settle payment in DAI to the smart contract
- Smart contract act as custody and redirect payment to biller once the invoice is fully payed (Receiver can also pay partially)
I was already able to to the following:
- Created a smart contract that let biller create and manage invoices
Created a ethers.js based dapp that let receivers:
unlock the usage of DAI token ("approve" function on DAI smart contract)
Settle payment (using transferFrom to send DAI tokens to smart contract)
However, that's where I'm stuck. The part that is missing:
Incoming payment from receiver is stored in smart contract
Smart contract run some function to trigger payment to biller (if invoice was fully payed)
I came to understand that there are no ways to trigger my smart contract once the receiver sends the DAI token, thus the DAI token would be transfered to the smart contract but wouldn't trigger the smart contract logic to update the invoice status and forwarding payment to biller. Given this scenario, how could possible solutions look like?