k2-connect-ruby 2.0.0 → 3.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/Gemfile.lock +78 -64
  4. data/README.md +70 -49
  5. data/k2-connect-ruby.gemspec +12 -11
  6. data/lib/k2-connect-ruby/{k2_entity/entity.rb → entity.rb} +5 -0
  7. data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +24 -26
  8. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +92 -98
  9. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +43 -44
  10. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +43 -44
  11. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +35 -36
  12. data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +34 -35
  13. data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +32 -34
  14. data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +34 -36
  15. data/lib/k2-connect-ruby/k2_entity/k2_token.rb +58 -54
  16. data/lib/k2-connect-ruby/k2_errors.rb +64 -62
  17. data/lib/k2-connect-ruby/k2_services/k2_client.rb +27 -0
  18. data/lib/k2-connect-ruby/k2_services/payload_process.rb +10 -5
  19. data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +52 -46
  20. data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +57 -51
  21. data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +50 -42
  22. data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +19 -11
  23. data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +16 -8
  24. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +18 -0
  25. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +13 -0
  26. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +13 -0
  27. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +20 -12
  28. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +40 -32
  29. data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +49 -46
  30. data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +19 -0
  31. data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +39 -32
  32. data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +42 -37
  33. data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +51 -50
  34. data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +11 -6
  35. data/lib/k2-connect-ruby/k2_utilities/k2_validation.rb +104 -102
  36. data/lib/k2-connect-ruby/{utilities.rb → k2_utilities.rb} +8 -8
  37. data/lib/k2-connect-ruby/version.rb +1 -1
  38. data/lib/k2-connect-ruby.rb +7 -25
  39. metadata +56 -43
  40. data/lib/k2-connect-ruby/k2_services/client/k2_client.rb +0 -24
  41. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_received.rb +0 -10
  42. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_received.rb +0 -5
  43. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_reversal.rb +0 -5
  44. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/m2m_transaction.rb +0 -8
  45. data/lib/k2-connect-ruby/k2_utilities/k2_authorize.rb +0 -14
  46. data/lib/k2-connect-ruby/k2_utilities/spec_modules/spec_config.rb +0 -41
@@ -1,104 +1,98 @@
1
- # For PAY/ Send Money to others
2
- # TODO: Add K2Config configuration for the callback URL
3
- class K2Pay < K2Entity
4
- attr_reader :recipients_location_url, :payments_location_url
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Pay < K2ConnectRuby::K2Entity::K2Entity
4
+ attr_reader :recipients_location_url, :payments_location_url
5
5
 
