Class: Lipisha::Sdk::LipishaAPI

Inherits:
Object
  • Object
show all
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

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

Acknowledge transaction

Full docs - acknowledge_transaction

Attributes

  • transaction



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 authorize_card_transaction(,
                               card_number,
                               address1,
                               address2,
                               expiry,
                               name,
                               country,
                               state,
                               zip,
                               security_code,
                               amount,
                               currency)
  endpoint = "authorize_card_transaction"
  parameters = { "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

Confirm transaction

Full docs - confirm_transaction

Attributes

  • transaction



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 (,
                           ,
                           )
  endpoint = "create_payment_account"
  parameters = { "transaction_account_type" => ,
                 "transaction_account_name" => ,
                 "transaction_account_manager" =>  }
  execute(endpoint, parameters)
end

#create_user(full_name, role, mobile_number, email, user_name, password) ⇒ Object

Create user

Full docs - 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 (,
                              ,
                              ,
                              ,
                              ,
                              ,
                              ,
                              )
  endpoint = "create_withdrawal_account"
  parameters = { "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" =>  }
  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_balanceObject

Gets available balance in Lipisha main account

Full docs - get_balance



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

Full docs - 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

Full docs - get_float

Attributes

  • account_number - float account number to look up



116
117
118
119
120
# File 'lib/lipisha/sdk.rb', line 116

def get_float()
  endpoint = "get_float"
  parameters = { "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

Full docs - 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_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_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

Request settlement

Full docs - request_settlement

Attributes

  • account_number

  • amount



569
570
571
572
573
# File 'lib/lipisha/sdk.rb', line 569

def request_settlement(, amount)
  endpoint = "request_settlement"
  parameters = { "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

Reverse transaction

Full docs - reverse_transaction

Attributes

  • transaction



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

Send airtime

Full docs - send_airtime

Attributes

  • account_number

  • mobile_number

  • amount

  • network



218
219
220
221
222
223
224
225
# File 'lib/lipisha/sdk.rb', line 218

def send_airtime(, mobile_number, amount, network)
  endpoint = "send_airtime"
  parameters = { "account_number" => ,
                 "mobile_number" => mobile_number,
                 "amount" => amount,
                 "network" => network }
  execute(endpoint, parameters)
end

#send_money(account_number, mobile_number, amount) ⇒ Object

Send money

Full docs - send_money

Attributes

  • account_number

  • mobile_number

  • amount



134
135
136
137
138
# File 'lib/lipisha/sdk.rb', line 134

def send_money(, mobile_number, amount)
  endpoint = "send_money"
  parameters = { "account_number" => , "mobile_number" => mobile_number, "amount" => amount }
  execute(endpoint, parameters)
end

#send_sms(mobile_number, message) ⇒ Object

Send sms

Full docs - send_sms

Attributes

  • mobile_number

  • message



151
152
153
154
155
# File 'lib/lipisha/sdk.rb', line 151

def send_sms(mobile_number, message)
  endpoint = "send_sms"
  parameters = { "mobile_number" => mobile_number, "message" => message }
  execute(endpoint, parameters)
end

#update_user(full_name, role, mobile_number, email, user_name) ⇒ Object

Update user

Full docs - update_user

Attributes

  • full_name

  • role

  • mobile_number

  • email

  • user_name



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