class BitPesa::Api

Public Class Methods

calculate_transaction(data) click to toggle source
# File lib/bitpesa/api.rb, line 59
def calculate_transaction data
  BitPesa::Client.post("/transactions/calculate", transaction: data)
end
create_sender(data) click to toggle source
# File lib/bitpesa/api.rb, line 29
def create_sender data
  BitPesa::Client.post("/senders", {sender: data})
end
create_transaction(data) click to toggle source
# File lib/bitpesa/api.rb, line 51
def create_transaction data
  BitPesa::Client.post("/transactions", transaction: data)
end
create_webhook(url:, events:, **meta_data) click to toggle source
# File lib/bitpesa/api.rb, line 73
def create_webhook url:, events:, **meta_data
  BitPesa::Client.post("/webhooks", {webhook: {url: url, events: events, metadata: meta_data}})
end
delete_sender(id) click to toggle source
# File lib/bitpesa/api.rb, line 41
def delete_sender id
  BitPesa::Client.delete("/senders/#{id}")
end
delete_webhook(id) click to toggle source
# File lib/bitpesa/api.rb, line 81
def delete_webhook id
  BitPesa::Client.delete("/webhooks/#{id}")
end
encode_document(file_content, file_name:, mime_type:, **meta_data) click to toggle source

Helpers

# File lib/bitpesa/api.rb, line 87
def encode_document file_content, file_name:, mime_type:, **meta_data
  encoded_file_content = "data:" + mime_type + ";base64," + Base64.encode64(file_content)
  {
    upload: encoded_file_content,
    upload_file_name: file_name,
    metadata: meta_data
  }
end
get_document(id) click to toggle source

Documents

# File lib/bitpesa/api.rb, line 11
def get_document id
  BitPesa::Client.get("/documents/#{id}")
end
get_sender(id) click to toggle source

Senders

# File lib/bitpesa/api.rb, line 25
def get_sender id
  BitPesa::Client.get("/senders/#{id}")
end
get_transaction(id) click to toggle source

Transactions

# File lib/bitpesa/api.rb, line 47
def get_transaction id
  BitPesa::Client.get("/transactions/#{id}")
end
get_webhook(id) click to toggle source

Webhooks

# File lib/bitpesa/api.rb, line 69
def get_webhook id
  BitPesa::Client.get("/webhooks/#{id}")
end
list_documents(page=1) click to toggle source
# File lib/bitpesa/api.rb, line 19
def list_documents page=1
  BitPesa::Client.get("/documents", page: page)
end
list_senders(page=1) click to toggle source
# File lib/bitpesa/api.rb, line 37
def list_senders page=1
  BitPesa::Client.get("/senders", page: page)
end
list_transactions(**filters) click to toggle source
# File lib/bitpesa/api.rb, line 55
def list_transactions **filters
  BitPesa::Client.get("/transactions", filters)
end
list_webhooks() click to toggle source
# File lib/bitpesa/api.rb, line 77
def list_webhooks
  BitPesa::Client.get("/webhooks")
end
update_sender(id, data) click to toggle source
# File lib/bitpesa/api.rb, line 33
def update_sender id, data
  BitPesa::Client.patch("/senders", data)
end
upload_document(file_content, **options) click to toggle source
# File lib/bitpesa/api.rb, line 15
def upload_document file_content, **options
  BitPesa::Client.post("/documents", {document: encode_document(file_content, options)})
end
validate_transaction(data) click to toggle source
# File lib/bitpesa/api.rb, line 63
def validate_transaction data
  BitPesa::Client.post("/transactions/validate", transaction: data)
end