lipisha-sdk 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aab98f319bcd1f8ef02dfc46c4d3c53cd24d59c6
4
+ data.tar.gz: a406112493f898023f7eb70af0029243bdcac764
5
+ SHA512:
6
+ metadata.gz: 2a20b45c472e83974b0e5f0527c1f7cb25c90f565ff8a0db81fe8f16585a7cd114429e3ee9952e24e1b89cb15a0bd149bff12eeb44e7497d507e48301a64d558
7
+ data.tar.gz: 13ccb5382cee8ecf3032e37651c19052b7e07c76e1b16e4478cbba524a040bd9c00c4f69808b2f1ae27bb543589bb328310958b01123eca92da58ee50fd372c1
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lipisha-sdk.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lipisha-sdk (1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ power_assert (0.2.6)
10
+ rake (10.4.2)
11
+ test-unit (3.1.5)
12
+ power_assert
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.3)
19
+ lipisha-sdk!
20
+ rake
21
+ test-unit
22
+
23
+ BUNDLED WITH
24
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Lipisha Consortium Limited
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ # Lipisha::Sdk
2
+
3
+ This gem provides bindings for Lipisha Payments API (http://developers.lipisha.com)
4
+
5
+ ## Features
6
+
7
+ - Send money
8
+ - Acknowledge transactions
9
+ - Send SMS
10
+ - Get Float
11
+ - Get Balance
12
+ - Charge card transactions
13
+ - Search transactions
14
+ - Search customers
15
+ - Add users
16
+ - Add payment accounts and withdrawal accounts
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'lipisha-sdk'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install lipisha-sdk
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ require "lipisha/sdk"
36
+
37
+ lipisha = Lipisha::Sdk::LipishaAPI.new("<YOUR API kEY>", "YOUR API SIGNATURE", "<ENVIRONMENT>")
38
+ # Enviroment may either be _live_ for production environment or _test_ for the lipisha sandbox.
39
+
40
+ response = lipisha.get_balance()
41
+ puts(response.status)
42
+ puts(response.status_code)
43
+ # This is a map of the content response
44
+ # See the Lipisha API documentation for available metadata
45
+ puts(response.content)
46
+ puts(response.json)
47
+
48
+ # Sending money
49
+ response = lipisha.send_money("039XXX", "0722123456", 200)
50
+ ```
51
+
52
+ ## IPN Examples
53
+
54
+ IPN Integration examples for Rails are in the examples directory
55
+
56
+ https://github.com/lipisha/lipisha-ruby-sdk/tree/master/examples
57
+
58
+ ## Running Tests
59
+
60
+ Edit the test configuration in `test/config.rb`
61
+
62
+ Run all tests
63
+
64
+ ```shell
65
+ bundle exec rake
66
+ ```
67
+
68
+ Run a particular test
69
+
70
+ ```
71
+ bundle exec rake TEST=test/<filename>
72
+ ```
73
+
74
+ e.g. Balance tests
75
+
76
+ ```
77
+ bundle exec rake TEST=test/test_balance
78
+ ```
79
+
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ # IPN Integration examples
2
+
3
+
4
+ This is an examples of Lipisha IPN integration for rails.
5
+
6
+ This assumes that you have configured an IPN URL for API callbacks.
7
+
8
+ IPN: Instant Payment Notification
@@ -0,0 +1,576 @@
1
+ require "lipisha/sdk/version"
2
+ require "net/http"
3
+ require "uri"
4
+ require "json"
5
+
6
+ module Lipisha
7
+ module Sdk
8
+ class APIResponse
9
+ attr_reader :status
10
+ attr_reader :status_code
11
+ attr_reader :status_description
12
+ attr_reader :content
13
+ attr_reader :json
14
+
15
+ ##
16
+ # Initializes lipisha API respnse
17
+ #
18
+ # === Attributes
19
+ #
20
+ # * +status+ - status of the api call e.g. Success
21
+ # * +status_code+ - numeric status code of the api call
22
+ # * +status_description+ - Verbose status code description
23
+ # * +content+ - content section of api call response
24
+ # * +json+ - Raw JSON response (Hashmap)
25
+ def initialize(status, status_code, status_description, content, json)
26
+ @status = status
27
+ @status_code = status_code
28
+ @status_description = status_description
29
+ @content = content
30
+ @json = json
31
+ end
32
+
33
+ def to_s
34
+ @json.to_s
35
+ end
36
+ end
37
+ ##
38
+ # This class defines API bindings for lipisha payments.
39
+ # Each methods responds with an APIResponse object which
40
+ # may be introspected for the status of the call.
41
+
42
+ class LipishaAPI
43
+ LIVE_API_BASE_URL = "https://www.lipisha.com/payments/accounts/index.php/v2/api/"
44
+ SANDBOX_API_BASE_URL = "http://developer.lipisha.com/index.php/v2/api/"
45
+ DEFAULT_API_VERSION = "1.3.0"
46
+ DEFAULT_API_TYPE = "Callback"
47
+
48
+ ##
49
+ # Initialize Lipisha API connector
50
+ # API credentials can be acquired from your Lipisha account under settings.
51
+ #
52
+ # === Attributes
53
+ #
54
+ # * +api_key+ - API Key to use to connect to Lipisha
55
+ # * +api_signature+ - API Signature to use when connecting
56
+ # * +environment+ - either "live" for production environment or "test"
57
+ # for the sandbox
58
+ #
59
+ def initialize(api_key, api_signature, environment = "LIVE")
60
+ @api_key = api_key
61
+ @api_signature = api_signature
62
+ $environment = environment.upcase
63
+ # Set API base environment for selected environment
64
+ case $environment
65
+ when "LIVE"
66
+ @api_base = LIVE_API_BASE_URL
67
+ when "TEST"
68
+ @api_base = SANDBOX_API_BASE_URL
69
+ else
70
+ fail "`environment` must be either LIVE or TEST"
71
+ end
72
+ end
73
+
74
+ def execute(api_endpoint, api_parameters)
75
+ api_url = @api_base + api_endpoint
76
+ uri = URI.parse(api_url)
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.use_ssl = (uri.scheme == "https")
79
+ request = Net::HTTP::Post.new(uri.request_uri)
80
+ # Set api key and signature
81
+ api_parameters["api_key"] = @api_key
82
+ api_parameters["api_signature"] = @api_signature
83
+ api_parameters["api_type"] = DEFAULT_API_TYPE
84
+ api_parameters["api_version"] = DEFAULT_API_VERSION
85
+ request.set_form_data(api_parameters)
86
+ response = http.request(request)
87
+ response_map = JSON.parse(response.body)
88
+ api_response = APIResponse.new(response_map["status"]["status"],
89
+ response_map["status"]["status_code"],
90
+ response_map["status"]["status_description"],
91
+ response_map["content"],
92
+ response_map)
93
+ api_response
94
+ end
95
+
96
+ ##
97
+ # Gets available balance in Lipisha main account
98
+ #
99
+ # {Full docs - get_balance}[http://developer.lipisha.com/index.php/app/launch/api_get_balance]
100
+ #
101
+ def get_balance
102
+ endpoint = "get_balance"
103
+ parameters = {}
104
+ execute(endpoint, parameters)
105
+ end
106
+
107
+ ##
108
+ # Gets available balance in float account
109
+ #
110
+ # {Full docs - get_float}[http://developer.lipisha.com/index.php/app/launch/api_get_float]
111
+ #
112
+ # ==== Attributes
113
+ #
114
+ # * +account_number+ - float account number to look up
115
+ #
116
+ def get_float(account_number)
117
+ endpoint = "get_float"
118
+ parameters = { "account_number" => account_number }
119
+ execute(endpoint, parameters)
120
+ end
121
+
122
+ ##
123
+ # Send money
124
+ #
125
+ # {Full docs - send_money}[http://developer.lipisha.com/index.php/app/launch/api_send_money]
126
+ #
127
+ # ==== Attributes
128
+ #
129
+ # * +account_number+
130
+ # * +mobile_number+
131
+ # * +amount+
132
+ #
133
+ #
134
+ def send_money(account_number, mobile_number, amount)
135
+ endpoint = "send_money"
136
+ parameters = { "account_number" => account_number, "mobile_number" => mobile_number, "amount" => amount }
137
+ execute(endpoint, parameters)
138
+ end
139
+
140
+ ##
141
+ # Send sms
142
+ #
143
+ # {Full docs - send_sms}[http://developer.lipisha.com/index.php/app/launch/api_send_sms]
144
+ #
145
+ # ==== Attributes
146
+ #
147
+ # * +mobile_number+
148
+ # * +message+
149
+ #
150
+ #
151
+ def send_sms(mobile_number, message)
152
+ endpoint = "send_sms"
153
+ parameters = { "mobile_number" => mobile_number, "message" => message }
154
+ execute(endpoint, parameters)
155
+ end
156
+
157
+ ##
158
+ # Acknowledge transaction
159
+ #
160
+ # {Full docs - acknowledge_transaction}[http://developer.lipisha.com/index.php/app/launch/api_acknowledge_transaction]
161
+ #
162
+ # ==== Attributes
163
+ #
164
+ # * +transaction+
165
+ #
166
+ #
167
+ def acknowledge_transaction(transaction)
168
+ endpoint = "acknowledge_transaction"
169
+ parameters = { "transaction" => transaction }
170
+ execute(endpoint, parameters)
171
+ end
172
+
173
+ ##
174
+ # Confirm transaction
175
+ #
176
+ # {Full docs - confirm_transaction}[http://developer.lipisha.com/index.php/app/launch/api_confirm_transaction]
177
+ #
178
+ # ==== Attributes
179
+ #
180
+ # * +transaction+
181
+ #
182
+ #
183
+ def confirm_transaction(transaction)
184
+ endpoint = "confirm_transaction"
185
+ parameters = { "transaction" => transaction }
186
+ execute(endpoint, parameters)
187
+ end
188
+
189
+ ##
190
+ # Reverse transaction
191
+ #
192
+ # {Full docs - reverse_transaction}[http://developer.lipisha.com/index.php/app/launch/api_reverse_transaction]
193
+ #
194
+ # ==== Attributes
195
+ #
196
+ # * +transaction+
197
+ #
198
+ #
199
+ def reverse_transaction(transaction)
200
+ endpoint = "reverse_transaction"
201
+ parameters = { "transaction" => transaction }
202
+ execute(endpoint, parameters)
203
+ end
204
+
205
+ ##
206
+ # Send airtime
207
+ #
208
+ # {Full docs - send_airtime}[http://developer.lipisha.com/index.php/app/launch/api_send_airtime]
209
+ #
210
+ # ==== Attributes
211
+ #
212
+ # * +account_number+
213
+ # * +mobile_number+
214
+ # * +amount+
215
+ # * +network+
216
+ #
217
+ #
218
+ def send_airtime(account_number, mobile_number, amount, network)
219
+ endpoint = "send_airtime"
220
+ parameters = { "account_number" => account_number,
221
+ "mobile_number" => mobile_number,
222
+ "amount" => amount,
223
+ "network" => network }
224
+ execute(endpoint, parameters)
225
+ end
226
+
227
+ ##
228
+ # Create user
229
+ #
230
+ # {Full docs - create_user}[http://developer.lipisha.com/index.php/app/launch/api_create_user]
231
+ #
232
+ # ==== Attributes
233
+ #
234
+ # * +full_name+
235
+ # * +role+
236
+ # * +mobile_number+
237
+ # * +email+
238
+ # * +user_name+
239
+ # * +password+
240
+ #
241
+ #
242
+ def create_user(full_name, role, mobile_number, email, user_name, password)
243
+ endpoint = "create_user"
244
+ parameters = { "full_name" => full_name,
245
+ "role" => role,
246
+ "mobile_number" => mobile_number,
247
+ "email" => email,
248
+ "user_name" => user_name,
249
+ "password" => password }
250
+ execute(endpoint, parameters)
251
+ end
252
+
253
+ ##
254
+ # Update user
255
+ #
256
+ # {Full docs - update_user}[http://developer.lipisha.com/index.php/app/launch/api_update_user]
257
+ #
258
+ # ==== Attributes
259
+ #
260
+ # * +full_name+
261
+ # * +role+
262
+ # * +mobile_number+
263
+ # * +email+
264
+ # * +user_name+
265
+ #
266
+ #
267
+ def update_user(full_name, role, mobile_number, email, user_name)
268
+ endpoint = "update_user"
269
+ parameters = { "full_name" => full_name,
270
+ "role" => role,
271
+ "mobile_number" => mobile_number,
272
+ "email" => email,
273
+ "user_name" => user_name }
274
+ execute(endpoint, parameters)
275
+ end
276
+
277
+ ##
278
+ # Create payment account
279
+ #
280
+ # {Full docs - create_payment_account}[http://developer.lipisha.com/index.php/app/launch/api_create_payment_account]
281
+ #
282
+ # ==== Attributes
283
+ #
284
+ # * +transaction_account_type+
285
+ # * +transaction_account_name+
286
+ # * +transaction_account_manager+
287
+ #
288
+ #
289
+ def create_payment_account(transaction_account_type,
290
+ transaction_account_name,
291
+ transaction_account_manager)
292
+ endpoint = "create_payment_account"
293
+ parameters = { "transaction_account_type" => transaction_account_type,
294
+ "transaction_account_name" => transaction_account_name,
295
+ "transaction_account_manager" => transaction_account_manager }
296
+ execute(endpoint, parameters)
297
+ end
298
+
299
+ ##
300
+ # Create withdrawal account
301
+ #
302
+ # {Full docs - create_withdrawal_account}[http://developer.lipisha.com/index.php/app/launch/api_create_withdrawal_account]
303
+ #
304
+ # ==== Attributes
305
+ #
306
+ # * +transaction_account_type+
307
+ # * +transaction_account_name+
308
+ # * +transaction_account_number+
309
+ # * +transaction_account_bank_name+
310
+ # * +transaction_account_bank_branch+
311
+ # * +transaction_account_bank_address+
312
+ # * +transaction_account_swift_code+
313
+ # * +transaction_account_manager+
314
+ #
315
+ #
316
+ def create_withdrawal_account(transaction_account_type,
317
+ transaction_account_name,
318
+ transaction_account_number,
319
+ transaction_account_bank_name,
320
+ transaction_account_bank_branch,
321
+ transaction_account_bank_address,
322
+ transaction_account_swift_code,
323
+ transaction_account_manager)
324
+ endpoint = "create_withdrawal_account"
325
+ parameters = { "transaction_account_type" => transaction_account_type,
326
+ "transaction_account_name" => transaction_account_name,
327
+ "transaction_account_number" => transaction_account_number,
328
+ "transaction_account_bank_name" => transaction_account_bank_name,
329
+ "transaction_account_bank_branch" => transaction_account_bank_branch,
330
+ "transaction_account_bank_address" => transaction_account_bank_address,
331
+ "transaction_account_swift_code" => transaction_account_swift_code,
332
+ "transaction_account_manager" => transaction_account_manager }
333
+ execute(endpoint, parameters)
334
+ end
335
+
336
+ ##
337
+ # Get transactions
338
+ #
339
+ # {Full docs - get_transactions}[http://developer.lipisha.com/index.php/app/launch/api_get_transactions]
340
+ #
341
+ # ==== Attributes
342
+ #
343
+ # * +transaction+
344
+ # * +transaction_type+
345
+ # * +transaction_method+
346
+ # * +transaction_date_start+
347
+ # * +transaction_date_end+
348
+ # * +transaction_account_name+
349
+ # * +transaction_account_number+
350
+ # * +transaction_reference+
351
+ # * +transaction_amount_minimum+
352
+ # * +transaction_amount_maximum+
353
+ # * +transaction_status+
354
+ # * +transaction_name+
355
+ # * +transaction_mobile_number+
356
+ # * +transaction_email+
357
+ # * +limit+
358
+ # * +offset+
359
+ #
360
+ #
361
+ def get_transactions(transaction = "",
362
+ transaction_type = "",
363
+ transaction_method = "",
364
+ transaction_date_start = "",
365
+ transaction_date_end = "",
366
+ transaction_account_name = "",
367
+ transaction_account_number = "",
368
+ transaction_reference = "",
369
+ transaction_amount_minimum = "",
370
+ transaction_amount_maximum = "",
371
+ transaction_status = "",
372
+ transaction_name = "",
373
+ transaction_mobile_number = "",
374
+ transaction_email = "",
375
+ limit = 100,
376
+ offset = 0)
377
+ endpoint = "get_transactions"
378
+ parameters = { "transaction" => transaction,
379
+ "transaction_type" => transaction_type,
380
+ "transaction_method" => transaction_method,
381
+ "transaction_date_start" => transaction_date_start,
382
+ "transaction_date_end" => transaction_date_end,
383
+ "transaction_account_name" => transaction_account_name,
384
+ "transaction_account_number" => transaction_account_number,
385
+ "transaction_reference" => transaction_reference,
386
+ "transaction_amount_minimum" => transaction_amount_minimum,
387
+ "transaction_amount_maximum" => transaction_amount_maximum,
388
+ "transaction_status" => transaction_status,
389
+ "transaction_name" => transaction_name,
390
+ "transaction_mobile_number" => transaction_mobile_number,
391
+ "transaction_email" => transaction_email,
392
+ "limit" => limit,
393
+ "offset" => offset }
394
+ execute(endpoint, parameters)
395
+ end
396
+
397
+ ##
398
+ # Get customers
399
+ #
400
+ # {Full docs - get_customers}[http://developer.lipisha.com/index.php/app/launch/api_get_customers]
401
+ #
402
+ # ==== Attributes
403
+ #
404
+ # * +customer_name+
405
+ # * +customer_mobile_number+
406
+ # * +customer_email+
407
+ # * +customer_first_payment_from+
408
+ # * +customer_first_payment_to+
409
+ # * +customer_last_payment_from+
410
+ # * +customer_last_payment_to+
411
+ # * +customer_payments_minimum+
412
+ # * +customer_payments_maximum+
413
+ # * +customer_total_spent_minimum+
414
+ # * +customer_total_spent_maximum+
415
+ # * +customer_average_spent_minimum+
416
+ # * +customer_average_spent_maximum+
417
+ # * +limit+
418
+ # * +offset+
419
+ #
420
+ #
421
+ def get_customers(customer_name = "",
422
+ customer_mobile_number = "",
423
+ customer_email = "",
424
+ customer_first_payment_from = "",
425
+ customer_first_payment_to = "",
426
+ customer_last_payment_from = "",
427
+ customer_last_payment_to = "",
428
+ customer_payments_minimum = "",
429
+ customer_payments_maximum = "",
430
+ customer_total_spent_minimum = "",
431
+ customer_total_spent_maximum = "",
432
+ customer_average_spent_minimum = "",
433
+ customer_average_spent_maximum = "",
434
+ limit = 1000,
435
+ offset = 0)
436
+ endpoint = "get_customers"
437
+ parameters = { "customer_name" => customer_name,
438
+ "customer_mobile_number" => customer_mobile_number,
439
+ "customer_email" => customer_email,
440
+ "customer_first_payment_from" => customer_first_payment_from,
441
+ "customer_first_payment_to" => customer_first_payment_to,
442
+ "customer_last_payment_from" => customer_last_payment_from,
443
+ "customer_last_payment_to" => customer_last_payment_to,
444
+ "customer_payments_minimum" => customer_payments_minimum,
445
+ "customer_payments_maximum" => customer_payments_maximum,
446
+ "customer_total_spent_minimum" => customer_total_spent_minimum,
447
+ "customer_total_spent_maximum" => customer_total_spent_maximum,
448
+ "customer_average_spent_minimum" => customer_average_spent_minimum,
449
+ "customer_average_spent_maximum" => customer_average_spent_maximum,
450
+ "limit" => limit,
451
+ "offset" => offset }
452
+ execute(endpoint, parameters)
453
+ end
454
+
455
+ ##
456
+ # Authorize card transaction
457
+ #
458
+ # {Full docs - authorize_card_transaction}[http://developer.lipisha.com/index.php/app/launch/api_authorize_card_transaction]
459
+ #
460
+ # ==== Attributes
461
+ #
462
+ # * +account_number+
463
+ # * +card_number+
464
+ # * +address1+
465
+ # * +address2+
466
+ # * +expiry+
467
+ # * +name+
468
+ # * +country+
469
+ # * +state+
470
+ # * +zip+
471
+ # * +security_code+
472
+ # * +amount+
473
+ # * +currency+
474
+ #
475
+ #
476
+ def authorize_card_transaction(account_number,
477
+ card_number,
478
+ address1,
479
+ address2,
480
+ expiry,
481
+ name,
482
+ country,
483
+ state,
484
+ zip,
485
+ security_code,
486
+ amount,
487
+ currency)
488
+ endpoint = "authorize_card_transaction"
489
+ parameters = { "account_number" => account_number,
490
+ "card_number" => card_number,
491
+ "address1" => address1,
492
+ "address2" => address2,
493
+ "expiry" => expiry,
494
+ "name" => name,
495
+ "country" => country,
496
+ "state" => state,
497
+ "zip" => zip,
498
+ "security_code" => security_code,
499
+ "amount" => amount,
500
+ "currency" => currency }
501
+ execute(endpoint, parameters)
502
+ end
503
+
504
+ ##
505
+ # Reverse card transaction
506
+ #
507
+ # {Full docs - reverse_card_transaction}[http://developer.lipisha.com/index.php/app/launch/api_reverse_card_transaction]
508
+ #
509
+ # ==== Attributes
510
+ #
511
+ # * +transaction_index+
512
+ # * +transaction_reference+
513
+ #
514
+ #
515
+ def reverse_card_transaction(transaction_index, transaction_reference)
516
+ endpoint = "reverse_card_transaction"
517
+ parameters = { "transaction_index" => transaction_index,
518
+ "transaction_reference" => transaction_reference }
519
+ execute(endpoint, parameters)
520
+ end
521
+
522
+ ##
523
+ # Complete card transaction
524
+ #
525
+ # {Full docs - complete_card_transaction}[http://developer.lipisha.com/index.php/app/launch/api_complete_card_transaction]
526
+ #
527
+ # ==== Attributes
528
+ #
529
+ # * +transaction_index+
530
+ # * +transaction_reference+
531
+ #
532
+ #
533
+ def complete_card_transaction(transaction_index, transaction_reference)
534
+ endpoint = "complete_card_transaction"
535
+ parameters = { "transaction_index" => transaction_index,
536
+ "transaction_reference" => transaction_reference }
537
+ execute(endpoint, parameters)
538
+ end
539
+
540
+ ##
541
+ # Void card transaction
542
+ #
543
+ # {Full docs - void_card_transaction}[http://developer.lipisha.com/index.php/app/launch/api_void_card_transaction]
544
+ #
545
+ # ==== Attributes
546
+ #
547
+ # * +transaction_index+
548
+ # * +transaction_reference+
549
+ #
550
+ #
551
+ def void_card_transaction(transaction_index, transaction_reference)
552
+ endpoint = "void_card_transaction"
553
+ parameters = { "transaction_index" => transaction_index,
554
+ "transaction_reference" => transaction_reference }
555
+ execute(endpoint, parameters)
556
+ end
557
+
558
+ ##
559
+ # Request settlement
560
+ #
561
+ # {Full docs - request_settlement}[http://developer.lipisha.com/index.php/app/launch/api_request_settlement]
562
+ #
563
+ # ==== Attributes
564
+ #
565
+ # * +account_number+
566
+ # * +amount+
567
+ #
568
+ #
569
+ def request_settlement(account_number, amount)
570
+ endpoint = "request_settlement"
571
+ parameters = { "account_number" => account_number, "amount" => amount }
572
+ execute(endpoint, parameters)
573
+ end
574
+ end
575
+ end
576
+ end
@@ -0,0 +1,5 @@
1
+ module Lipisha
2
+ module Sdk
3
+ VERSION = "1.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lipisha/sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lipisha-sdk"
8
+ spec.version = Lipisha::Sdk::VERSION
9
+ spec.authors = ["Lipisha Consortium Limited"]
10
+ spec.email = ["api@lipisha.com"]
11
+ spec.description = %q{Lipisha Payments Ruby SDK.}
12
+ spec.summary = %q{Lipisha Payments Ruby SDK}
13
+ spec.homepage = "https://github.com/lipisha/lipisha-ruby-sdk"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ spec.add_development_dependency "test-unit", "~> 0"
24
+ end
@@ -0,0 +1,60 @@
1
+ API_KEY = ENV["LIPISHA_API_KEY"]
2
+ API_SIGNATURE = ENV["LIPISHA_API_SIGNATURE"]
3
+ API_ENVIRONMENT = "live"
4
+ STATUS_SUCCESS = "SUCCESS"
5
+ STATUS_CONFIRMED = "Completed"
6
+
7
+ FLOAT_ACCOUNT = ""
8
+ PAYOUT_ACCOUNT = ""
9
+ AIRTIME_ACCOUNT = ""
10
+
11
+ TRANSACTION_ID_CONFIRM = ""
12
+ TRANSACTION_ID_REVERSE = ""
13
+
14
+ AIRTIME_AMOUNT = 10
15
+ AIRTIME_NETWORK = ""
16
+ AIRTIME_MOBILE_NUMBER = ""
17
+ PAYOUT_MOBILE_NUMBER = ""
18
+ PAYOUT_AMOUNT = 10
19
+
20
+
21
+ ACCOUNT_NAME = ""
22
+ ACCOUNT_ADMIN = ""
23
+
24
+
25
+ TEST_USER_NAMES = ""
26
+ TEST_USER_ROLE = ""
27
+ TEST_USER_MOBILE = ""
28
+ TEST_USER_EMAIL = ""
29
+ TEST_USER_LOGIN = ""
30
+
31
+ TEST_TX_ACCOUNT_NAME = ""
32
+ TEST_TX_ACCOUNT_NUMBER = ""
33
+ TEST_TX_ACCOUNT_BANK_NAME = ""
34
+ TEST_TX_ACCOUNT_BANK_BRANCH = ""
35
+ TEST_TX_ACCOUNT_BANK_ADDRESS = ""
36
+ TEST_TX_ACCOUNT_SWIFT_CODE = ""
37
+ TEST_TX_ACCOUNT_MANAGER = ""
38
+
39
+ CARD_AMOUNT = 10
40
+ CARD_CURRENCY = ""
41
+ CARD_ACCOUNT = ""
42
+ CARD_NUMBER = ""
43
+ CARD_ADDRESS1 = ""
44
+ CARD_ADDRESS2 = ""
45
+ CARD_EXPIRY = ""
46
+ CARD_NAMES = ""
47
+ CARD_COUNTRY = ""
48
+ CARD_STATE = ""
49
+ CARD_ZIP = ""
50
+ CARD_SECURITY_CODE = ""
51
+
52
+
53
+ CARD_COMPLETE_TX_INDEX = ""
54
+ CARD_COMPLETE_TX_REF = ""
55
+
56
+ CARD_REVERSE_TX_INDEX = ""
57
+ CARD_REVERSE_TX_REF = ""
58
+
59
+ CARD_VOID_TX_INDEX = ""
60
+ CARD_VOID_TX_REF = ""
@@ -0,0 +1,49 @@
1
+ require "test/unit"
2
+ require "lipisha/sdk"
3
+ require_relative "config"
4
+
5
+ class AccountsTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @lipisha = Lipisha::Sdk::LipishaAPI.new(API_KEY, API_SIGNATURE, API_ENVIRONMENT)
9
+ end
10
+
11
+ def test_create_payment_account
12
+ omit_if((ACCOUNT_NAME.empty? and ACCOUNT_ADMIN.empty?))
13
+ response = @lipisha.create_payment_account(1, ACCOUNT_NAME, ACCOUNT_ADMIN)
14
+ puts(response)
15
+ assert_not_nil response
16
+ assert_equal(STATUS_SUCCESS, response.status)
17
+ end
18
+
19
+ def test_create_withdrawal_account
20
+ omit_if(TEST_TX_ACCOUNT_NAME.empty?)
21
+ response = @lipisha.create_withdrawal_account(1,
22
+ TEST_TX_ACCOUNT_NAME,
23
+ TEST_TX_ACCOUNT_NUMBER,
24
+ TEST_TX_ACCOUNT_BANK_NAME,
25
+ TEST_TX_ACCOUNT_BANK_BRANCH,
26
+ TEST_TX_ACCOUNT_BANK_ADDRESS,
27
+ TEST_TX_ACCOUNT_SWIFT_CODE,
28
+ TEST_TX_ACCOUNT_MANAGER)
29
+ puts(response)
30
+ assert_not_nil response
31
+ assert_equal(STATUS_SUCCESS, response.status)
32
+ assert_equal(TEST_TX_ACCOUNT_NUMBER, response.content["transaction_account_number"])
33
+ end
34
+
35
+ def test_create_user
36
+ omit_if(TEST_USER_ROLE.empty?)
37
+ response = @lipisha.create_user(TEST_USER_NAMES,
38
+ TEST_USER_ROLE,
39
+ TEST_USER_MOBILE,
40
+ TEST_USER_EMAIL,
41
+ TEST_USER_LOGIN,
42
+ TEST_USER_PASSWORD)
43
+ puts(response)
44
+ assert_not_nil response
45
+ assert_equal(STATUS_SUCCESS, response.status)
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,31 @@
1
+ require "test/unit"
2
+ require "lipisha/sdk"
3
+ require_relative "config"
4
+
5
+ class BalanceTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @lipisha = Lipisha::Sdk::LipishaAPI.new(API_KEY, API_SIGNATURE, API_ENVIRONMENT)
9
+ end
10
+
11
+ def test_get_balance
12
+ response = @lipisha.get_balance()
13
+ puts(response)
14
+ assert_not_nil response
15
+ assert_not_nil response.status
16
+ assert_not_nil response.status_code
17
+ assert_not_nil response.content
18
+ assert_equal(STATUS_SUCCESS, response.status)
19
+ end
20
+
21
+ def test_get_float
22
+ omit_if(FLOAT_ACCOUNT.empty?)
23
+ response = @lipisha.get_float(FLOAT_ACCOUNT)
24
+ puts(response)
25
+ assert_not_nil response
26
+ assert_equal(STATUS_SUCCESS, response.status)
27
+ assert_equal(FLOAT_ACCOUNT, response.content["account_number"])
28
+ end
29
+
30
+
31
+ end
@@ -0,0 +1,63 @@
1
+ require "test/unit"
2
+ require "lipisha/sdk"
3
+ require_relative "config"
4
+
5
+ class CardTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @lipisha = Lipisha::Sdk::LipishaAPI.new(API_KEY, API_SIGNATURE, API_ENVIRONMENT)
9
+ end
10
+
11
+ def test_authorize_card_transaction
12
+ omit_if((CARD_NUMBER.empty? and CARD_EXPIRY.empty?))
13
+ response = @lipisha.authorize_card_transaction(CARD_ACCOUNT,
14
+ CARD_NUMBER,
15
+ CARD_ADDRESS1,
16
+ CARD_ADDRESS2,
17
+ CARD_EXPIRY,
18
+ CARD_NAMES,
19
+ CARD_COUNTRY,
20
+ CARD_STATE,
21
+ CARD_ZIP,
22
+ CARD_SECURITY_CODE,
23
+ CARD_AMOUNT,
24
+ CARD_CURRENCY)
25
+ puts(response)
26
+ assert_not_nil response
27
+ assert_equal(STATUS_SUCCESS, response.status)
28
+ end
29
+
30
+ def test_complete_card_transaction
31
+ omit_if((CARD_COMPLETE_TX_REF.empty? and CARD_COMPLETE_TX_INDEX.empty?))
32
+ response = @lipisha.complete_card_transaction(CARD_COMPLETE_TX_INDEX,
33
+ CARD_COMPLETE_TX_REF)
34
+ puts(response)
35
+ assert_not_nil response
36
+ assert_equal(STATUS_SUCCESS, response.status)
37
+ assert_equal(CARD_COMPLETE_TX_INDEX, response.content["transaction_index"])
38
+ assert_equal(CARD_COMPLETE_TX_REF, response.content["transaction_reference"])
39
+ end
40
+
41
+ def test_void_card_transaction
42
+ omit_if((CARD_VOID_TX_REF.empty? and CARD_VOID_TX_INDEX.empty?))
43
+ response = @lipisha.void_card_transaction(CARD_VOID_TX_INDEX,
44
+ CARD_VOID_TX_REF)
45
+ puts(response)
46
+ assert_not_nil response
47
+ assert_equal(STATUS_SUCCESS, response.status)
48
+ assert_equal(CARD_VOID_TX_INDEX, response.content["transaction_index"])
49
+ assert_equal(CARD_VOID_TX_REF, response.content["transaction_reference"])
50
+ end
51
+
52
+ def test_reverse_card_transaction
53
+ omit_if((CARD_REVERSE_TX_REF.empty? and CARD_REVERSE_TX_INDEX.empty?))
54
+ response = @lipisha.reverse_card_transaction(CARD_REVERSE_TX_INDEX,
55
+ CARD_REVERSE_TX_REF)
56
+ puts(response)
57
+ assert_not_nil response
58
+ assert_equal(STATUS_SUCCESS, response.status)
59
+ assert_equal(CARD_REVERSE_TX_INDEX, response.content["transaction_index"])
60
+ assert_equal(CARD_REVERSE_TX_REF, response.content["transaction_reference"])
61
+ end
62
+
63
+ end
@@ -0,0 +1,28 @@
1
+ require "test/unit"
2
+ require "lipisha/sdk"
3
+ require_relative "config"
4
+
5
+ class SendMoneyAirtimeTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @lipisha = Lipisha::Sdk::LipishaAPI.new(API_KEY, API_SIGNATURE, API_ENVIRONMENT)
9
+ end
10
+
11
+ def test_send_money
12
+ omit_if((PAYOUT_AMOUNT.nil? and PAYOUT_ACCOUNT.empty? and PAYOUT_MOBILE_NUMBER.empty?))
13
+ response = @lipisha.send_money(PAYOUT_ACCOUNT, PAYOUT_MOBILE_NUMBER, PAYOUT_AMOUNT)
14
+ puts(response)
15
+ assert_not_nil response
16
+ assert_equal(STATUS_SUCCESS, response.status)
17
+ end
18
+
19
+ def test_send_airtime
20
+ omit_if((AIRTIME_AMOUNT.nil? and AIRTIME_NETWORK.empty? and AIRTIME_MOBILE_NUMBER.empty?))
21
+ response = @lipisha.send_airtime(AIRTIME_ACCOUNT, AIRTIME_MOBILE_NUMBER, AIRTIME_AMOUNT, AIRTIME_NETWORK)
22
+ puts(response)
23
+ assert_not_nil response
24
+ assert_equal(STATUS_SUCCESS, response.status)
25
+ assert_equal(AIRTIME_MOBILE_NUMBER, response.content["mobile_number"])
26
+ assert_equal(AIRTIME_AMOUNT, response.content["amount"])
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ require "test/unit"
2
+ require "lipisha/sdk"
3
+ require_relative "config"
4
+
5
+ class TransactionsTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @lipisha = Lipisha::Sdk::LipishaAPI.new(API_KEY, API_SIGNATURE, API_ENVIRONMENT)
9
+ end
10
+
11
+ def test_get_transactions
12
+ response = @lipisha.get_transactions(transcation_amount_minimum=10.0,
13
+ transaction_amount_maximum=200.0)
14
+ puts(response)
15
+ assert_not_nil response
16
+ assert_not_nil response.status
17
+ assert_not_nil response.status_code
18
+ assert_not_nil response.content
19
+ assert_equal(STATUS_SUCCESS, response.status)
20
+ end
21
+
22
+ def test_get_customers
23
+ response = @lipisha.get_customers(customer_payments_minimum=20.0)
24
+ puts(response)
25
+ assert_not_nil response
26
+ assert_equal(STATUS_SUCCESS, response.status)
27
+ end
28
+
29
+ def test_confirm_transaction
30
+ omit_if(TRANSACTION_ID_CONFIRM.empty?)
31
+ response = @lipisha.confirm_transaction(TRANSACTION_ID_CONFIRM)
32
+ puts(response)
33
+ assert_not_nil response
34
+ assert_not_nil response.content
35
+ assert_not_nil response.status
36
+ assert_equal(STATUS_SUCCESS, response.status)
37
+ assert_equal(STATUS_CONFIRMED, response.content["transaction_status"])
38
+ end
39
+
40
+ def test_reverse_transaction
41
+ omit_if(TRANSACTION_ID_REVERSE.empty?)
42
+ response = @lipisha.reverse_transaction(TRANSACTION_ID_REVERSE)
43
+ assert_not_nil response
44
+ assert_equal(STATUS_SUCCESS, response.status)
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lipisha-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Lipisha Consortium Limited
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Lipisha Payments Ruby SDK.
56
+ email:
57
+ - api@lipisha.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - examples/README.md
69
+ - lib/lipisha/sdk.rb
70
+ - lib/lipisha/sdk/version.rb
71
+ - lipisha-sdk.gemspec
72
+ - test/config.rb
73
+ - test/test_accounts.rb
74
+ - test/test_balance.rb
75
+ - test/test_cards.rb
76
+ - test/test_send_money_airtime.rb
77
+ - test/test_transactions_customers.rb
78
+ homepage: https://github.com/lipisha/lipisha-ruby-sdk
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Lipisha Payments Ruby SDK
102
+ test_files:
103
+ - test/config.rb
104
+ - test/test_accounts.rb
105
+ - test/test_balance.rb
106
+ - test/test_cards.rb
107
+ - test/test_send_money_airtime.rb
108
+ - test/test_transactions_customers.rb