6
- # Adding PAY Recipients with either mobile_wallets or bank_accounts as destination of your payments.
7
- def add_recipient(params)
8
- params = params.with_indifferent_access
9
- @exception_array += %w[type]
10
- # In the case of mobile pay recipient
11
- if params[:type].eql?('mobile_wallet')
12
- params = validate_input(params, @exception_array += %w[first_name last_name phone_number email network])
13
- k2_request_pay_recipient = {
14
- first_name: params[:first_name],
15
- last_name: params[:last_name],
16
- phone_number: validate_phone(params[:phone_number]),
17
- email: validate_email(params[:email]),
18
- network: params[:network]
19
- }
20
- # In the case of bank pay recipient
21
- elsif params[:type].eql?('bank_account')
22
- params = validate_input(params, @exception_array += %w[account_name account_number bank_branch_ref settlement_method])
23
- k2_request_pay_recipient = {
24
- account_name: params[:account_name],
25
- account_number: params[:account_number],
26
- bank_branch_ref: params[:bank_branch_ref],
27
- settlement_method: params[:settlement_method]
28
- }
29
- # In the case of till pay recipient
30
- elsif params[:type].eql?('till')
31
- params = validate_input(params, @exception_array += %w[till_name till_number])
32
- k2_request_pay_recipient = {
33
- till_name: params[:till_name],
34
- till_number: params[:till_number]
35
- }
36
- # In the case of bank pay recipient
37
- elsif params[:type].eql?('paybill')
38
- params = validate_input(params, @exception_array += %w[paybill_name paybill_number paybill_account_number])
39
- k2_request_pay_recipient = {
40
- paybill_name: params[:paybill_name],
41
- paybill_number: params[:paybill_number],
42
- paybill_account_number: params[:paybill_account_number]
43
- }
44
- else
45
- raise ArgumentError, 'Undefined Payment Method.'
46
- end
47
- recipients_body = {
48
- type: params[:type],
49
- #type: params['pay_type'],
50
- pay_recipient: k2_request_pay_recipient
51
- }
52
- pay_recipient_hash = make_hash(K2Config.path_url('pay_recipient'), 'post', @access_token, 'PAY', recipients_body)
53
- @threads << Thread.new do
54
- sleep 0.25
55
- @recipients_location_url = K2Connect.make_request(pay_recipient_hash)
56
- end
57
- @threads.each(&:join)
58
- end
6
+ # Adding PAY Recipients with either mobile_wallets or bank_accounts as destination of your payments.
7
+ def add_recipient(params)
8
+ params = params.with_indifferent_access
9
+ @exception_array += %w[type]
10
+ # In the case of mobile pay recipient
11
+ k2_request_pay_recipient = if params[:type].eql?('mobile_wallet')
12
+ params = validate_input(params, @exception_array += %w[first_name last_name phone_number email network])
13
+ {
14
+ first_name: params[:first_name],
15
+ last_name: params[:last_name],
16
+ phone_number: validate_phone(params[:phone_number]),
17
+ email: validate_email(params[:email]),
18
+ network: params[:network]
19
+ }
20
+ # In the case of bank pay recipient
21
+ elsif params[:type].eql?('bank_account')
22
+ params = validate_input(params, @exception_array += %w[account_name account_number bank_branch_ref settlement_method])
23
+ {
24
+ account_name: params[:account_name],
25
+ account_number: params[:account_number],
26
+ bank_branch_ref: params[:bank_branch_ref],
27
+ settlement_method: params[:settlement_method]
28
+ }
29
+ # In the case of till pay recipient
30
+ elsif params[:type].eql?('till')
31
+ params = validate_input(params, @exception_array += %w[till_name till_number])
32
+ {
33
+ till_name: params[:till_name],
34
+ till_number: params[:till_number]
35
+ }
36
+ # In the case of bank pay recipient
37
+ elsif params[:type].eql?('paybill')
38
+ params = validate_input(params, @exception_array += %w[paybill_name paybill_number paybill_account_number])
39
+ {
40
+ paybill_name: params[:paybill_name],
41
+ paybill_number: params[:paybill_number],
42
+ paybill_account_number: params[:paybill_account_number]
43
+ }
44
+ else
45
+ raise ArgumentError, 'Undefined Payment Method.'
46
+ end
47
+ recipients_body = {
48
+ type: params[:type],
49
+ #type: params['pay_type'],
50
+ pay_recipient: k2_request_pay_recipient
51
+ }
52
+ pay_recipient_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('pay_recipient'), 'post', @access_token, 'PAY', recipients_body)
53
+ @recipients_location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(pay_recipient_hash)
54
+ end
59
55
 
60
- # Create an outgoing Payment to a third party.
61
- def create_payment(params)
62
- # Validation
63
- params = validate_input(params, @exception_array += %w[destination_reference destination_type description category tags currency value callback_url metadata])
64
- # The Request Body Parameters
65
- k2_request_pay_amount = {
66
- currency: params[:currency],
67
- value: params[:value]
68
- }
69
- k2_request_pay_metadata = params[:metadata]
70
- k2_request_links = {
71
- callback_url: params[:callback_url]
72
- }
73
- create_payment_body = {
74
- destination_reference: params[:destination_reference],
75
- destination_type: params[:destination_type],
76
- description: params[:description],
77
- category: params[:category],
78
- tags: params[:tags],
79
- amount: k2_request_pay_amount,
80
- meta_data: k2_request_pay_metadata,
81
- _links: k2_request_links
82
- }
83
- create_payment_hash = make_hash(K2Config.path_url('payments'), 'post', @access_token, 'PAY', create_payment_body)
84
- @threads << Thread.new do
85
- sleep 0.25
86
- @payments_location_url = K2Connect.make_request(create_payment_hash)
87
- end
88
- @threads.each(&:join)
89
- end
56
+ # Create an outgoing Payment to a third party.
57
+ def create_payment(params)
58
+ # Validation
59
+ params = validate_input(params, @exception_array += %w[destination_reference destination_type description category tags currency value callback_url metadata])
60
+ # The Request Body Parameters
61
+ k2_request_pay_amount = {
62
+ currency: params[:currency],
63
+ value: params[:value]
64
+ }
65
+ k2_request_pay_metadata = params[:metadata]
66
+ k2_request_links = {
67
+ callback_url: params[:callback_url]
68
+ }
69
+ create_payment_body = {
70
+ destination_reference: params[:destination_reference],
71
+ destination_type: params[:destination_type],
72
+ description: params[:description],
73
+ category: params[:category],
74
+ tags: params[:tags],
75
+ amount: k2_request_pay_amount,
76
+ meta_data: k2_request_pay_metadata,
77
+ _links: k2_request_links
78
+ }
79
+ create_payment_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('payments'), 'post', @access_token, 'PAY', create_payment_body)
80
+ @payments_location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(create_payment_hash)
81
+ end
90
82
 
