Class: Taproot

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/taproot.rb

Instance Method Summary collapse

Instance Method Details

#_color_status(status) ⇒ Object



225
226
227
228
229
230
231
232
233
# File 'lib/taproot.rb', line 225

def _color_status(status)
  if status >= 400
    yellow status.to_s
  elsif status >= 500
    red status.to_s
  else
    green status.to_s
  end
end

#log(message) ⇒ Object



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

def log(message)
  puts "--- [#{CONFIG_MANAGER.current}] #{message}"
end

#nonce_from_paramsObject



194
195
196
197
198
199
200
# File 'lib/taproot.rb', line 194

def nonce_from_params
  server_config[:nonce_param_names].find do |nonce_param_name|
    if params[nonce_param_name]
      return params[nonce_param_name]
    end
  end
end

#sale(nonce, amount) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/taproot.rb', line 202

def sale(nonce, amount)
  transaction_params = {
    :amount => amount,
    :payment_method_nonce => nonce,
  }

  if CONFIG_MANAGER.
    transaction_params[:merchant_account_id] = CONFIG_MANAGER.
  end

  log("Creating transaction #{transaction_params.inspect}")

  result = Braintree::Transaction.sale(transaction_params)

  if result.success?
    {:message => "created #{result.transaction.id} #{result.transaction.status}"}
  else
    {:message => result.message}
  end
rescue Exception => e
  {:message => e.message}
end

#server_configObject



184
185
186
187
188
# File 'lib/taproot.rb', line 184

def server_config
  {
    :nonce_param_names => ["nonce", "payment_method_nonce", "paymentMethodNonce"]
  }
end