mpayer_ruby 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b4d99a94ee5c778c3be51edc14a2a13e6a44e93
4
- data.tar.gz: 33951faa2cb58c902faf7e9d7502e05064ff125d
3
+ metadata.gz: e57d97fe2e30c9be6a54646a115b271cdd47cafb
4
+ data.tar.gz: b7236c7fddab6140c0aeeeb8c4eeb33c90087c53
5
5
  SHA512:
6
- metadata.gz: 477d864b4897a932be2ae34c90da8afef2948795c11485a47f1274c535cad8605cd06bbaab6ba382adb42a814117af76207c2a6a0e908a69d938fb674f75fb09
7
- data.tar.gz: cb3ee3475cc84284ca7b11d6a1787864553769e408aa7f10cff8be78978a9b6d9a2ea7d80223369ddf04eae5cc4a49b4cb8f5f633efd8a17f20c4f9284063dca
6
+ metadata.gz: 72472be1d6e853bad00ee6c377357327b8b02bfa1a4dbe485efbda2f9bb59464d3bef58c9cad184ef6294982d9feb90befe9727b2597f14dbfe221d24528468f
7
+ data.tar.gz: 06b71dcaa992df7893efa807574a5605b974513f679514e9c05108257b509992817d442e7f53ef590fa0664a8af58febc07a24ba794dc03db35a1e974963c416
data/README.md CHANGED
@@ -32,7 +32,7 @@ export MPAYER_TOKEN=<Your token>
32
32
  ```
33
33
 
34
34
  ## Configurations
35
- To configure credentials locally on you code use config block below. For Rails, put this in `config/initializers/mpayer.rb`
35
+ To configure credentials for your API calls on you code use config block below. For Rails, put this in `config/initializers/mpayer.rb`
36
36
 
37
37
  ```ruby
38
38
  Mpayer.setup do |config|
@@ -67,6 +67,8 @@ clients = Mpayer::Client.find(123, fetch:false)
67
67
  ## Endpoints
68
68
  Mpayer gem currently supports a few endpoint below
69
69
 
70
+ https://app.mpayer.co.ke/api/login
71
+
70
72
  https://app.mpayer.co.ke/api/client
71
73
 
72
74
  https://app.mpayer.co.ke/api/accounts
@@ -83,6 +85,16 @@ client = client.first
83
85
  client.name #=> "CLark Kent"
84
86
  ```
85
87
 
88
+ ### Login
89
+ Login provides your organisations settings and credentials.
90
+ ```ruby
91
+ login = Mpayer.login
92
+ # defaults are picked from user:ENV['MPAYER_USER'],password:ENV['MPAYER_PASSWORD']
93
+
94
+ login = Mpayer.login(user:'james@bond.com', password: "bond..james bond")
95
+
96
+ ```
97
+
86
98
  ### Client
87
99
  ```ruby
88
100
  clients = Mpayer::Client.all
@@ -15,8 +15,18 @@ module Mpayer
15
15
  after_initialize
16
16
  end
17
17
 
18
+ def id=(value)
19
+ raise Exception, "Mpayer Object ID cannot be nil" if value.nil? and attributes.deleting.nil?
20
+ @id = value
21
+ end
22
+
18
23
  protected
19
24
 
25
+ def kill
26
+ instance_variables.each{|var| instance_variable_set(var,nil)}
27
+ freeze
28
+ end
29
+
20
30
  # after_initialize{ @endpoint = 'clients'}
21
31
  # class << self
22
32
  # # Used to instantiate new objects instead of using def initialize
@@ -35,7 +35,7 @@ module Mpayer
35
35
  def destroy
36
36
  url = "/payables/#{self.id}"
37
37
  self.response = Mpayer::Fetch.delete(url)
38
- self.id, self.attributes = nil, nil
38
+ self.kill
39
39
  end
40
40
 
41
41
  protected
