k2-connect-ruby 3.0.0 → 4.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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +31 -0
  3. data/.gitignore +2 -0
  4. data/Gemfile.lock +38 -5
  5. data/README.md +499 -198
  6. data/k2-connect-ruby.gemspec +39 -35
  7. data/lib/k2-connect-ruby/entity.rb +39 -9
  8. data/lib/k2-connect-ruby/http_client.rb +43 -0
  9. data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +12 -11
  10. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/destination_request.rb +27 -0
  11. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_bank_account.rb +32 -0
  12. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_mpesa_wallet.rb +38 -0
  13. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_paybill.rb +31 -0
  14. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_till.rb +30 -0
  15. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/merchant_bank_account.rb +27 -0
  16. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/merchant_mpesa_wallet.rb +27 -0
  17. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/bank_account.rb +17 -0
  18. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/mobile_wallet.rb +24 -0
  19. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/paybill.rb +17 -0
  20. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/recipient_request.rb +32 -0
  21. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/till.rb +17 -0
  22. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient.rb +54 -0
  23. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +14 -31
  24. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/payment_link.rb +53 -0
  25. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/payment_links/payment_link_request.rb +43 -0
  26. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/reversal.rb +39 -0
  27. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/reversals/reversal_request.rb +39 -0
  28. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/send_money/send_money_request.rb +53 -0
  29. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/send_money.rb +73 -0
  30. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/stk_push/stk_push_request.rb +51 -0
  31. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/merchant_bank_account.rb +35 -0
  32. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/merchant_mpesa_wallet.rb +38 -0
  33. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/transfer_account_request.rb +25 -0
  34. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account.rb +49 -0
  35. data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +16 -13
  36. data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +16 -14
  37. data/lib/k2-connect-ruby/k2_entity/k2_token.rb +14 -39
  38. data/lib/k2-connect-ruby/k2_entity/polling/polling_request.rb +48 -0
  39. data/lib/k2-connect-ruby/k2_entity/webhook/webhook_subscription_request.rb +66 -0
  40. data/lib/k2-connect-ruby/k2_errors.rb +15 -71
  41. data/lib/k2-connect-ruby/k2_services/base_service.rb +25 -0
  42. data/lib/k2-connect-ruby/k2_services/k2_client.rb +7 -6
  43. data/lib/k2-connect-ruby/k2_services/payloads/daraja_webhooks.rb +43 -0
  44. data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +20 -18
  45. data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +36 -32
  46. data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +31 -29
  47. data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +3 -1
  48. data/lib/k2-connect-ruby/k2_services/payloads/transactions/payment_link.rb +38 -0
  49. data/lib/k2-connect-ruby/k2_services/payloads/transactions/reversal.rb +35 -0
  50. data/lib/k2-connect-ruby/k2_services/payloads/transactions/send_money_payment.rb +25 -0
  51. data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +2 -0
  52. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +9 -3
  53. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_reversed.rb +22 -0
  54. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +6 -0
  55. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +4 -0
  56. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_received.rb +18 -0
  57. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_reversed.rb +17 -0
  58. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_voided.rb +17 -0
  59. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +11 -7
  60. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/transfer_webhook.rb +50 -0
  61. data/lib/k2-connect-ruby/k2_services/send_introspect_token_request_service.rb +56 -0
  62. data/lib/k2-connect-ruby/k2_services/send_k2_connect_get_request_service.rb +42 -0
  63. data/lib/k2-connect-ruby/k2_services/send_k2_connect_post_request_service.rb +44 -0
  64. data/lib/k2-connect-ruby/k2_services/send_request_token_request_service.rb +55 -0
  65. data/lib/k2-connect-ruby/k2_services/send_revoke_token_request_service.rb +56 -0
  66. data/lib/k2-connect-ruby/k2_services/send_token_info_request_service.rb +44 -0
  67. data/lib/k2-connect-ruby/k2_services.rb +29 -0
  68. data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +18 -26
  69. data/lib/k2-connect-ruby/k2_utilities/config/k2_config.yml +9 -10
  70. data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +12 -5
  71. data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +0 -48
  72. data/lib/k2-connect-ruby/k2_utilities/k2_connection_helper.rb +21 -0
  73. data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +16 -15
  74. data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +34 -21
  75. data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +3 -1
  76. data/lib/k2-connect-ruby/k2_utilities/phone_number_validator.rb +15 -0
  77. data/lib/k2-connect-ruby/k2_utilities.rb +9 -20
  78. data/lib/k2-connect-ruby/version.rb +1 -1
  79. data/lib/k2-connect-ruby.rb +14 -13
  80. metadata +119 -36
  81. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +0 -98
  82. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +0 -48
  83. data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +0 -44
  84. data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +0 -40
  85. data/lib/k2-connect-ruby/k2_services/payload_process.rb +0 -19
  86. data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +0 -44
  87. data/lib/k2-connect-ruby/k2_utilities/k2_validation.rb +0 -128
