Class: Lipisha::Sdk::LipishaAPI
- Inherits:
-
Object
- Object
- Lipisha::Sdk::LipishaAPI
- Defined in:
- lib/lipisha/sdk.rb
Overview
This class defines API bindings for lipisha payments. Each methods responds with an APIResponse object which may be introspected for the status of the call.
Constant Summary collapse
- LIVE_API_BASE_URL =
"https://www.lipisha.com/payments/accounts/index.php/v2/api/"
- SANDBOX_API_BASE_URL =
"http://developer.lipisha.com/index.php/v2/api/"
- DEFAULT_API_VERSION =
"1.3.0"
- DEFAULT_API_TYPE =
"Callback"
Instance Method Summary collapse
-
#acknowledge_transaction(transaction) ⇒ Object
Acknowledge transaction.
-
#authorize_card_transaction(account_number, card_number, address1, address2, expiry, name, country, state, zip, security_code, amount, currency) ⇒ Object
Authorize card transaction.
-
#complete_card_transaction(transaction_index, transaction_reference) ⇒ Object
Complete card transaction.
-
#confirm_transaction(transaction) ⇒ Object
Confirm transaction.
-
#create_payment_account(transaction_account_type, transaction_account_name, transaction_account_manager) ⇒ Object
Create payment account.
-
#create_user(full_name, role, mobile_number, email, user_name, password) ⇒ Object
Create user.
-
#create_withdrawal_account(transaction_account_type, transaction_account_name, transaction_account_number, transaction_account_bank_name, transaction_account_bank_branch, transaction_account_bank_address, transaction_account_swift_code, transaction_account_manager) ⇒ Object
Create withdrawal account.
- #execute(api_endpoint, api_parameters) ⇒ Object
-
#get_balance ⇒ Object
Gets available balance in Lipisha main account.
-
#get_customers(customer_name = "", customer_mobile_number = "", customer_email = "", customer_first_payment_from = "", customer_first_payment_to = "", customer_last_payment_from = "", customer_last_payment_to = "", customer_payments_minimum = "", customer_payments_maximum = "", customer_total_spent_minimum = "", customer_total_spent_maximum = "", customer_average_spent_minimum = "", customer_average_spent_maximum = "", limit = 1000, offset = 0) ⇒ Object
Get customers.
-
#get_float(account_number) ⇒ Object
Gets available balance in float account.
-
#get_transactions(transaction = "", transaction_type = "", transaction_method = "", transaction_date_start = "", transaction_date_end = "", transaction_account_name = "", transaction_account_number = "", transaction_reference = "", transaction_amount_minimum = "", transaction_amount_maximum = "", transaction_status = "", transaction_name = "", transaction_mobile_number = "", transaction_email = "", limit = 100, offset = 0) ⇒ Object
Get transactions.
-
#initialize(api_key, api_signature, environment = "LIVE") ⇒ LipishaAPI
constructor
Initialize Lipisha API connector API credentials can be acquired from your Lipisha account under settings.
-
#request_settlement(account_number, amount) ⇒ Object
Request settlement.
-
#reverse_card_transaction(transaction_index, transaction_reference) ⇒ Object
Reverse card transaction.
-
#reverse_transaction(transaction) ⇒ Object
Reverse transaction.
-
#send_airtime(account_number, mobile_number, amount, network) ⇒ Object
Send airtime.
-
#send_money(account_number, mobile_number, amount) ⇒ Object
Send money.
-
#send_sms(mobile_number, message) ⇒ Object
Send sms.
-
#update_user(full_name, role, mobile_number, email, user_name) ⇒ Object
Update user.
-
#void_card_transaction(transaction_index, transaction_reference) ⇒ Object
Void card transaction.
Constructor Details
#initialize(api_key, api_signature, environment = "LIVE") ⇒ LipishaAPI
Initialize Lipisha API connector API credentials can be acquired from your Lipisha account under settings.
Attributes
-
api_key
- API Key to use to connect to Lipisha -
api_signature
- API Signature to use when connecting -
environment
- either “live” for production environment or “test”for the sandbox
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lipisha/sdk.rb', line 59 def initialize(api_key, api_signature, environment = "LIVE") @api_key = api_key @api_signature = api_signature $environment = environment.upcase # Set API base environment for selected environment case $environment when "LIVE" @api_base = LIVE_API_BASE_URL when "TEST" @api_base = SANDBOX_API_BASE_URL else fail "`environment` must be either LIVE or TEST" end end |
Instance Method Details
#acknowledge_transaction(transaction) ⇒ Object
167 168 169 170 171 |
# File 'lib/lipisha/sdk.rb', line 167 def acknowledge_transaction(transaction) endpoint = "acknowledge_transaction" parameters = { "transaction" => transaction } execute(endpoint, parameters) end |
#authorize_card_transaction(account_number, card_number, address1, address2, expiry, name, country, state, zip, security_code, amount, currency) ⇒ Object
Authorize card transaction
Full docs - authorize_card_transaction
Attributes
-
account_number
-
card_number
-
address1
-
address2
-
expiry
-
name
-
country
-
state
-
zip
-
security_code
-
amount
-
currency
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/lipisha/sdk.rb', line 476 def (account_number, card_number, address1, address2, expiry, name, country, state, zip, security_code, amount, currency) endpoint = "authorize_card_transaction" parameters = { "account_number" => account_number, "card_number" => card_number, "address1" => address1, "address2" => address2, "expiry" => expiry, "name" => name, "country" => country, "state" => state, "zip" => zip, "security_code" => security_code, "amount" => amount, "currency" => currency } execute(endpoint, parameters) end |
#complete_card_transaction(transaction_index, transaction_reference) ⇒ Object
Complete card transaction
Full docs - complete_card_transaction
Attributes
-
transaction_index
-
transaction_reference
533 534 535 536 537 538 |
# File 'lib/lipisha/sdk.rb', line 533 def complete_card_transaction(transaction_index, transaction_reference) endpoint = "complete_card_transaction" parameters = { "transaction_index" => transaction_index, "transaction_reference" => transaction_reference } execute(endpoint, parameters) end |
#confirm_transaction(transaction) ⇒ Object
183 184 185 186 187 |
# File 'lib/lipisha/sdk.rb', line 183 def confirm_transaction(transaction) endpoint = "confirm_transaction" parameters = { "transaction" => transaction } execute(endpoint, parameters) end |
#create_payment_account(transaction_account_type, transaction_account_name, transaction_account_manager) ⇒ Object
Create payment account
Full docs - create_payment_account
Attributes
-
transaction_account_type
-
transaction_account_name
-
transaction_account_manager
289 290 291 292 293 294 295 296 297 |
# File 'lib/lipisha/sdk.rb', line 289 def create_payment_account(transaction_account_type, transaction_account_name, transaction_account_manager) endpoint = "create_payment_account" parameters = { "transaction_account_type" => transaction_account_type, "transaction_account_name" => transaction_account_name, "transaction_account_manager" => transaction_account_manager } execute(endpoint, parameters) end |
#create_user(full_name, role, mobile_number, email, user_name, password) ⇒ Object
Create user
Attributes
-
full_name
-
role
-
mobile_number
-
email
-
user_name
-
password
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/lipisha/sdk.rb', line 242 def create_user(full_name, role, mobile_number, email, user_name, password) endpoint = "create_user" parameters = { "full_name" => full_name, "role" => role, "mobile_number" => mobile_number, "email" => email, "user_name" => user_name, "password" => password } execute(endpoint, parameters) end |
#create_withdrawal_account(transaction_account_type, transaction_account_name, transaction_account_number, transaction_account_bank_name, transaction_account_bank_branch, transaction_account_bank_address, transaction_account_swift_code, transaction_account_manager) ⇒ Object
Create withdrawal account
Full docs - create_withdrawal_account
Attributes
-
transaction_account_type
-
transaction_account_name
-
transaction_account_number
-
transaction_account_bank_name
-
transaction_account_bank_branch
-
transaction_account_bank_address
-
transaction_account_swift_code
-
transaction_account_manager
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/lipisha/sdk.rb', line 316 def create_withdrawal_account(transaction_account_type, transaction_account_name, transaction_account_number, transaction_account_bank_name, transaction_account_bank_branch, transaction_account_bank_address, transaction_account_swift_code, transaction_account_manager) endpoint = "create_withdrawal_account" parameters = { "transaction_account_type" => transaction_account_type, "transaction_account_name" => transaction_account_name, "transaction_account_number" => transaction_account_number, "transaction_account_bank_name" => transaction_account_bank_name, "transaction_account_bank_branch" => transaction_account_bank_branch, "transaction_account_bank_address" => transaction_account_bank_address, "transaction_account_swift_code" => transaction_account_swift_code, "transaction_account_manager" => transaction_account_manager } execute(endpoint, parameters) end |
#execute(api_endpoint, api_parameters) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lipisha/sdk.rb', line 74 def execute(api_endpoint, api_parameters) api_url = @api_base + api_endpoint uri = URI.parse(api_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") request = Net::HTTP::Post.new(uri.request_uri) # Set api key and signature api_parameters["api_key"] = @api_key api_parameters["api_signature"] = @api_signature api_parameters["api_type"] = DEFAULT_API_TYPE api_parameters["api_version"] = DEFAULT_API_VERSION request.set_form_data(api_parameters) response = http.request(request) response_map = JSON.parse(response.body) api_response = APIResponse.new(response_map["status"]["status"], response_map["status"]["status_code"], response_map["status"]["status_description"], response_map["content"], response_map) api_response end |
#get_balance ⇒ Object
Gets available balance in Lipisha main account
101 102 103 104 105 |
# File 'lib/lipisha/sdk.rb', line 101 def get_balance endpoint = "get_balance" parameters = {} execute(endpoint, parameters) end |
#get_customers(customer_name = "", customer_mobile_number = "", customer_email = "", customer_first_payment_from = "", customer_first_payment_to = "", customer_last_payment_from = "", customer_last_payment_to = "", customer_payments_minimum = "", customer_payments_maximum = "", customer_total_spent_minimum = "", customer_total_spent_maximum = "", customer_average_spent_minimum = "", customer_average_spent_maximum = "", limit = 1000, offset = 0) ⇒ Object
Get customers
Attributes
-
customer_name
-
customer_mobile_number
-
customer_email
-
customer_first_payment_from
-
customer_first_payment_to
-
customer_last_payment_from
-
customer_last_payment_to
-
customer_payments_minimum
-
customer_payments_maximum
-
customer_total_spent_minimum
-
customer_total_spent_maximum
-
customer_average_spent_minimum
-
customer_average_spent_maximum
-
limit
-
offset
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/lipisha/sdk.rb', line 421 def get_customers(customer_name = "", customer_mobile_number = "", customer_email = "", customer_first_payment_from = "", customer_first_payment_to = "", customer_last_payment_from = "", customer_last_payment_to = "", customer_payments_minimum = "", customer_payments_maximum = "", customer_total_spent_minimum = "", customer_total_spent_maximum = "", customer_average_spent_minimum = "", customer_average_spent_maximum = "", limit = 1000, offset = 0) endpoint = "get_customers" parameters = { "customer_name" => customer_name, "customer_mobile_number" => customer_mobile_number, "customer_email" => customer_email, "customer_first_payment_from" => customer_first_payment_from, "customer_first_payment_to" => customer_first_payment_to, "customer_last_payment_from" => customer_last_payment_from, "customer_last_payment_to" => customer_last_payment_to, "customer_payments_minimum" => customer_payments_minimum, "customer_payments_maximum" => customer_payments_maximum, "customer_total_spent_minimum" => customer_total_spent_minimum, "customer_total_spent_maximum" => customer_total_spent_maximum, "customer_average_spent_minimum" => customer_average_spent_minimum, "customer_average_spent_maximum" => customer_average_spent_maximum, "limit" => limit, "offset" => offset } execute(endpoint, parameters) end |
#get_float(account_number) ⇒ Object
Gets available balance in float account
Attributes
-
account_number
- float account number to look up
116 117 118 119 120 |
# File 'lib/lipisha/sdk.rb', line 116 def get_float(account_number) endpoint = "get_float" parameters = { "account_number" => account_number } execute(endpoint, parameters) end |
#get_transactions(transaction = "", transaction_type = "", transaction_method = "", transaction_date_start = "", transaction_date_end = "", transaction_account_name = "", transaction_account_number = "", transaction_reference = "", transaction_amount_minimum = "", transaction_amount_maximum = "", transaction_status = "", transaction_name = "", transaction_mobile_number = "", transaction_email = "", limit = 100, offset = 0) ⇒ Object
Get transactions
Attributes
-
transaction
-
transaction_type
-
transaction_method
-
transaction_date_start
-
transaction_date_end
-
transaction_account_name
-
transaction_account_number
-
transaction_reference
-
transaction_amount_minimum
-
transaction_amount_maximum
-
transaction_status
-
transaction_name
-
transaction_mobile_number
-
transaction_email
-
limit
-
offset
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/lipisha/sdk.rb', line 361 def get_transactions(transaction = "", transaction_type = "", transaction_method = "", transaction_date_start = "", transaction_date_end = "", transaction_account_name = "", transaction_account_number = "", transaction_reference = "", transaction_amount_minimum = "", transaction_amount_maximum = "", transaction_status = "", transaction_name = "", transaction_mobile_number = "", transaction_email = "", limit = 100, offset = 0) endpoint = "get_transactions" parameters = { "transaction" => transaction, "transaction_type" => transaction_type, "transaction_method" => transaction_method, "transaction_date_start" => transaction_date_start, "transaction_date_end" => transaction_date_end, "transaction_account_name" => transaction_account_name, "transaction_account_number" => transaction_account_number, "transaction_reference" => transaction_reference, "transaction_amount_minimum" => transaction_amount_minimum, "transaction_amount_maximum" => transaction_amount_maximum, "transaction_status" => transaction_status, "transaction_name" => transaction_name, "transaction_mobile_number" => transaction_mobile_number, "transaction_email" => transaction_email, "limit" => limit, "offset" => offset } execute(endpoint, parameters) end |
#request_settlement(account_number, amount) ⇒ Object
569 570 571 572 573 |
# File 'lib/lipisha/sdk.rb', line 569 def request_settlement(account_number, amount) endpoint = "request_settlement" parameters = { "account_number" => account_number, "amount" => amount } execute(endpoint, parameters) end |
#reverse_card_transaction(transaction_index, transaction_reference) ⇒ Object
Reverse card transaction
Full docs - reverse_card_transaction
Attributes
-
transaction_index
-
transaction_reference
515 516 517 518 519 520 |
# File 'lib/lipisha/sdk.rb', line 515 def reverse_card_transaction(transaction_index, transaction_reference) endpoint = "reverse_card_transaction" parameters = { "transaction_index" => transaction_index, "transaction_reference" => transaction_reference } execute(endpoint, parameters) end |
#reverse_transaction(transaction) ⇒ Object
199 200 201 202 203 |
# File 'lib/lipisha/sdk.rb', line 199 def reverse_transaction(transaction) endpoint = "reverse_transaction" parameters = { "transaction" => transaction } execute(endpoint, parameters) end |
#send_airtime(account_number, mobile_number, amount, network) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/lipisha/sdk.rb', line 218 def send_airtime(account_number, mobile_number, amount, network) endpoint = "send_airtime" parameters = { "account_number" => account_number, "mobile_number" => mobile_number, "amount" => amount, "network" => network } execute(endpoint, parameters) end |
#send_money(account_number, mobile_number, amount) ⇒ Object
134 135 136 137 138 |
# File 'lib/lipisha/sdk.rb', line 134 def send_money(account_number, mobile_number, amount) endpoint = "send_money" parameters = { "account_number" => account_number, "mobile_number" => mobile_number, "amount" => amount } execute(endpoint, parameters) end |
#send_sms(mobile_number, message) ⇒ Object
151 152 153 154 155 |
# File 'lib/lipisha/sdk.rb', line 151 def send_sms(mobile_number, ) endpoint = "send_sms" parameters = { "mobile_number" => mobile_number, "message" => } execute(endpoint, parameters) end |
#update_user(full_name, role, mobile_number, email, user_name) ⇒ Object
267 268 269 270 271 272 273 274 275 |
# File 'lib/lipisha/sdk.rb', line 267 def update_user(full_name, role, mobile_number, email, user_name) endpoint = "update_user" parameters = { "full_name" => full_name, "role" => role, "mobile_number" => mobile_number, "email" => email, "user_name" => user_name } execute(endpoint, parameters) end |
#void_card_transaction(transaction_index, transaction_reference) ⇒ Object
Void card transaction
Full docs - void_card_transaction
Attributes
-
transaction_index
-
transaction_reference
551 552 553 554 555 556 |
# File 'lib/lipisha/sdk.rb', line 551 def void_card_transaction(transaction_index, transaction_reference) endpoint = "void_card_transaction" parameters = { "transaction_index" => transaction_index, "transaction_reference" => transaction_reference } execute(endpoint, parameters) end |