bitpesa-sdk

Bitpesa - the Ruby gem for the BitPesa API

Reference documentation for the BitPesa API V1

This SDK is automatically generated by the OpenAPI Generator project:

  • API version: 1.0
  • Package version: 0.2.0
  • Build package: org.openapitools.codegen.languages.RubyClientCodegen

For more information, please visit:

Installation

Build a gem

To build the Ruby code into a gem:

gem build bitpesa-sdk.gemspec

Then either install the gem locally:

gem install ./bitpesa-sdk-0.2.0.gem

(for development, run gem install --dev ./bitpesa-sdk-0.2.0.gem to install the development dependencies)

or publish the gem to a gem hosting service, e.g. RubyGems.

Finally add this to the Gemfile:

gem 'bitpesa-sdk', '~> 0.2.0'

Install from Git

If the Ruby gem is hosted at a git repository: https://github.com/bitpesa/bitpesa-ruby-sdk, then add the following in the Gemfile:

gem 'bitpesa-sdk', :git => 'https://github.com/bitpesa/bitpesa-ruby-sdk.git'

Include the Ruby code directly

Include the Ruby code directly using -I as follows:

ruby -Ilib script.rb

Getting Started

Please follow the installation procedure and then run the following code:

Webhooks

To parse webhooks you can use the following snippet:

webhook_content = "{ (...) }"

webhook_api = Bitpesa::ApiClient.new
webhook = webhook_api.parse_response(webhook_content, "Webhook")

if webhook['event'].start_with?('transaction')
  transaction_webhook = webhook_api.parse_response(webhook_content, 'TransactionWebhook')
  puts transaction_webhook.object.to_s
elsif webhook['event'].start_with?('recipient')
  recipient_webhook = webhook_api.parse_response(webhook_content, 'RecipientWebhook')
  puts recipient_webhook.object.to_s
elsif webhook['event'].start_with?('payout_method')
  payout_method_webhook = webhook_api.parse_response(webhook_content, 'PayoutMethodWebhook')
  puts payout_method_webhook.object.to_s
elsif webhook['event'].start_with?('sender')
  sender_webhook = webhook_api.parse_response(webhook_content, 'SenderWebhook')
  puts sender_webhook.object.to_s
elsif webhook['event'].start_with?('document')
  document_webhook = webhook_api.parse_response(webhook_content, 'DocumentWebhook')
  puts document_webhook.object.to_s
else
  puts webhook
end

Documentation for API Endpoints

All URIs are relative to https://api-sandbox.bitpesa.co/v1