@@ -1,51 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module K2ConnectRuby
2
4
  module K2Utilities
3
5
  module Config
4
6
  module K2Config
5
- @config = YAML.load_file(File.join(File.dirname(__FILE__), 'k2_config.yml'), permitted_classes: [ActiveSupport::HashWithIndifferentAccess]).with_indifferent_access
7
+ @config = YAML.load_file(
8
+ File.join(File.dirname(__FILE__), "k2_config.yml"), permitted_classes: [ActiveSupport::HashWithIndifferentAccess]
9
+ ).with_indifferent_access
6
10
 
7
11
  class << self
8
12
  # Set the Host Url
9
- def set_base_url(base_url)
10
- raise ArgumentError, 'Invalid URL Format.' unless base_url =~ /\A#{URI.regexp(%w[http https])}\z/
13
+ def base_url=(base_url)
14
+ raise(ArgumentError, "Invalid URL Format.") unless base_url =~ /\A#{URI.regexp(["http", "https"])}\z/
15
+
11
16
  @config[:base_url] = base_url
12
- File.open(File.join(File.dirname(__FILE__), 'k2_config.yml'), 'w') { |f| YAML.dump(@config, f) }
17
+ File.open(File.join(File.dirname(__FILE__), "k2_config.yml"), "w") { |f| YAML.dump(@config, f) }
13
18
  end
14
19
 
15
- def set_version(version_number)
16
- raise ArgumentError, 'Invalid Format: Version Number input should be Numeric' unless version_number.is_a?(Numeric)
17
- @config[:version] = "v#{version_number}"
18
- File.open(File.join(File.dirname(__FILE__), 'k2_config.yml'), 'w') { |f| YAML.dump(@config, f) }
20
+ def base_url
21
+ @config[:base_url]
19
22
  end
20
23
 
21
- def version
22
- @config[:version]
24
+ def endpoints
25
+ @config[:endpoints]
23
26
  end
24
27
 
25
- def path_endpoint(key)
26
- unless key.include?('token')
27
- return "api/#{version}/#{@config[:endpoints][:"#{key}"]}"
28
- end
29
- @config[:endpoints][:"#{key}"]
28
+ def endpoint(key)
29
+ base_url + path(key)
30
30
  end
31
31
 
32
- def path_endpoints
33
- @config[:endpoints]
34
- end
32
+ def path(key)
33
+ return @config[:endpoints][:"#{key}"].to_s unless key.include?("token")
35
34
 
36
- def path_url(key)
37
- base_url + path_endpoint(key)
35
+ @config[:endpoints][:"#{key}"]
38
36
  end
39
37
 
40
38
  def network_operators
41
39
  @config[:network_operators]
42
40
  end
43
-
44
- private
45
-
46
- def base_url
47
- @config[:base_url]
48
- end
49
41
  end
50
42
 
51
43
  end
@@ -1,19 +1,18 @@
1
1
  --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
2
- version: v1
3
2
  base_url: https://sandbox.kopokopo.com/
4
3
  endpoints: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
5
4
  oauth_token: oauth/token
6
5
  revoke_token: oauth/revoke
7
6
  introspect_token: oauth/introspect
8
7
  token_info: oauth/token/info
9
- webhook_subscriptions: webhook_subscriptions
10
- pay_recipient: pay_recipients
11
- payments: payments
12
- incoming_payments: incoming_payments
13
- settlement_mobile_wallet: merchant_wallets
14
- settlement_bank_account: merchant_bank_accounts
15
- transfers: settlement_transfers
16
- poll: polling
17
- transaction_sms_notifications: transaction_sms_notifications
8
+ webhook_subscriptions: api/v2/webhook_subscriptions
9
+ external_recipient: api/v2/external_recipients
10
+ send_money: api/v2/send_money
11
+ incoming_payments: api/v2/incoming_payments
12
+ reversals: api/v2/reversals
13
+ payment_links: "/api/v2/payment_links"
14
+ settlement_mobile_wallet: api/v2/merchant_wallets
15
+ settlement_bank_account: api/v2/merchant_bank_accounts
16
+ poll: api/v2/polling
18
17
  network_operators:
19
18
  - SAFARICOM