@@ -0,0 +1,108 @@
1
+ module Mpayer::TestHelper
2
+ # login
3
+ # create_mpayer_client
4
+ # create_mpayer_account
5
+ # create_mpayer_payable
6
+ # get_mpayer_accounts
7
+ # get_mpayer_account
8
+ # create_mpayer_transaction
9
+ # get_mpayer_transactions
10
+
11
+ def mpayer_login
12
+ @@mpayer_login ||= Mpayer.login
13
+ end
14
+
15
+ def create_mpayer_client
16
+ client_attributes = {
17
+ client: {
18
+ client_name: Faker::Name.name,
19
+ client_birthday: Time.now.iso8601,
20
+ client_type: "ext",
21
+ ac_type: "cu",
22
+ client_mobile: Faker::Number.number(10) ,
23
+ client_email: Faker::Internet.email,
24
+ currency: "kes",
25
+ mandate:"s",
26
+ sub_type: "od"
27
+ }
28
+ }
29
+ @@create_mpayer_client ||= Mpayer::Client.create(client_attributes)
30
+ @@client_account ||= Mpayer::Client.find(@@create_mpayer_client.id,fetch:false).account(@@create_mpayer_client.account.id)
31
+ @@create_mpayer_client
32
+ end
33
+
34
+ def create_mpayer_account
35
+ client = create_mpayer_client
36
+ account_options = {
37
+ account:{
38
+ name: "#{client.fname} #{client.lname}",
39
+ ac_type: 'cu',
40
+ sub_type: 'od',
41
+ mandate: 's',
42
+ aliases_attributes: [{org_id:mpayer_login.org_no ,alias_key:'telephone', alias_value:"#{client.fname}#{SecureRandom.uuid.gsub('-','')}"}]
43
+ # tags_attributes:@tags,
44
+ # infos_attributes:@infos
45
+ }
46
+ }
47
+ @@create_mpayer_account ||= client.create_account(account_options)
48
+ @@account ||= Mpayer::Client.find(client.id,fetch:false).account(@@create_mpayer_account.id)
49
+ @@create_mpayer_account
50
+ end
51
+
52
+ def create_mpayer_payable
53
+ account = create_mpayer_account
54
+ payable_items = []
55
+ [*0..5].each do |n|
56
+ payable_items << {
57
+ payment_party: account.acid ,
58
+ terminal_ac: account.acid ,
59
+ details: Faker::Lorem.sentence ,
60
+ amount: 10,
61
+ price: 10,
62
+ unit_measure: 1.0
63
+ }
64
+ end
65
+
66
+ options = {
67
+ payment: {
68
+ payable_no: SecureRandom.uuid,
69
+ note: Faker::Lorem.sentence ,
70
+ ref_id: SecureRandom.uuid,
71
+ # client_id: client_id,
72
+ # status: @model.status,
73
+ # payable_type: @model.payable_type,
74
+ due_date: Time.now+(86400*31),
75
+ pay: payable_items
76
+ # tags:@tags,
77
+ # flags:@flags,
78
+ # infos:@infos ,
79
+ # sync_lag:@sync_lag
80
+ }
81
+ }
82
+ @@create_mpayer_payable ||= Mpayer::Payable.create(options)
83
+ @@search_payable ||= Mpayer::Payable.where(ref_id:@@create_mpayer_payable.ref_id)
84
+ @@create_mpayer_payable
85
+ end
86
+
87
+ def get_mpayer_accounts
88
+ @@get_mpayer_accounts ||= Mpayer::Account.all
89
+ end
90
+
91
+ def get_mpayer_account
92
+ first_account = get_mpayer_accounts.first
93
+ @@get_mpayer_account ||= Mpayer::Account.find(first_account.id)
94
+ end
95
+
96
+ def create_mpayer_transaction
97
+ body = {particulars:Faker::Lorem.sentence,amount:1000, cr_party: get_mpayer_account.acid}
98
+ body.merge!({ref_num:Faker::Code.isbn})
99
+ @@create_mpayer_transaction ||= Mpayer::Transaction.deposit(body)
100
+ @@search_tran ||= Mpayer::Transaction.where(ref_id:@@create_mpayer_transaction.ref_id)
101
+ @@create_mpayer_transaction
102
+ end
103
+
104
+ def get_mpayer_transactions
105
+ @@get_mpayer_transactions ||= Mpayer::Transaction.all(from: Time.now - (86400*400))
106
+ @@get_mpayer_transactions.any? ? @@get_mpayer_transactions : [create_mpayer_transaction]
107
+ end
108
+ end
@@ -1,3 +1,3 @@
1
1
  module Mpayer
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/mpayer_ruby.rb CHANGED
@@ -33,8 +33,8 @@ module Mpayer
33
33
  yield(configuration)
34
34
  end
35
35
 
36
- def login
37
- Mpayer::Fetch.post('/login',{user: ENV['MPAYER_USER'],password:ENV['MPAYER_PASSWORD']})
36
+ def login(user:ENV['MPAYER_USER'],password:ENV['MPAYER_PASSWORD'])
37
+ Mpayer::Fetch.post('/login',{user: user,password:password})
38
38
  end
39
39
  end
40
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpayer_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kariuki Gathitu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-30 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -268,6 +268,7 @@ files:
268
268
  - lib/mpayer_ruby/support/fake_mpayer/messages/.keep
269
269
  - lib/mpayer_ruby/support/fake_mpayer/payables/.keep
270
270
  - lib/mpayer_ruby/support/fake_mpayer/transactions/.keep
271
+ - lib/mpayer_ruby/support/test_helper.rb
271
272
  - lib/mpayer_ruby/version.rb
272
273
  - mpayer_ruby.gemspec
273
274
  homepage: https://github.com/kgathi2/mpayer_ruby