@payus/payus-sdk
Version:
Payment Gateway API to process crypto currency.
156 lines (126 loc) • 3.82 kB
JavaScript
'use strict'
const request = require('request')
class PayusAPI {
constructor (accessToken, apiURL) {
this.accessToken = accessToken
this.apiURL = apiURL || 'https://payus.io:5000'
}
// get_address_balance
getAddressBalance (body) {
return this.apiCall(`POST`, `/api/get_address_balance`, body)
}
// payment_crypto_rest
paymentCryptoRest (body) {
return this.apiCall(`POST`, `/api/payment_crypto_rest`, body)
}
// get merchant account balance
getAccountBalance (body) {
return this.apiCall(`POST`, `/api/get_merchant_account_balance`, body)
}
// get balance
getBalance (body) {
return this.apiCall(`POST`, `/api/get_balance`, body)
}
// get deposite transactions
getDepositTransactions (body) {
return this.apiCall(`POST`, `/api/get_deposit_transactions`, body)
}
// Withdraw
withdraw (body) {
return this.apiCall(`POST`, `/api/withdraw`, body)
}
// Withdraw Transaction
getWithdrawTransaction (body) {
return this.apiCall(`POST`, `/api/get_withdraw_transaction`, body)
}
// generate address
generateAddress (body) {
return this.apiCall(`POST`, `/api/generate_address`, body)
}
// Save address
saveAddress (body) {
return this.apiCall(`POST`, `/api/save_address`, body)
}
// Adress valid check
isValidAddress (body) {
return this.apiCall(`POST`, `/api/is_valid_address`, body)
}
// Green address check
isGreenAddress (body) {
return this.apiCall(`POST`, `/api/is_green_address`, body)
}
// Green transaction
isGreenTransaction (body) {
return this.apiCall(`POST`, `/api/is_green_transaction`, body)
}
// Get address
getMyAddresses (body) {
return this.apiCall(`POST`, `/api/get_my_addresses`, body)
}
// Get coin list
getMycoinlist () {
return this.apiCall(`GET`, `/api/getmycoinlist`, {})
}
// Get Raw transaction
getRawTransaction (body) {
return this.apiCall(`POST`, `/api/get_raw_transaction`, body)
}
// Track payment
trackPayment (body) {
return this.apiCall(`GET`, `/api/track_payment/${body.id}`, body)
}
// Send email
sendEmail (body) {
return this.apiCall(`POST`, `/api/send_email`, body)
}
// Get payment button coin
getPaymentButtonCoin (body) {
return this.apiCall(`GET`, `/api/payment/${body.merchant_id}/${body.button_type}`, body)
}
// Payus model API
payusModelApi (body) {
return this.apiCall(`POST`, `/api/payment/payus_model_api`, body)
}
// get deposit coin address
getDepositCoinAddress (body) {
return this.apiCall(`POST`, `/api/get_deposit_coin_address`, body)
}
// get deposit token
getDepositToken (body) {
return this.apiCall(`POST`, `/api/get_deposit_token`, body)
}
// get withdraw token address
getWithdrawTokenAddress (body) {
return this.apiCall(`POST`, `/api/get_withdraw_token_address`, body)
}
// get withdraw coin
getWithdrawCoin (body) {
return this.apiCall(`POST`, `/api/get_withdraw_coin`, body)
}
error (err) {
return Promise.reject(err)
}
apiCall (method, endpoint, body) {
var options = {
method: method || 'GET',
url: this.apiURL + endpoint,
headers: {
'Content-Type': 'application/json',
'x-auth-token': this.accessToken
},
body: JSON.stringify(body)
}
if (method === 'GET') {
delete options.body
}
return new Promise((resolve, reject) => {
return request(options, function (error, httpResp, respBody) {
if (error) {
return reject(error)
}
return resolve(JSON.parse(respBody))
})
})
}
}
module.exports = PayusAPI