@@ -1,5 +1,7 @@
1
- require 'openssl'
2
- require 'active_support/security_utils'
1
+ # frozen_string_literal: true
2
+
3
+ require "openssl"
4
+ require "active_support/security_utils"
3
5
 
4
6
  module K2ConnectRuby
5
7
  module K2Utilities
@@ -7,11 +9,16 @@ module K2ConnectRuby
7
9
  extend self
8
10
 
9
11
  def authenticate(body, api_secret_key, signature)
10
- raise ArgumentError, "Nil Authentication Argument!\n Check whether your Input is Empty" if body.blank? || api_secret_key.blank? || signature.blank?
12
+ if body.blank? || api_secret_key.blank? || signature.blank?
13
+ raise ArgumentError, "Nil Authentication Argument!\n Check whether your Input is Empty"
14
+ end
11
15
 
12
- digest = OpenSSL::Digest.new('sha256')
16
+ digest = OpenSSL::Digest.new("sha256")
13
17
  hmac = OpenSSL::HMAC.hexdigest(digest, api_secret_key, body.to_json)
14
- raise ArgumentError, "Invalid Details Given!\n Ensure that your the Arguments Given are correct, namely:\n\t- The Response Body\n\t- Secret Key\n\t- Signature" unless ActiveSupport::SecurityUtils.secure_compare(hmac, signature)
18
+ unless ActiveSupport::SecurityUtils.secure_compare(hmac, signature)
19
+ raise ArgumentError, "Invalid Details Given!\n Ensure that your the Arguments Given are correct, namely:\n\t- The Response Body\n\t- Secret Key\n\t- Signature"
20
+ end
21
+
15
22
  true
16
23
  end
17
24
  end
@@ -1,48 +0,0 @@
1
- module K2ConnectRuby
2
- module K2Utilities
3
- module K2Connection
4
- extend self
5
- # Method for sending the request to K2 sandbox or Mock Server
6
- def make_request(connection_hash)
7
- access_token = connection_hash[:access_token]
8
- class_type = connection_hash[:class_type]
9
- path_url = connection_hash[:path_url]
10
- request_type = connection_hash[:request_type]
11
- requires_token = connection_hash[:requires_token]
12
-
13
- unless class_type.eql?('Access Token') || access_token.present?
14
- raise ArgumentError, 'No Access Token in Arguments!'
15
- end
16
-
17
- # Set up Headers
18
- headers = if requires_token
19
- { 'Content-Type': 'application/json', Accept: 'application/json', Authorization: "Bearer #{access_token}" }
20
- else
21
- { 'Content-Type': 'application/json' }
22
- end
23
-
24
- k2_response = RestClient::Request.execute(
25
- method: request_type,
26
- url: path_url,
27
- headers: headers,
28
- payload: connection_hash[:params].to_json
29
- )
30
-
31
- # Response Body
32
- response_body = JSON.parse(k2_response.body, symbolize_names: true) if k2_response.body.present?
33
- response_headers = JSON.parse(k2_response.headers.to_json, symbolize_names: true)
34
- response_code = k2_response.code.to_s
35
- raise K2ConnectRuby::K2ConnectionError.new(response_code) unless response_code.starts_with?("2")
36
-
37
- if request_type.eql?('get')
38
- response_body
39
- else
40
- # Returns the access token for authorization
41
- return response_body[:access_token] if path_url.include?('oauth/token')
42
-
43
- response_headers[:location]
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module K2ConnectRuby
4
+ module K2Utilities
5
+ module K2ConnectionHelper
6
+ extend self
7
+
8
+ def rest_client_error(ex)
9
+ ex.response.present? ? JSON.parse(ex.response.body) : {}
10
+ end
11
+
12
+ def response_headers(headers)
13
+ headers.blank? ? {} : JSON.parse(headers.to_json, symbolize_names: true)
14
+ end
15
+
16
+ def response_body(body)
17
+ body.blank? ? {} : JSON.parse(body, symbolize_names: true)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,35 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module K2ConnectRuby
2
4
  module K2Utilities
3
5
  module K2ProcessResult
4
6
  extend self
5
7
 
6
8
  def process(payload, secret_key, signature)
7
- raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank?
9
+ raise ArgumentError, "Empty/Nil Request Body Argument!" if payload.blank?
10
+
8
11
  check_type(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature)
9
12
  end
10
13
 
11
14
  # Check the Event Type.
12
15
  def check_type(payload)
13
- result_type = payload.dig('data', 'type')
16
+ result_type = payload.dig("data", "type")
14
17
  case result_type
15
18
  # Incoming Payments