91
- # Query/Check the status of a previously initiated PAY Payment request
92
- def query_status(method_type)
93
- if method_type.eql?('recipients')
94
- super('PAY', @recipients_location_url)
95
- elsif method_type.eql?('payments')
96
- super('PAY', @payments_location_url)
97
- end
98
- end
83
+ # Query/Check the status of a previously initiated PAY Payment request
84
+ def query_status(method_type)
85
+ if method_type.eql?('recipients')
86
+ super('PAY', @recipients_location_url)
87
+ elsif method_type.eql?('payments')
88
+ super('PAY', @payments_location_url)
89
+ end
90
+ end
99
91
 
100
- # Query Location URL
101
- def query_resource(url)
102
- super('PAY', url)
92
+ # Query Location URL
93
+ def query_resource(url)
94
+ super('PAY', url)
95
+ end
96
+ end
103
97
  end
104
98
  end
@@ -1,49 +1,48 @@
1
- # For Creating pre-approved and owned settlement accounts
2
- class K2Settlement < K2Entity
3
- # Create a Verified Settlement Account via API (Mobile Wallet and Bank Account)
4
- def add_settlement_account(params)
5
- params=params.with_indifferent_access
6
- the_path_url = ''
7
- settlement_body = {}
8
- @exception_array += %w[type]
9
- # The Request Body Parameters
10
- if params[:type].eql?('merchant_wallet')
11
- params = validate_input(params, @exception_array += %w[first_name last_name phone_number network])
12
- settlement_body = {
13
- first_name: params[:first_name],
14
- last_name: params[:last_name],
15
- phone_number: validate_phone(params[:phone_number]),
16
- network: params[:network]
17
- }
18
- the_path_url = K2Config.path_url('settlement_mobile_wallet')
19
- elsif params[:type].eql?('merchant_bank_account')
20
- params = validate_input(params, @exception_array += %w[account_name bank_ref bank_branch_ref account_number currency value, settlement_method])
21
- settlement_body = {
22
- account_name: params[:account_name],
23
- bank_branch_ref: params[:bank_branch_ref],
24
- account_number: params[:account_number],
25
- settlement_method: params[:settlement_method]
26
- }
27
- the_path_url = K2Config.path_url('settlement_bank_account')
28
- else
29
- raise ArgumentError, 'Unknown Settlement Account'
30
- end
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Settlement < K2ConnectRuby::K2Entity::K2Entity
4
+ # Create a Verified Settlement Account via API (Mobile Wallet and Bank Account)
5
+ def add_settlement_account(params)
6
+ params=params.with_indifferent_access
7
+ the_path_url = ''
8
+ settlement_body = {}
9
+ @exception_array += %w[type]
10
+ # The Request Body Parameters
11
+ settlement_body = if params[:type].eql?('merchant_wallet')
12
+ params = validate_input(params, @exception_array += %w[first_name last_name phone_number network])
13
+ the_path_url = K2ConnectRuby::K2Utilities::Config::K2Config.path_url('settlement_mobile_wallet')
14
+ {
15
+ first_name: params[:first_name],
16
+ last_name: params[:last_name],
17
+ phone_number: validate_phone(params[:phone_number]),
18
+ network: params[:network]
19
+ }
20
+ elsif params[:type].eql?('merchant_bank_account')
21
+ params = validate_input(params, @exception_array += %w[account_name bank_ref bank_branch_ref account_number currency value, settlement_method])
22
+ the_path_url = K2ConnectRuby::K2Utilities::Config::K2Config.path_url('settlement_bank_account')
23
+ {
24
+ account_name: params[:account_name],
25
+ bank_branch_ref: params[:bank_branch_ref],
26
+ account_number: params[:account_number],
27
+ settlement_method: params[:settlement_method]
28
+ }
29
+ else
30
+ raise ArgumentError, 'Unknown Settlement Account'
31
+ end
31
32
 
