Class: CoinPayments::Api

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/coin_payments/api.rb

Constant Summary collapse

URL_ENDPOINT =
ENV.fetch("COIN_PAYMENTS_BASE_URL", "https://www.coinpayments.net/api.php")
API_VERSION =
ENV.fetch("COIN_PAYMENTS_API_VERSION", "1")

Instance Method Summary collapse

Instance Method Details

#callback_addresses(options = {}) ⇒ Object

Callback Addresses CoinPayments::Api.new.callback_addresses



100
101
102
103
104
105
106
107
# File 'lib/coin_payments/api.rb', line 100

def callback_addresses(options = {})
  body = {
    cmd: "get_callback_address",
    currency: options.fetch(:currency, "BTC")
  }
  body[:ipn_url] = options[:ipn_url] if options[:ipn_url]
  post body
end

#claim_tagObject

Claim Tag CoinPayments::Api.new.claim_tag



208
209
210
# File 'lib/coin_payments/api.rb', line 208

def claim_tag

end

#conversion_limitsObject

Conversion Limits CoinPayments::Api.new.conversion_limits



164
165
166
# File 'lib/coin_payments/api.rb', line 164

def conversion_limits

end

#convert_coinsObject

Convert Coins CoinPayments::Api.new.convert_coins



158
159
160
# File 'lib/coin_payments/api.rb', line 158

def convert_coins

end

#create_transaction(options = {}) ⇒ Object

Receiving Payments Create Transaction CoinPayments::Api.new.create_transaction amount: 10, currency1: “USD”, currency2: “BTC”, buyer_email: “[email protected]”, buyer_name: “John Doe”



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/coin_payments/api.rb', line 76

def create_transaction(options = {})
  required_params = %i( amount currency1 currency2 buyer_email)
  required_params_present = required_params.all? { |e| options.keys.include?(e) }
  raise "Required Argument Error. Must include #{required_params.join(', ')}" unless required_params_present
  body = {
    cmd: "create_transaction",
    amount: options[:amount],
    currency1: options[:currency1],
    currency2: options[:currency2],
    buyer_email: options[:buyer_email],
  }
  body[:buyer_name] = options[:buyer_name] if options[:buyer_name]
  body[:item_name] = options[:item_name] if options[:item_name]
  body[:item_number] = options[:item_number] if options[:item_number]
  body[:invoice] = options[:invoice] if options[:invoice]
  body[:custom] = options[:custom] if options[:custom]
  body[:address] = options[:address] if options[:address]
  body[:ipn_url] = options[:ipn_url] if options[:ipn_url]
  post body
end

#create_transferObject

Withdrawals/Transfers Create Transfer CoinPayments::Api.new.create_transfer



146
147
148
# File 'lib/coin_payments/api.rb', line 146

def create_transfer

end

#create_withdrawalObject

Create Withdrawal / Mass Withdrawal CoinPayments::Api.new.create_withdrawal



152
153
154
# File 'lib/coin_payments/api.rb', line 152

def create_withdrawal

end

#get_basic_account_infoObject

Get Basic Account Info CoinPayments::Api.new.get_basic_account_info



26
27
28
29
# File 'lib/coin_payments/api.rb', line 26

def 
  body = {cmd: "get_basic_info"}
  post body
end

#get_coin_balances(options = {}) ⇒ Object

Get Coin Balances CoinPayments::Api.new.get_coin_balances CoinPayments::Api.new.get_coin_balances all: true



53
54
55
56
57
58
59
# File 'lib/coin_payments/api.rb', line 53

def get_coin_balances(options = {})
  body = {
    cmd: "balances"
  }
  body[:all] = 1 if options[:all]
  post body
end

#get_conversion_infoObject

Get Conversion Info CoinPayments::Api.new.get_conversion_info



182
183
184
# File 'lib/coin_payments/api.rb', line 182

def get_conversion_info

end

#get_deposit_address(currency = "BTC") ⇒ Object

Get Deposit Address CoinPayments::Api.new.get_deposit_address



63
64
65
66
67
68
69
# File 'lib/coin_payments/api.rb', line 63

def get_deposit_address(currency = "BTC")
  body = {
    cmd: "get_deposit_address",
    currency: currency
  }
  post body