16
- when 'incoming_payment'
17
- incoming_payments = K2ConnectRuby::K2Services::Payloads::Transactions::IncomingPayment.new(payload)
18
- return incoming_payments
19
- # Outgoing Payments
20
- when 'payment'
21
- outgoing_payments = K2ConnectRuby::K2Services::Payloads::Transactions::OutgoingPayment.new(payload)
22
- return outgoing_payments
23
- when 'settlement_transfer'
24
- transfer = K2ConnectRuby::K2Services::Payloads::Transactions::Transfer.new(payload)
25
- return transfer
19
+ when "incoming_payment"
20
+ K2ConnectRuby::K2Services::Payloads::Transactions::IncomingPayment.new(payload)
21
+ when "send_money"
22
+ K2ConnectRuby::K2Services::Payloads::Transactions::SendMoneyPayment.new(payload)
23
+ when "reversal"
24
+ K2ConnectRuby::K2Services::Payloads::Transactions::Reversal.new(payload)
25
+ when "payment_link"
26
+ K2ConnectRuby::K2Services::Payloads::Transactions::PaymentLink.new(payload)
26
27
  else
27
- raise ArgumentError, 'No Other Specified Payment Type!'
28
+ raise ArgumentError, "No Other Specified Payment Type!"
28
29
  end
29
30
  end
30
31
 
31
32
  # Returns a Hash Object
32
- def return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj)
33
+ def return_obj_hash(obj, instance_hash = HashWithIndifferentAccess.new)
33
34
  obj.instance_variables.each do |value|
34
35
  instance_hash[:"#{value.to_s.tr('@', '')}"] = obj.instance_variable_get(value)
35
36
  end
@@ -37,7 +38,7 @@ module K2ConnectRuby
37
38
  end
38
39
 
39
40
  # Returns an Array Object
40
- def return_obj_array(instance_array = [], obj)
41
+ def return_obj_array(obj, instance_array = [])
41
42
  obj.instance_variables.each do |value|
42
43
  instance_array << obj.instance_variable_get(value)
43
44
  end
@@ -1,41 +1,54 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module K2ConnectRuby
2
4
  module K2Utilities
3
5
  module K2ProcessWebhook
4
6
  extend self
5
7
 
6
8
  def process(payload, secret_key, signature)
7
- raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank?
8
- check_topic(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature)
9
+ raise ArgumentError, "Empty/Nil Request Body Argument!" if payload.blank?
10
+
11
+ process_webhook(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature)
12
+ end
13
+
14
+ def process_webhook(payload)
15
+ if daraja_payload?(payload)
16
+ K2ConnectRuby::K2Services::Payloads::DarajaWebhooks.new(payload)
17
+ else
18
+ process_k2_connect_payload(payload)
19
+ end
9
20
  end
10
21
 
11
- def check_topic(payload)
12
- result_topic = payload.dig('topic')
22
+ def process_k2_connect_payload(payload)
23
+ result_topic = payload.dig("topic")
13
24
  case result_topic
14
25
  # Buygoods Transaction Received
15
- when 'buygoods_transaction_received'
16
- buygoods_received = K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReceived.new(payload)
17
- return buygoods_received
26
+ when "buygoods_transaction_received"
27
+ K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReceived.new(payload)
18
28
  # Buygoods Transaction Reversed
19
- when 'buygoods_transaction_reversed'
20
- buygoods_reversed = K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReversed.new(payload)
21
- return buygoods_reversed
22
- # B2b Transaction
23
- when 'b2b_transaction_received'
24
- b2b_transaction = K2ConnectRuby::K2Services::Payloads::Webhooks::B2bTransactionReceived.new(payload)
25
- return b2b_transaction
29
+ when "buygoods_transaction_reversed"
30
+ K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReversed.new(payload)
31
+ # B2B Transaction
32
+ when "b2b_transaction_received"
33
+ K2ConnectRuby::K2Services::Payloads::Webhooks::B2bTransactionReceived.new(payload)
34
+ # B2B Transaction Reversed
35
+ when "b2b_transaction_reversed"
36
+ K2ConnectRuby::K2Services::Payloads::Webhooks::B2bTransactionReversed.new(payload)
26
37
  # Settlement Transfer
27
- when 'settlement_transfer_completed'
28
- settlement_transfer = K2ConnectRuby::K2Services::Payloads::Webhooks::SettlementWebhook.new(payload)
29
- return settlement_transfer
38
+ when "settlement_transfer_completed"
39
+ K2ConnectRuby::K2Services::Payloads::Webhooks::TransferWebhook.new(payload)
30
40
  # Customer Created
