Sha256: 01d0243d47bd18aa2d2418847e5f34ffb562779c70324cfcce1a7d4216d7ba7d

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require_relative 'base/base'
require 'json'

# Handles all transactions via Onchain
class Onchain < Base
  # Onchain sending of bitcoin
  #
  # - Required Function Parameters:
  #
  #
  #       data: {
  #    satoshis: number,
  #    customerEmail: string,
  #    address: string,
  #    priorityLevel: string
  #     }
  #
  #
  # - Priority level is used to detect how long a transaction would take. Its default is regular
  def send_bitcoin(data)
    required_parameters = %w[satoshis customerEmail address]

    checked_passed_parameters(required_parameters, data)
    payload = data.to_json
    post_request("#{base_url}#{BaseEndpoints::ONCHAIN}/send_bitcoin", payload)
  end

  # Generates a temporary address for onchain transaction
  #
  # - Required Function Parameters: <tt>customer_email</tt>
  def generate_address(customer_email)
    body = { customerEmail: customer_email }
    payload = body.to_json
    post_request("#{base_url}#{BaseEndpoints::ADDRESS}/generate", payload)
  end

  # Returns a JSON data containing list of addresses
  #
  # - Required Function Parameters: <tt>page_number</tt> <tt>limit</tt>
  #
  #
  #     default: <tt>page_number => 1, limit => 10</tt>
  def list_addresses(page_number: 1, limit: 10)
    get_request("#{base_url}#{BaseEndpoints::ADDRESS}order=ASC&page=#{page_number}&take=#{limit}")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitnob-0.0.3 lib/bitnob/objects/onchain.rb