32
- settlement_hash = make_hash(the_path_url, 'post', @access_token, 'Transfer', settlement_body)
33
- @threads << Thread.new do
34
- sleep 0.25
35
- @location_url = K2Connect.make_request(settlement_hash)
36
- end
37
- @threads.each(&:join)
38
- end
33
+ settlement_hash = make_hash(the_path_url, 'post', @access_token, 'Transfer', settlement_body)
34
+ @location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(settlement_hash)
35
+ end
39
36
 
40
- # Check the status of a prior initiated Transfer. Make sure to add the id to the url
41
- def query_status
42
- super('Settlement', path_url=@location_url)
43
- end
37
+ # Check the status of a prior initiated Transfer. Make sure to add the id to the url
38
+ def query_status
39
+ super('Settlement', path_url=@location_url)
40
+ end
44
41
 
45
- # Query Location URL
46
- def query_resource(url)
47
- super('Settlement', url)
42
+ # Query Location URL
43
+ def query_resource(url)
44
+ super('Settlement', url)
45
+ end
46
+ end
48
47
  end
49
48
  end
@@ -1,48 +1,47 @@
1
- # For STK Push/Receive MPESA Payments from merchant's customers
2
- class K2Stk < K2Entity
3
- # Receive payments from M-PESA users.
4
- def receive_mpesa_payments(params)
5
- # Validation
6
- params = validate_input(params, @exception_array += %w[payment_channel till_number first_name last_name phone_number email currency value metadata callback_url])
7
- # The Request Body Parameters
8
- k2_request_subscriber = {
9
- first_name: params[:first_name],
10
- middle_name: params[:middle_name],
11
- last_name: params[:last_name],
12
- phone_number: validate_phone(params[:phone_number]),
13
- email: validate_email(params[:email])
14
- }
15
- k2_request_amount = {
16
- currency: 'KES',
17
- value: params[:value]
18
- }
19
- k2_request_metadata = params[:metadata]
20
- k2_request_links = {
21
- callback_url: params[:callback_url]
22
- }
23
- receive_body = {
24
- payment_channel: params[:payment_channel],
25
- till_number: validate_till_number_prefix(params[:till_number]),
26
- subscriber: k2_request_subscriber,
27
- amount: k2_request_amount,
28
- meta_data: k2_request_metadata,
29
- _links: k2_request_links
30
- }
31
- receive_hash = make_hash(K2Config.path_url('incoming_payments'), 'post', @access_token, 'STK', receive_body)
32
- @threads << Thread.new do
33
- sleep 0.25
34
- @location_url = K2Connect.make_request(receive_hash)
35
- end
36
- @threads.each(&:join)
37
- end
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Stk < K2ConnectRuby::K2Entity::K2Entity
4
+ # Receive payments from M-PESA users.
5
+ def receive_mpesa_payments(params)
6
+ # Validation
7
+ params = validate_input(params, @exception_array += %w[payment_channel till_number first_name last_name phone_number email currency value metadata callback_url])
8
+ # The Request Body Parameters
9
+ k2_request_subscriber = {
10
+ first_name: params[:first_name],
11
+ middle_name: params[:middle_name],
12
+ last_name: params[:last_name],
13
+ phone_number: validate_phone(params[:phone_number]),
14
+ email: validate_email(params[:email])
15
+ }
16
+ k2_request_amount = {
17
+ currency: 'KES',
18
+ value: params[:value]
19
+ }
20
+ k2_request_metadata = params[:metadata]
21
+ k2_request_links = {
22
+ callback_url: params[:callback_url]
23
+ }
24
+ receive_body = {
25
+ payment_channel: params[:payment_channel],
26
+ till_number: validate_till_number_prefix(params[:till_number]),
27
+ subscriber: k2_request_subscriber,
28
+ amount: k2_request_amount,
29
+ meta_data: k2_request_metadata,
30
+ _links: k2_request_links
31
+ }
32
+ receive_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('incoming_payments'), 'post', @access_token, 'STK', receive_body)
33
+ @location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(receive_hash)
34
+ end
38
35
 