Class Method HTTP request Description
Bitpesa::APILogsApi get_api_log GET /api_logs/Log ID Fetch an individual API log
Bitpesa::APILogsApi get_api_logs GET /api_logs Fetch a list of API logs
Bitpesa::AccountDebitsApi get_accounts_debit GET /accounts/debits/Debit ID Fetching an account debit
Bitpesa::AccountDebitsApi get_accounts_debits GET /accounts/debits Listing Accounts debits
Bitpesa::AccountDebitsApi post_accounts_debits POST /accounts/debits Creating an account debit
Bitpesa::AccountValidationApi post_account_validations POST /account_validations Validates the existence of a bank account
Bitpesa::AccountsApi get_account GET /accounts/Currency Fetches account balance for specified currrency
Bitpesa::AccountsApi get_accounts GET /accounts Fetches account balances for all currencies
Bitpesa::CurrencyInfoApi info_currencies GET /info/currencies Getting a list of possible requested currencies
Bitpesa::CurrencyInfoApi info_currencies_in GET /info/currencies/in Getting a list of possible input currencies
Bitpesa::CurrencyInfoApi info_currencies_out GET /info/currencies/out Getting a list of possible output currencies
Bitpesa::DocumentsApi get_document GET /documents/ID Fetching a document
Bitpesa::DocumentsApi get_documents GET /documents Getting a list of documents
Bitpesa::DocumentsApi post_documents POST /documents Creating a document
Bitpesa::LogsApi get_webhook_log GET /logs/Log ID Fetch an individual webhook log
Bitpesa::LogsApi get_webhook_logs GET /logs/webhooks Fetch a list of webhook logs
Bitpesa::PaymentMethodsApi payment_methods_in GET /info/payment_methods/in This method returns possible payin methods.
Bitpesa::PaymentMethodsApi payment_methods_out GET /info/payment_methods/out This method returns possible payout methods.
Bitpesa::PayoutMethodsApi delete_payout_method DELETE /payout_methods/Method ID Deleting a payout method
Bitpesa::PayoutMethodsApi get_payout_method GET /payout_methods/Method ID Fetching a payout method
Bitpesa::PayoutMethodsApi get_payout_methods GET /payout_methods Listing payout methods
Bitpesa::PayoutMethodsApi patch_payout_method PATCH /payout_methods/Method ID Updating a payout method
Bitpesa::PayoutMethodsApi post_payout_methods POST /payout_methods Creating a payout method
Bitpesa::RecipientsApi delete_recipient DELETE /recipients/ID Cancelling a recipient
Bitpesa::RecipientsApi get_recipients GET /recipients Getting a list of recipients with filtering
Bitpesa::RecipientsApi patch_recipient PATCH /recipients/ID Updating a recipient
Bitpesa::SendersApi delete_sender DELETE /senders/ID Deleting a sender
Bitpesa::SendersApi get_sender GET /senders/ID Fetching a sender
Bitpesa::SendersApi get_senders GET /senders Listing senders
Bitpesa::SendersApi patch_sender PATCH /senders/ID Updating a sender
Bitpesa::SendersApi post_senders POST /senders Creating a sender
Bitpesa::TransactionsApi calculate_transactions POST /transactions/calculate Calculates transaction amounts for a transaction payload
Bitpesa::TransactionsApi get_transaction GET /transactions/ID Fetch a single transaction
Bitpesa::TransactionsApi get_transactions GET /transactions Get a list of transactions
Bitpesa::TransactionsApi payin_transaction POST /transactions/ID/payin Creates a fake payin for transaction
Bitpesa::TransactionsApi payout_transaction POST /transactions/ID/payout Creates a fake payout for transaction
Bitpesa::TransactionsApi post_transactions POST /transactions Creates a new transaction
Bitpesa::TransactionsApi validate_transactions POST /transactions/validate Validates a transaction payload
Bitpesa::WebhooksApi delete_webhook DELETE /webhooks/ID Unsubscribing from a webhook
Bitpesa::WebhooksApi get_webhook GET /webhooks/ID Find a webhook's details
Bitpesa::WebhooksApi get_webhook_events GET /webhooks/events Find possible webhook events
Bitpesa::WebhooksApi get_webhooks GET /webhooks Listing webhooks
Bitpesa::WebhooksApi post_webhooks POST /webhooks Creating a webhook

Documentation for Models

Documentation for Authorization

You can set the API Key and Secret on the ApiClient object for authentication:

# Load the gem
require 'bitpesa'

# Setup authorization

Bitpesa.configure do |config|
  config.api_key = 'YOUR API KEY'
  config.api_secret = 'YOUR API SECRET'
  config.host = "https://api-sandbox.bitpesa.co/v1"
end

begin
  request = Bitpesa::AccountValidationRequest.new # account validation api
  request. = '9040004458219'
  request.bank_code = '020100'
  request.country = 'GH'
  request.currency = 'GHS'
  request.method = 'bank'

  avi = Bitpesa::AccountValidationApi.new
   = avi.(request)
   = .object.
  puts "Account Name: #{}"
rescue Bitpesa::ApiError => e
  if e.validation_error
    puts e.response_object("AccountValidationResponse").meta.error
  else
    puts "Exception when calling AccountValidationApi#account_validation_example: #{e}"
  end
end