end

#get_exchange_rates(options = {}) ⇒ Object

Get Exchange Rates / Supported Coins CoinPayments::Api.new.get_exchange_rates CoinPayments::Api.new.get_exchange_rates accepted: true CoinPayments::Api.new.get_exchange_rates accepted: true, accepted_only: true



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/coin_payments/api.rb', line 36

def get_exchange_rates(options = {})
  body = {
    cmd: "rates"
  }
  body[:short] = 1 if options[:short]
  body[:accepted] = 1 if options[:accepted]
  response = post body, openstruct: false
  if options[:accepted_only]
    response.to_h.delete_if { |_k, v| v[:accepted] == 0 }
  else
    response.to_h
  end
end

#get_profile_informationObject

PayByName Get Profile Information CoinPayments::Api.new.get_profile_information



190
191
192
# File 'lib/coin_payments/api.rb', line 190

def get_profile_information

end

#get_tag_listObject

Get Tag List CoinPayments::Api.new.get_tag_list



196
197
198
# File 'lib/coin_payments/api.rb', line 196

def get_tag_list

end

#get_tx_info(*transaction_ids) ⇒ Object

Get TX Info CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM” CoinPayments::Api.new.get_tx_info “CPCK5DNHP28DYY3GMWBTWLOIZM”, “CPCK5OLFDULWTYNDW7UQ0LYE2D” # Multiple lookup, don’t recommend as it returns funny & they don’t like more than 25



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/coin_payments/api.rb', line 112

def get_tx_info(*transaction_ids)
  cmd = if transaction_ids.size > 1
    "get_tx_info_multi"
  else
    "get_tx_info"
  end
  body = {
    cmd: cmd,
    txid: transaction_ids.join('|'),
    # full: 0 # I don't see any practical use for this
  }
  post body, openstruct: cmd != "get_tx_info_multi"
end

#get_tx_list(options = {}) ⇒ Object

Get TX List CoinPayments::Api.new.get_tx_list CoinPayments::Api.new.get_tx_list limit: 5 CoinPayments::Api.new.get_tx_list limit: 5, start: 5 CoinPayments::Api.new.get_tx_list newer: (Time.now - 1800).to_i



131
132
133
134
135
136
137
138
139
140
# File 'lib/coin_payments/api.rb', line 131

def get_tx_list(options = {})
  body = {
    cmd: "get_tx_ids"
  }
  body[:limit] = [options[:limit].to_i, 100].min if options[:limit] # limit The maximum number of transaction IDs to return from 1-100. (default: 25)
  body[:start] = options[:start] if options[:start] # start What transaction # to start from (for iteration/pagination.) (default: 0, starts with your newest transactions.)
  body[:newer] = options[:newer] if options[:newer] # newer Return transactions started at the given Unix timestamp or later. (default: 0)
  body[:all] = options[:all] if options[:all] # By default we return an array of TX IDs where you are the seller for use with get_tx_info_multi or get_tx_info. If all is set to 1 returns an array with TX IDs and whether you are the seller or buyer for the transaction.
  post body
end

#get_withdrawal_historyObject

Get Withdrawal History CoinPayments::Api.new.get_withdrawal_history



170
171
172
# File 'lib/coin_payments/api.rb', line 170

def get_withdrawal_history

end

#get_withdrawal_infoObject

Get Withdrawal Info CoinPayments::Api.new.get_withdrawal_info



176
177
178
# File 'lib/coin_payments/api.rb', line 176

def get_withdrawal_info

end

#post(body, openstruct: true) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/coin_payments/api.rb', line 8

def post(body, openstruct: true)
  response = self.class.post(URL_ENDPOINT, body: modify_body(body), timeout: 30, headers: modify_headers(body))
  if response["error"] == "ok"
    if openstruct
      JSON::parse(response["result"].to_json, object_class: OpenStruct)
    else
      response
    end
  else
    OpenStruct.new response
  end
end

#update_tag_profileObject

Update Tag Profile CoinPayments::Api.new.update_tag_profile



202
203
204
# File 'lib/coin_payments/api.rb', line 202

def update_tag_profile

end