31
- when 'customer_created'
32
- customer_created = K2ConnectRuby::K2Services::Payloads::Webhooks::CustomerCreated.new(payload)
33
- return customer_created
41
+ when "customer_created"
42
+ K2ConnectRuby::K2Services::Payloads::Webhooks::CustomerCreated.new(payload)
34
43
  else
35
- raise ArgumentError, 'No Other Specified Event!'
44
+ raise ArgumentError, "No Other Specified Event!"
36
45
  end
37
46
  end
38
47
 
48
+ def daraja_payload?(payload)
49
+ payload.key?("TransactionType")
50
+ end
51
+
39
52
  # Returns a Hash Object
40
53
  def return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj)
41
54
  obj.instance_variables.each do |value|
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module K2ConnectRuby
2
4
  module K2Utilities
3
5
  module K2UrlParse
4
6
  extend self
5
7
 
6
8
  def remove_localhost(url)
7
- url.host = '127.0.0.1' if url.host.eql?('localhost')
9
+ url.host = "127.0.0.1" if url.host.eql?("localhost")
8
10
  url
9
11
  end
10
12
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module K2ConnectRuby
4
+ module K2Utilities
5
+ class PhoneNumberValidator < ActiveModel::Validator
6
+ def validate(record)
7
+ phone_number = record.phone_number
8
+
9
+ record.errors.add(:phone_number, "is invalid.") if phone_number&.size == 13 && !phone_number&.starts_with?("+2547")
10
+ record.errors.add(:phone_number, "is invalid.") if phone_number&.size == 12 && !phone_number&.starts_with?("2547")
11
+ record.errors.add(:phone_number, "is invalid.") if phone_number&.size == 10 && !phone_number&.starts_with?("07")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,22 +1,11 @@
1
- require 'k2-connect-ruby/k2_utilities/k2_url_parse'
2
- require 'k2-connect-ruby/k2_utilities/k2_authenticator'
3
- require 'k2-connect-ruby/k2_utilities/k2_connection'
4
- require 'k2-connect-ruby/k2_utilities/k2_validation'
5
- require 'k2-connect-ruby/k2_utilities/config/k2_config'
6
- require 'k2-connect-ruby/k2_utilities/k2_process_result'
7
- require 'k2-connect-ruby/k2_utilities/k2_process_webhook'
1
+ require "k2-connect-ruby/k2_utilities/config/k2_config"
2
+ require "k2-connect-ruby/k2_utilities/k2_url_parse"
3
+ require "k2-connect-ruby/k2_utilities/k2_authenticator"
4
+ require "k2-connect-ruby/k2_utilities/k2_connection_helper"
5
+ require "k2-connect-ruby/k2_utilities/k2_process_result"
6
+ require "k2-connect-ruby/k2_utilities/k2_process_webhook"
7
+ require "k2-connect-ruby/k2_utilities/phone_number_validator"
8
8
 
9
9
  module K2ConnectRuby
10
- module K2Utilities
11
- def make_hash(path_url, request, access_token, class_type, body, requires_token = true)
12
- {
13
- path_url: path_url,
14
- access_token: access_token,
15
- request_type: request,
16
- requires_token: requires_token,
17
- class_type: class_type,
18
- params: body
19
- }.with_indifferent_access
20
- end
21
- end
22
- end
10
+ module K2Utilities; end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module K2ConnectRuby
2
- VERSION = "3.0.0"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -1,16 +1,17 @@
1
- require 'active_model'
2
- require 'active_support/json'
3
- require 'active_support/dependencies/autoload'
4
- require 'active_support/core_ext'
5
- require 'active_support/core_ext/hash/indifferent_access'
6
- require 'yaml'
7
- require 'rest-client'
8
- require 'json'
1
+ require "active_model"
2
+ require "active_support/json"
3
+ require "active_support/dependencies/autoload"
4
+ require "active_support/core_ext"
5
+ require "active_support/core_ext/hash/indifferent_access"
6
+ require "yaml"
7
+ require "rest-client"
8
+ require "json"
9
9
 
10
- require 'k2-connect-ruby/k2_utilities'
11
- require 'k2-connect-ruby/k2_services/payload_process'
12
- require 'k2-connect-ruby/entity'
13
- require 'k2-connect-ruby/k2_errors'
14
- require 'k2-connect-ruby/version'
10
+ require "k2-connect-ruby/k2_utilities"
11
+ require "k2-connect-ruby/k2_services"
12
+ require "k2-connect-ruby/entity"
13
+ require "k2-connect-ruby/k2_errors"
14
+ require "k2-connect-ruby/version"
15
+ require "k2-connect-ruby/http_client"
15
16
 
16
17
  module K2ConnectRuby; end