Layer 231
PaymentsCreateOnrampSession
Create a session with a fiat-to-crypto on-ramp provider and get the URL where the user completes the purchase. Call it once the provider, currency pair and amount are chosen (see payments. get Onramp Providers, payments. get Onramp Availability and payments. get Onramp Quote). The purchased coins go to the given address, typically the user's built-in wallet address from wallet. get State.
method
payments.createOnrampSession#a2197cf6 flags:# provider:string crypto_currency:string address:string payment_method:flags.0?string base_currency:flags.1?string base_amount:flags.2?string memo:flags.3?string theme:flags.4?string success_return_url:flags.5?string fail_return_url:flags.6?string crypto_amount:flags.7?string = OnrampSession;
Parameters
| Name | Type | Description |
|---|---|---|
| Provider | string | On-ramp provider ID, from payments. get Onramp Providers |
| CryptoCurrency | string | Cryptocurrency to buy, e. g. TON |
| Address | string | Wallet address that will receive the purchased cryptocurrency |
| PaymentMethod | flags.0?string | Payment method to use, as returned by payments. get Onramp Availability |
| BaseCurrency | flags.1?string | Fiat currency to pay with, ISO 4217 code |
| BaseAmount | flags.2?string | Amount to pay in the fiat currency, as a decimal string |
| Memo | flags.3?string | Memo (comment) to attach to the incoming transfer |
| Theme | flags.4?string | Color theme for the provider's page |
| SuccessReturnUrl | flags.5?string | URL to return to after a successful purchase |
| FailReturnUrl | flags.6?string | URL to return to if the purchase fails |
| CryptoAmount | flags.7?string | Amount of cryptocurrency to buy, as a decimal string, instead of base_amount |
Returns
OnrampSessionGogram Example
providers, err := client.PaymentsGetOnrampProviders("TON") if err != nil || len(providers) == 0 { log.Fatal("no on-ramp providers: ", err) } state, _ := client.WalletGetState() wallet := state.(*tg.WalletStateObj) // buy TON straight into your Telegram wallet session, err := client.PaymentsCreateOnrampSession(&tg.PaymentsCreateOnrampSessionParams{ Provider: providers[0].ID, CryptoCurrency: "TON", Address: wallet.Address, BaseCurrency: "USD", BaseAmount: "50", }) if err != nil { log.Fatal(err) } fmt.Println("open to pay:", session.URL)