This is a payment widget that allows you to enable payment via TON Crystal Extension. It is added to any site through the connection of the library and the simplest in-page configuration. The site can trigger a widget pop-up window when it is necessary to accept a payment from a client.
- Set the widget code on your site. The library of a particular version is connected from the official Broxus repository or downloaded by the merchant to their servers independently: <script src="https://github.com/broxus/..." />
- Write the necessary configuration and payment callbacks
- Add a button that calls the widget to the site.
- That is all. You can accept payments.
In the first iteration, coins supported by the TON Crystal wallet are added:
- TON Crystal
- TIP-3/Broxus
The merchant specifies the specific list of accepted currencies independently in the configuration.
The widget stores a sorted array with the accepted currencies in the config.currencies parameter . In this case, you can specify either as symbolic names of currencies (from the official list of currencies), or by specifying the address of the root contract of the token.
Through direct assignment
tonaccept.config.currencies = ['TON', 'USDC'];
or by calling the setCurrencies method
tonaccept.config.setCurrencies(['TON', 'USDC']);
or by specifying a REST method that will return a sorted list in the form of a simple sorted JSON array
tonaccept.config.currenciesRemote = 'https://localhost/currencies';
The merchant can set the name and icon of his store:
tonaccept.config.storeIcon = 'https://localhost/icon';
tonaccept.config.storeAddress = 'https://localhost/';
tonaccept.config.storeName = 'Megastore';
This data will be displayed on the widget.
The merchant can specify one or more addresses for accepting payments:
tonaccept.addresses.push('0:...');
If you specify several addresses, the specific one at the time of payment will be selected randomly.
Conversion via TON Swap
The merchant can call the payment window using the following method:
tonaccept.requestPayment(orderId, description, amount, [currency], [validUntilUtc], [onSuccess], [onFailure]);
By default, all payments are denominated in USDT, unless an alternative currency is specified. If an alternative currency is specified, then if it is available on TON Swap in a pair to WTON, then an attempt will be made to search for rates to the other accepted currencies. If it is not available, the widget will display only it.
Upon successful completion of the payment, the callback specified in onSuccess is called, and the hash of the transaction is passed to it. If the widget window is closed or the payment is unsuccessful, onFailure is called .
Alternatively, if the product is denominated in several currencies, you can use the following method:
let price = new Map();
price.set('TON', 100);
price.set('USDC', 40);
tonaccept.requestMultiCurPayment(orderId, description, price, baseCurrency, [validUntilUtc], [onSuccess], [onFailure]);
In the case of specifically specified multi-currency prices, auto-conversion via TON Swap is not carried out!