39
- # Query/Check STK Payment Request Status
40
- def query_status
41
- super('STK', path_url=@location_url)
42
- end
36
+ # Query/Check STK Payment Request Status
37
+ def query_status
38
+ super('STK', path_url=@location_url)
39
+ end
43
40
 
44
- # Query Location URL
45
- def query_resource(url)
46
- super('STK', url)
41
+ # Query Location URL
42
+ def query_resource(url)
43
+ super('STK', url)
44
+ end
45
+ end
47
46
  end
48
47
  end
@@ -1,45 +1,44 @@
1
- # For Transferring funds to pre-approved and owned settlement accounts
2
- class K2Transfer < K2Entity
3
- # Create a either a 'blind' transfer, for when destination is specified, and a 'targeted' transfer which has a specified destination.
4
- def transfer_funds(params)
5
- # Validation
6
- unless params["destination_reference"].blank? && params["destination_type"].blank?
7
- params = validate_input(params, @exception_array += %w[destination_reference destination_type currency value callback_url metadata])
8
- end
9
- params = params.with_indifferent_access
10
- # The Request Body Parameters
11
- k2_request_transfer = {
12
- destination_reference: params[:destination_reference],
13
- destination_type: params[:destination_type],
14
- amount: {
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Transfer < K2ConnectRuby::K2Entity::K2Entity
4
+ # Create a either a 'blind' transfer, for when destination is specified, and a 'targeted' transfer which has a specified destination.
5
+ def transfer_funds(params)
6
+ # Validation
7
+ unless params["destination_reference"].blank? && params["destination_type"].blank?
8
+ params = validate_input(params, @exception_array += %w[destination_reference destination_type callback_url metadata])
9
+ end
10
+ params = params.with_indifferent_access
11
+ # The Request Body Parameters
12
+ k2_request_transfer = {
13
+ destination_reference: params[:destination_reference],
14
+ destination_type: params[:destination_type],
15
+ amount: {
15
16
  currency: params[:currency],
16
17
  value: params[:value]
18
+ }
17
19
  }
18
- }
19
- metadata = params[:metadata]
20
- transfer_body = k2_request_transfer.merge(
21
- {
20
+ metadata = params[:metadata]
21
+ transfer_body = k2_request_transfer.merge(
22
+ {
22
23
  _links:
23
- {
24
- callback_url: params[:callback_url]
25
- },
24
+ {
25
+ callback_url: params[:callback_url]
26
+ },
26
27
  metadata: metadata
27
- })
28
- transfer_hash = make_hash(K2Config.path_url('transfers'), 'post', @access_token, 'Transfer', transfer_body)
29
- @threads << Thread.new do
30
- sleep 0.25
31
- @location_url = K2Connect.make_request(transfer_hash)
32
- end
33
- @threads.each(&:join)
34
- end
28
+ })
29
+ transfer_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('transfers'), 'post', @access_token, 'Transfer', transfer_body)
30
+ @location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(transfer_hash)
31
+ end
35
32
 
36
- # Check the status of a prior initiated Transfer. Make sure to add the id to the url
37
- def query_status
38
- super('Transfer', path_url=@location_url)
39
- end
33
+ # Check the status of a prior initiated Transfer. Make sure to add the id to the url
34
+ def query_status
35
+ super('Transfer', path_url=@location_url)
36
+ end
40
37
 
41
- # Query Location URL
42
- def query_resource(url)
43
- super('Transfer', url)
38
+ # Query Location URL
39
+ def query_resource(url)
40
+ super('Transfer', url)
41
+ end
42
+ end
44
43
  end
45
44
  end
@@ -1,41 +1,40 @@
1
- class K2Notification
2
- include K2Validation, K2Utilities
3
- attr_reader :location_url, :k2_response_body
4
- attr_accessor :access_token
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Notification
4
+ include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
5
+ attr_reader :location_url, :k2_response_body
6
+ attr_accessor :access_token
5
7
 
6
- # Initialize with access_token
7
- def initialize(access_token)
8
- raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
9
- @threads = []
10
- @access_token = access_token
11
- end
8
+ # Initialize with access_token
9
+ def initialize(access_token)
10
+ raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
11
+ @access_token = access_token
12
+ end
12
13
 
