Buying crypto
The SDK allows you to buy cryptocurrency with a bank card using a CrypteriumPayin
class.
In this class, we have implemented several methods for conducting purchase operations:
-
The
pairs
method is responsible for the list of available cryptocurrencies. -
Once a cryptocurrency has been selected, you can use the
averageRate
method to get its approximate exchange rate of conversion against the euro. -
When buying crypto, a fee is possible. Get an estimated fee using the
averageFee
method. -
The app may have purchase limits. The methods
averageLimits
andlimits
return the allowed minimum and maximum of the euros you can spend for a purchase. The limits are determined by the KYC level and the type of a bank card. -
Check the possibility of making a purchase using the
check
method. -
If a purchase with the given parameters is possible, run the
execute
method to confirm the transaction.
See more details in the description of each method.
CrypteriumPayin class
The CrypteriumPayin
class has been implemented for purchasing crypto with a bank card. To manage the process, initialize a CrypteriumPayin
object:
let payin: CrypteriumPayin = CrypteriumAPI.cardPayin()
payin: ICrypteriumPayIn = CrypteriumAPI.cardsPayin()
Methods
pairs
Use the pairs
method to get the array of cryptocurrencies available for purchasing. The method calls a completion closure and puts an object of the CRPTLoadPairsResult
type as an argument of the closure.
payin.pairs(completion: (CRPTLoadPairsResult) -> Void)
enum CRPTLoadPairsResult {
case success([CRPTCurrency])
case failure(CRPTError)
}
payin.loadPairs(completion: (CRPTLoadPairsResult) -> Unit)
sealed class CRPTLoadPairsResult {
data class success(val pairs: List<CRPTCurrency?>) : CRPTLoadPairsResult()
data class failure(val error: CRPTError) : CRPTLoadPairsResult()
}
CRPTLoadPairsResult
The CRPTLoadPairsResult
object value is attached to a success or a failure case:
case | variable | variable type | description |
---|---|---|---|
success | pairs | [CRPTCurrency] | array of cryptocurrencies available for purchasing |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have the value below:
value | description |
AUTHORIZATION | authorization error |
averageRate
The averageRate
method gives the approximate rate for the selected cryptocurrency against the euro. The method calls a completion closure and puts an object of the CRPTRateResult
type as an argument of the closure.
payin.averageRate(for currency: CRPTCurrency, completion: (CRPTRateResult) -> Void)
enum CRPTRateResult {
case success(Decimal)
case failure(CRPTError)
}
payin.averageRate(currency: CRPTCurrency, completion: (CRPTRateResult) -> Unit)
sealed class CRPTRateResult {
data class success(val rate: BigDecimal) : CRPTRateResult()
data class failure(val error: CRPTError) : CRPTRateResult()
}
Income parameters
parameter name | parameter type | description |
currency | CRPTCurrency | cryptocurrency to buy |
CRPTRateResult
The CRPTRateResult
object value is attached to a success or a failure case:
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend error |
averageFee
The averageFee
method is designed to get the approximate fee when purchasing crypto with a card. The fee is a decimal fraction of the amount of crypto to buy. To get the total amount for spending use this formula:
total amount = amount + amount * averageFee.
Fee example
amount = 100 euros
averageFee = 0.02
totalAmount = 100 + 100 * 0.02 = 102 euros
The method calls a completion closure and puts an object of the CRPTFeeResult
type as an argument of the closure.
payin.averageFee(for amount: Decimal, completion: (CRPTFeeResult) -> Void)
enum CRPTFeeResult {
case success(Decimal)
case failure(CRPTError)
}
payin.averageFee(amount: BigDecimal, completion: (CRPTFeeResult) -> Unit)
sealed class CRPTFeeResult {
data class success(val rate: BigDecimal) : CRPTFeeResult()
data class failure(val error: CRPTError) : CRPTFeeResult()
}
Income parameters
parameter name | parameter type | description |
amount | Decimal | amount of euros to spend |
CRPTFeeResult
The CRPTFeeResult
object value is attached to a success or a failure case:
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
BACKEND | backend error |
averageLimits
The averageLimits
method allows you to get the approximate maximum and minimum amount of the euros a user can spend for purchasing crypto. The limits depend on the type of a user's bank card (country of residence and other conditions). Use this method to get the approximate limits when a bank card is not yet defined. The method calls a completion closure and puts an object of the CRPTLimitsResult
type as an argument of the closure.
payin.averageLimits(completion: (CRPTLimitsResult) -> Void)
enum CRPTLimitsResult {
case success(CRPTLimits)
case failure(CRPTError)
}
payin.averageLimits(completion: (CRPTLimitsResult) -> Unit)
sealed class CRPTLimitsResult {
data class success(val limits: CRPTLimits) : CRPTLimitsResult()
data class failure(val error: CRPTError) : CRPTLimitsResult()
}
CRPTLimitsResult
The CRPTLimitsResult
object value is attached to a success or a failure case:
case | variable | variable type | description |
success | limits | CRPTLimits | minimum and maximum amount of euro to spend |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend error |
limits
The limits
method allows you to get the exact maximum and minimum amount of euro a user can spend for purchasing crypto. The limits depend on the type of a user's bank card (country of residence and other conditions). Use this method to get the limits when the bank card is already defined. The method calls a completion closure and puts an object of CRPTLimitsResult
type as an argument of the closure.
payin.limits(for card: CRPTCardModel, completion: (CRPTLimitsResult) -> Void)
enum CRPTLimitsResult {
case success(CRPTLimits)
case failure(CRPTError)
}
payin.limits(card: CRPTCardModel, completion: (CRPTLimitsResult) -> Unit)
sealed class CRPTLimitsResult {
data class success(val limits: CRPTLimits) : CRPTLimitsResult()
data class failure(val error: CRPTError) : CRPTLimitsResult()
}
Income parameters
parameter name | parameter type | description |
card | CRPTCardModel | bank card |
CRPTLimitsResult
The CRPTLimitsResult
object value is attached to success or failure case:
case | variable | variable type | description |
success | limits | CRPTLimits | minimum and maximum amount |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend error |
check
Use the check
method to check if a user can buy a specific cryptocurrency for the certain amount of euros with the defined card. The method calls a completion closure and puts an object of CRPTPayinCheckResult
type as an argument of the closure.
payin.check(euroAmount: Decimal, currency: CRPTCurrency, card: CRPTCardModel, completion: (CRPTPayinCheckResult) -> Void)
enum CRPTPayinCheckResult {
case success()
case failure(CRPTError)
}
payin.check(euroAmount: BigDecimal, currency: CRPTCurrency, card: CRPTCardModel, completion: (CRPTPayinCheckResult) -> Unit)
sealed class CRPTPayinCheckResult {
object success : CRPTPayinCheckResult()
data class failure(val error: CRPTError) : CRPTPayinCheckResult()
}
Income parameters
parameter name | parameter type | description |
---|---|---|
euroAmount | Decimal | amount of euros to spend |
currency | CRPTCurrency | cryptocurrency to buy |
card | CRPTCardModel | bank card |
CRPTPayinCheckResult
The CRPTPayinCheckResult
object value is attached to success or failure case:
case | variable | variable type | description |
---|---|---|---|
success | - | - | transaction has passed all checks and is ready for execution |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend error |
MAINTENANCE | maintenance error |
UPDATE | update error |
LIMITS | exceeding transaction or card limits |
KYC0 | exceeding monthly limits, KYC0 verification required |
KYC1 | exceeding monthly limits, KYC1 verification required |
KYC2 | exceeding monthly limits, KYC2 verification required |
execute
The execute
method commits the crypto purchase transaction. The method gets a WebView handler as a closure. This closure returns WebView where a user enters the 3D secure code of his bank card. The method commits the transaction and calls a completion closure. The argument of the closure is an object of the CRPTPayinExecuteResult
type.
Before calling the
execute
method, check the possibility of purchasing using the check method.
payin.execute(euroAmount: Decimal, currency: CRPTCurrency, card: CRPTCardModel, cvv: String, webViewHandler: (WebView) -> Void, completion: (CRPTPayinExecuteResult) -> Void)
enum CRPTPayinExecuteResult {
case success(CRPTTransactionStatus)
case failure(CRPTError)
}
payin.execute(euroAmount: BigDecimal, currency: CRPTCurrency, card: CRPTCardModel, cvv: String, context: Context, webViewHandler: (WebView) -> Unit, completion: (CRPTPayinExecuteResult) -> Unit)
sealed class CRPTPayinExecuteResult {
data class success(val status: CRPTTransactionStatus) : CRPTPayinExecuteResult()
data class failure(val error: CRPTError) : CRPTPayinExecuteResult()
}
Income parameters
parameter name | parameter type | description |
euroAmount | Decimal | amount of euros to spend |
currency | CRPTCurrency | cryptocurrency to buy |
card | CRPTCardModel | bank card |
cvv | String | bank card cvv |
webViewHandler | WebView | WebView handler for 3D secure code |
context (Android only) | Context | current screen context |
CRPTPayinExecuteResult
The CRPTPayinExecuteResult
object value is attached to a success or a failure case:
case | variable | variable type | description |
success | status | CRPTTransactionStatus | transaction status |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization failed |
VALIDATION | the coin is not in the list of available pairs |
BACKEND | backend error |
MAINTENANCE | maintenance error |
UPDATE | update error |
LIMITS | exceeding transaction or card limits |
KYC0 | exceeding monthly limits, KYC0 verification required |
KYC1 | exceeding monthly limits, KYC1 verification required |
KYC2 | exceeding monthly limits, KYC2 verification required |
Updated over 2 years ago