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.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +31 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +38 -5
- data/README.md +499 -198
- data/k2-connect-ruby.gemspec +39 -35
- data/lib/k2-connect-ruby/entity.rb +39 -9
- data/lib/k2-connect-ruby/http_client.rb +43 -0
- data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +12 -11
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/destination_request.rb +27 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_bank_account.rb +32 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_mpesa_wallet.rb +38 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_paybill.rb +31 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/external_till.rb +30 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/merchant_bank_account.rb +27 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/destination/merchant_mpesa_wallet.rb +27 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/bank_account.rb +17 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/mobile_wallet.rb +24 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/paybill.rb +17 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/recipient_request.rb +32 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient/till.rb +17 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/external_recipient.rb +54 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +14 -31
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/payment_link.rb +53 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/payment_links/payment_link_request.rb +43 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/reversal.rb +39 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/reversals/reversal_request.rb +39 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/send_money/send_money_request.rb +53 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/send_money.rb +73 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/stk_push/stk_push_request.rb +51 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/merchant_bank_account.rb +35 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/merchant_mpesa_wallet.rb +38 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account/transfer_account_request.rb +25 -0
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/transfer_account.rb +49 -0
- data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +16 -13
- data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +16 -14
- data/lib/k2-connect-ruby/k2_entity/k2_token.rb +14 -39
- data/lib/k2-connect-ruby/k2_entity/polling/polling_request.rb +48 -0
- data/lib/k2-connect-ruby/k2_entity/webhook/webhook_subscription_request.rb +66 -0
- data/lib/k2-connect-ruby/k2_errors.rb +15 -71
- data/lib/k2-connect-ruby/k2_services/base_service.rb +25 -0
- data/lib/k2-connect-ruby/k2_services/k2_client.rb +7 -6
- data/lib/k2-connect-ruby/k2_services/payloads/daraja_webhooks.rb +43 -0
- data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +20 -18
- data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +36 -32
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +31 -29
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +3 -1
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/payment_link.rb +38 -0
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/reversal.rb +35 -0
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/send_money_payment.rb +25 -0
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +2 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +9 -3
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_reversed.rb +22 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +6 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +4 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_received.rb +18 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_reversed.rb +17 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/card_transaction_voided.rb +17 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +11 -7
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/transfer_webhook.rb +50 -0
- data/lib/k2-connect-ruby/k2_services/send_introspect_token_request_service.rb +56 -0
- data/lib/k2-connect-ruby/k2_services/send_k2_connect_get_request_service.rb +42 -0
- data/lib/k2-connect-ruby/k2_services/send_k2_connect_post_request_service.rb +44 -0
- data/lib/k2-connect-ruby/k2_services/send_request_token_request_service.rb +55 -0
- data/lib/k2-connect-ruby/k2_services/send_revoke_token_request_service.rb +56 -0
- data/lib/k2-connect-ruby/k2_services/send_token_info_request_service.rb +44 -0
- data/lib/k2-connect-ruby/k2_services.rb +29 -0
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +18 -26
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.yml +9 -10
- data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +12 -5
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +0 -48
- data/lib/k2-connect-ruby/k2_utilities/k2_connection_helper.rb +21 -0
- data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +16 -15
- data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +34 -21
- data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +3 -1
- data/lib/k2-connect-ruby/k2_utilities/phone_number_validator.rb +15 -0
- data/lib/k2-connect-ruby/k2_utilities.rb +9 -20
- data/lib/k2-connect-ruby/version.rb +1 -1
- data/lib/k2-connect-ruby.rb +14 -13
- metadata +119 -36
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +0 -98
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +0 -48
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +0 -44
- data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +0 -40
- data/lib/k2-connect-ruby/k2_services/payload_process.rb +0 -19
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +0 -44
- 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(
|
|
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
|
|
10
|
-
raise
|
|
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__),
|
|
17
|
+
File.open(File.join(File.dirname(__FILE__), "k2_config.yml"), "w") { |f| YAML.dump(@config, f) }
|
|
13
18
|
end
|
|
14
19
|
|
|
15
|
-
def
|
|
16
|
-
|
|
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
|
|
22
|
-
@config[:
|
|
24
|
+
def endpoints
|
|
25
|
+
@config[:endpoints]
|
|
23
26
|
end
|
|
24
27
|
|
|
25
|
-
def
|
|
26
|
-
|
|
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
|
|
33
|
-
@config[:endpoints]
|
|
34
|
-
end
|
|
32
|
+
def path(key)
|
|
33
|
+
return @config[:endpoints][:"#{key}"].to_s unless key.include?("token")
|
|
35
34
|
|
|
36
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
incoming_payments: incoming_payments
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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(
|
|
16
|
+
digest = OpenSSL::Digest.new("sha256")
|
|
13
17
|
hmac = OpenSSL::HMAC.hexdigest(digest, api_secret_key, body.to_json)
|
|
14
|
-
|
|
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,
|
|
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(
|
|
16
|
+
result_type = payload.dig("data", "type")
|
|
14
17
|
case result_type
|
|
15
18
|
# Incoming Payments
|
|
16
|
-
when
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
when
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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,
|
|
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
|
|
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 = []
|
|
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,
|
|
8
|
-
|
|
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
|
|
12
|
-
result_topic = payload.dig(
|
|
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
|
|
16
|
-
|
|
17
|
-
return buygoods_received
|
|
26
|
+
when "buygoods_transaction_received"
|
|
27
|
+
K2ConnectRuby::K2Services::Payloads::Webhooks::BuygoodsTransactionReceived.new(payload)
|
|
18
28
|
# Buygoods Transaction Reversed
|
|
19
|
-
when
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
28
|
-
|
|
29
|
-
return settlement_transfer
|
|
38
|
+
when "settlement_transfer_completed"
|
|
39
|
+
K2ConnectRuby::K2Services::Payloads::Webhooks::TransferWebhook.new(payload)
|
|
30
40
|
# Customer Created
|
|
31
|
-
when
|
|
32
|
-
|
|
33
|
-
return customer_created
|
|
41
|
+
when "customer_created"
|
|
42
|
+
K2ConnectRuby::K2Services::Payloads::Webhooks::CustomerCreated.new(payload)
|
|
34
43
|
else
|
|
35
|
-
raise ArgumentError,
|
|
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 =
|
|
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
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
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
|
-
|
|
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
|
data/lib/k2-connect-ruby.rb
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
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
|
|
11
|
-
require
|
|
12
|
-
require
|
|
13
|
-
require
|
|
14
|
-
require
|
|
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
|