I’m learning this now! It’s a little non-trivial, although it is covered in the examples Roman provided.
You can get an account-identifier
by hashing the principal of the canister together with a “subaccount” which can be pretty much any other value converted into a blob. Any account-identifier
that starts with your canister’s principal can be controlled by your canister.
You’ll need to convert it into a string, for people to send money to it, though.
Because this isn’t very easy to drop into an existing app, I’m building an invoice canister that will simplify the experience for a lot of use cases. Payments - Invoice Canister Design Review. With the invoice, you’ll be able to run a simple query to find out your default account-identifier to transfer into, and you’ll be able to make an invoice for an amount to be paid, and easily check whether the payment has been satisfied