13
- # Sends transaction notifications via SMS
14
- def send_sms_transaction_notification(params)
15
- k2_request_links = {
16
- callback_url: params[:callback_url]
17
- }
18
- k2_request_body = {
19
- webhook_event_reference: params[:webhook_event_reference],
20
- message: params[:message],
21
- _links: k2_request_links,
22
- }
23
- subscribe_hash = make_hash(K2Config.path_url('transaction_sms_notifications'), 'post', @access_token,'Notification', k2_request_body)
24
- @location_url = K2Connect.make_request(subscribe_hash)
25
- end
14
+ # Sends transaction notifications via SMS
15
+ def send_sms_transaction_notification(params)
16
+ k2_request_links = {
17
+ callback_url: params[:callback_url]
18
+ }
19
+ k2_request_body = {
20
+ webhook_event_reference: params[:webhook_event_reference],
21
+ message: params[:message],
22
+ _links: k2_request_links,
23
+ }
24
+ subscribe_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('transaction_sms_notifications'), 'post', @access_token,'Notification', k2_request_body)
25
+ @location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(subscribe_hash)
26
+ end
26
27
 
27
- # Query Recent Webhook
28
- def query_resource(location_url = @location_url)
29
- query_hash = make_hash(location_url, 'get', @access_token, 'Notification', nil)
30
- @threads << Thread.new do
31
- sleep 0.25
32
- @k2_response_body = K2Connect.make_request(query_hash)
33
- end
34
- @threads.each(&:join)
35
- end
28
+ # Query Recent Webhook
29
+ def query_resource(location_url = @location_url)
30
+ query_hash = make_hash(location_url, 'get', @access_token, 'Notification', nil)
31
+ @k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
32
+ end
36
33
 
37
- # Query Specific Webhook URL
38
- def query_resource_url(url)
39
- query_resource(url)
34
+ # Query Specific Webhook URL
35
+ def query_resource_url(url)
36
+ query_resource(url)
37
+ end
38
+ end
40
39
  end
41
40
  end
@@ -1,40 +1,38 @@
1
- # Class for Polling Service
2
- class K2Polling
3
- include K2Validation, K2Utilities
4
- attr_reader :location_url, :k2_response_body
5
- attr_accessor :access_token
1
+ module K2ConnectRuby
2
+ module K2Entity
3
+ class K2Polling
4
+ include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
5
+ attr_reader :location_url, :k2_response_body
6
+ attr_accessor :access_token
6
7
 
7
- # Initialize with access token
8
- def initialize(access_token)
9
- raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
10
- @threads = []
11
- @access_token = access_token
12
- end
8
+ # Initialize with access token
9
+ def initialize(access_token)
10
+ raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
11
+ @access_token = access_token
12
+ end
13
13
 
14
- def poll(params)
15
- k2_request_body = {
16
- scope: params[:scope],
17
- scope_reference: params[:scope_reference],
18
- from_time: params[:from_time],
19
- to_time: params[:to_time],
20
- _links: { callback_url: params[:callback_url] }
21
- }
22
- poll_hash = make_hash(K2Config.path_url('poll'), 'post', @access_token,'Polling', k2_request_body)
23
- @location_url = K2Connect.make_request(poll_hash)
24
- end
14
+ def poll(params)
15
+ k2_request_body = {
16
+ scope: params[:scope],
17
+ scope_reference: params[:scope_reference],
18
+ from_time: params[:from_time],
19
+ to_time: params[:to_time],
20
+ _links: { callback_url: params[:callback_url] }
21
+ }
22
+ poll_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('poll'), 'post', @access_token,'Polling', k2_request_body)
23
+ @location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(poll_hash)
24
+ end
25
25
 
26
- # Retrieve your newly created polling request by its resource location
27
- def query_resource(location_url = @location_url)
28
- query_hash = make_hash(location_url, 'get', @access_token, 'Polling', nil)
29
- @threads << Thread.new do
30
- sleep 0.25
31
- @k2_response_body = K2Connect.make_request(query_hash)
32
- end
33
- @threads.each(&:join)
34
- end
26
+ # Retrieve your newly created polling request by its resource location
27
+ def query_resource(location_url = @location_url)
28
+ query_hash = make_hash(location_url, 'get', @access_token, 'Polling', nil)
29
+ @k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
30
+ end
35
31
 
36
- # Retrieve your newly created polling request by specific resource location
37
- def query_resource_url(url)
38
- query_resource(url)
32
+ # Retrieve your newly created polling request by specific resource location
33
+ def query_resource_url(url)
34
+ query_resource(url)
35
+ end
36
+ end
39
37
  end
40
38
  end