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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +78 -64
- data/README.md +70 -49
- data/k2-connect-ruby.gemspec +12 -11
- data/lib/k2-connect-ruby/{k2_entity/entity.rb → entity.rb} +5 -0
- data/lib/k2-connect-ruby/k2_entity/k2_entity.rb +24 -26
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_pay.rb +92 -98
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_settlement.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_stk.rb +43 -44
- data/lib/k2-connect-ruby/k2_entity/k2_financial_entities/k2_transfer.rb +35 -36
- data/lib/k2-connect-ruby/k2_entity/k2_notification.rb +34 -35
- data/lib/k2-connect-ruby/k2_entity/k2_polling.rb +32 -34
- data/lib/k2-connect-ruby/k2_entity/k2_subscribe.rb +34 -36
- data/lib/k2-connect-ruby/k2_entity/k2_token.rb +58 -54
- data/lib/k2-connect-ruby/k2_errors.rb +64 -62
- data/lib/k2-connect-ruby/k2_services/k2_client.rb +27 -0
- data/lib/k2-connect-ruby/k2_services/payload_process.rb +10 -5
- data/lib/k2-connect-ruby/k2_services/payloads/k2_transaction.rb +52 -46
- data/lib/k2-connect-ruby/k2_services/payloads/k2_webhooks.rb +57 -51
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/incoming_payment.rb +50 -42
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment.rb +19 -11
- data/lib/k2-connect-ruby/k2_services/payloads/transactions/transfer.rb +16 -8
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received.rb +18 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed.rb +13 -0
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/customer_created.rb +20 -12
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook.rb +40 -32
- data/lib/k2-connect-ruby/k2_utilities/config/k2_config.rb +49 -46
- data/lib/k2-connect-ruby/k2_utilities/k2_authenticator.rb +19 -0
- data/lib/k2-connect-ruby/k2_utilities/k2_connection.rb +39 -32
- data/lib/k2-connect-ruby/k2_utilities/k2_process_result.rb +42 -37
- data/lib/k2-connect-ruby/k2_utilities/k2_process_webhook.rb +51 -50
- data/lib/k2-connect-ruby/k2_utilities/k2_url_parse.rb +11 -6
- data/lib/k2-connect-ruby/k2_utilities/k2_validation.rb +104 -102
- data/lib/k2-connect-ruby/{utilities.rb → k2_utilities.rb} +8 -8
- data/lib/k2-connect-ruby/version.rb +1 -1
- data/lib/k2-connect-ruby.rb +7 -25
- metadata +56 -43
- data/lib/k2-connect-ruby/k2_services/client/k2_client.rb +0 -24
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/b2b_received.rb +0 -10
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_received.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/buygoods_reversal.rb +0 -5
- data/lib/k2-connect-ruby/k2_services/payloads/webhooks/m2m_transaction.rb +0 -8
- data/lib/k2-connect-ruby/k2_utilities/k2_authorize.rb +0 -14
- data/lib/k2-connect-ruby/k2_utilities/spec_modules/spec_config.rb +0 -41
@@ -1,46 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Transactions
|
5
|
+
class IncomingPayment < CommonPayment
|
6
|
+
attr_reader :event,
|
7
|
+
:event_type,
|
8
|
+
:transaction_reference,
|
9
|
+
:origination_time,
|
10
|
+
:sender_phone_number,
|
11
|
+
:amount,
|
12
|
+
:currency,
|
13
|
+
:till_number,
|
14
|
+
:system,
|
15
|
+
:resource_id,
|
16
|
+
:resource_status,
|
17
|
+
:sender_first_name,
|
18
|
+
:sender_middle_name,
|
19
|
+
:sender_last_name,
|
20
|
+
:errors
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
22
|
+
def initialize(payload)
|
23
|
+
super
|
24
|
+
# Event details
|
25
|
+
@event = payload.dig('data', 'attributes', 'event')
|
26
|
+
@event_type = payload.dig('data', 'attributes', 'event', 'type')
|
27
|
+
# Resource details
|
28
|
+
@resource_id = payload.dig('data', 'attributes', 'event', 'resource', 'id')
|
29
|
+
@transaction_reference = payload.dig('data', 'attributes', 'event', 'resource', 'reference')
|
30
|
+
@origination_time = payload.dig('data', 'attributes', 'event', 'resource', 'origination_time')
|
31
|
+
@sender_phone_number = payload.dig('data', 'attributes', 'event', 'resource', 'sender_phone_number')
|
32
|
+
@amount = payload.dig('data', 'attributes', 'event', 'resource', 'amount')
|
33
|
+
@currency = payload.dig('data', 'attributes', 'event', 'resource', 'currency')
|
34
|
+
@till_number = payload.dig('data', 'attributes', 'event', 'resource', 'till_number')
|
35
|
+
@system = payload.dig('data', 'attributes', 'event', 'resource', 'system')
|
36
|
+
@resource_status = payload.dig('data', 'attributes', 'event', 'resource', 'status')
|
37
|
+
@sender_first_name = payload.dig('data', 'attributes', 'event', 'resource', 'sender_first_name')
|
38
|
+
@sender_middle_name = payload.dig('data', 'attributes', 'event', 'resource', 'sender_middle_name')
|
39
|
+
@sender_last_name = payload.dig('data', 'attributes', 'event', 'resource', 'sender_last_name')
|
40
|
+
# Errors
|
41
|
+
@errors = payload.dig('data', 'attributes', 'event', 'errors')
|
42
|
+
end
|
39
43
|
|
40
|
-
|
44
|
+
private
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
def valid_payment_type
|
47
|
+
raise ArgumentError, "Wrong Payment Type" unless @type.eql?("incoming_payment")
|
48
|
+
end
|
45
49
|
|
46
|
-
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,15 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Transactions
|
5
|
+
class OutgoingPayment < OutgoingTransaction
|
6
|
+
attr_reader :transaction_reference,
|
7
|
+
:destination
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
def initialize(payload)
|
10
|
+
super
|
11
|
+
end
|
8
12
|
|
9
|
-
|
13
|
+
private
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
def valid_payment_type
|
16
|
+
raise ArgumentError, "Wrong Payment Type" unless @type.eql?("payment")
|
17
|
+
end
|
14
18
|
|
15
|
-
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,12 +1,20 @@
|
|
1
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Transactions
|
5
|
+
class Transfer < OutgoingTransaction
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
7
|
+
def initialize(payload)
|
8
|
+
super
|
9
|
+
end
|
6
10
|
|
7
|
-
|
11
|
+
private
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
def valid_payment_type
|
14
|
+
raise ArgumentError, "Wrong Payment Type" unless @type.eql?("settlement_transfer")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
|
-
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Webhooks
|
5
|
+
class B2bTransactionReceived < K2CommonEvents
|
6
|
+
attr_reader :sending_till,
|
7
|
+
:till_number
|
8
|
+
|
9
|
+
def initialize(payload)
|
10
|
+
super
|
11
|
+
@till_number = payload.dig('event', 'resource', 'till_number')
|
12
|
+
@sending_till = payload.dig('event', 'resource', 'sending_till')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Webhooks
|
5
|
+
class CustomerCreated < K2Webhooks
|
6
|
+
attr_reader :resource_first_name,
|
7
|
+
:resource_middle_name,
|
8
|
+
:resource_last_name,
|
9
|
+
:resource_phone_number
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def initialize(payload)
|
12
|
+
super
|
13
|
+
@resource_first_name = payload.dig('event', 'resource', 'first_name')
|
14
|
+
@resource_middle_name = payload.dig('event', 'resource', 'middle_name')
|
15
|
+
@resource_last_name = payload.dig('event', 'resource', 'last_name')
|
16
|
+
@resource_phone_number = payload.dig('event', 'resource', 'phone_number')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
13
21
|
end
|
14
|
-
end
|
22
|
+
end
|
@@ -1,36 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
module Webhooks
|
5
|
+
class SettlementWebhook < K2CommonEvents
|
6
|
+
attr_reader :disbursements,
|
7
|
+
:destination_type,
|
8
|
+
:destination_network,
|
9
|
+
:destination_reference,
|
10
|
+
:destination_last_name,
|
11
|
+
:destination_first_name,
|
12
|
+
:destination_account_name,
|
13
|
+
:destination_phone_number,
|
14
|
+
:destination_account_number,
|
15
|
+
:destination_bank_branch_ref,
|
16
|
+
:destination_settlement_method
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def initialize(payload)
|
19
|
+
super
|
20
|
+
# Destination
|
21
|
+
@disbursements = payload.dig('event', 'resource', 'disbursements')
|
22
|
+
@destination_type = payload.dig('event', 'resource', 'destination', 'type')
|
23
|
+
@destination_reference = payload.dig('event', 'resource', 'destination', 'resource', 'reference')
|
24
|
+
destination_assets(payload)
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def destination_assets(payload)
|
28
|
+
if @destination_type.eql?('Mobile Wallet')
|
29
|
+
@destination_network = payload.dig('event', 'resource', 'destination', 'resource', 'network')
|
30
|
+
@destination_last_name = payload.dig('event', 'resource', 'destination', 'resource', 'last_name')
|
31
|
+
@destination_first_name = payload.dig('event', 'resource', 'destination', 'resource', 'first_name')
|
32
|
+
@destination_phone_number = payload.dig('event', 'resource', 'destination', 'resource', 'phone_number')
|
33
|
+
elsif @destination_type.eql?('Bank Account')
|
34
|
+
@destination_account_name = payload.dig('event', 'resource', 'destination', 'resource', 'account_name')
|
35
|
+
@destination_account_number = payload.dig('event', 'resource', 'destination', 'resource', 'account_number')
|
36
|
+
@destination_bank_branch_ref = payload.dig('event', 'resource', 'destination', 'resource', 'bank_branch_ref')
|
37
|
+
@destination_settlement_method = payload.dig('event', 'resource', 'destination', 'resource', 'settlement_method')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
36
|
-
end
|
44
|
+
end
|
@@ -1,51 +1,54 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Utilities
|
3
|
+
module Config
|
4
|
+
module K2Config
|
5
|
+
@config = YAML.load_file(File.join(File.dirname(__FILE__), 'k2_config.yml'), permitted_classes: [ActiveSupport::HashWithIndifferentAccess]).with_indifferent_access
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# 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/
|
11
|
+
@config[:base_url] = base_url
|
12
|
+
File.open(File.join(File.dirname(__FILE__), 'k2_config.yml'), 'w') { |f| YAML.dump(@config, f) }
|
13
|
+
end
|
14
|
+
|
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) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def version
|
22
|
+
@config[:version]
|
23
|
+
end
|
24
|
+
|
25
|
+
def path_endpoint(key)
|
26
|
+
unless key.include?('token')
|
27
|
+
return "api/#{version}/#{@config[:endpoints][:"#{key}"]}"
|
28
|
+
end
|
29
|
+
@config[:endpoints][:"#{key}"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def path_endpoints
|
33
|
+
@config[:endpoints]
|
34
|
+
end
|
35
|
+
|
36
|
+
def path_url(key)
|
37
|
+
base_url + path_endpoint(key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def network_operators
|
41
|
+
@config[:network_operators]
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def base_url
|
47
|
+
@config[:base_url]
|
48
|
+
end
|
49
|
+
end
|
23
50
|
|
24
|
-
def path_endpoint(key)
|
25
|
-
unless key.include?('token')
|
26
|
-
return "api/#{version}/#{@config[:endpoints][:"#{key}"]}"
|
27
51
|
end
|
28
|
-
@config[:endpoints][:"#{key}"]
|
29
|
-
end
|
30
|
-
|
31
|
-
def path_endpoints
|
32
|
-
@config[:endpoints]
|
33
|
-
end
|
34
|
-
|
35
|
-
def path_url(key)
|
36
|
-
# TODO: Custom error/exception message
|
37
|
-
base_url + path_endpoint(key)
|
38
|
-
end
|
39
|
-
|
40
|
-
def network_operators
|
41
|
-
@config[:network_operators]
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def base_url
|
47
|
-
@config[:base_url]
|
48
52
|
end
|
49
53
|
end
|
50
|
-
|
51
54
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'active_support/security_utils'
|
3
|
+
|
4
|
+
module K2ConnectRuby
|
5
|
+
module K2Utilities
|
6
|
+
module K2Authenticator
|
7
|
+
extend self
|
8
|
+
|
9
|
+
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?
|
11
|
+
|
12
|
+
digest = OpenSSL::Digest.new('sha256')
|
13
|
+
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)
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,41 +1,48 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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]
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
13
|
+
unless class_type.eql?('Access Token') || access_token.present?
|
14
|
+
raise ArgumentError, 'No Access Token in Arguments!'
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
headers = { 'Content-Type': 'application/json' }
|
20
|
-
end
|
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
|
21
23
|
|
22
|
-
|
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
|
+
)
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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")
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
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')
|
33
42
|
|
34
|
-
|
35
|
-
|
43
|
+
response_headers[:location]
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
37
|
-
|
38
|
-
# Return the result of the Query
|
39
|
-
return response_body
|
40
47
|
end
|
41
48
|
end
|
@@ -1,43 +1,48 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
self.check_type(payload) if K2Authenticator.authenticate(payload, secret_key, signature)
|
6
|
-
end
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Utilities
|
3
|
+
module K2ProcessResult
|
4
|
+
extend self
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Incoming Payments
|
13
|
-
when 'incoming_payment'
|
14
|
-
incoming_payments = IncomingPayments.new(payload)
|
15
|
-
return incoming_payments
|
16
|
-
# Outgoing Payments
|
17
|
-
when 'payment'
|
18
|
-
outgoing_payments = OutgoingPayment.new(payload)
|
19
|
-
return outgoing_payments
|
20
|
-
when 'settlement_transfer'
|
21
|
-
transfer = Transfer.new(payload)
|
22
|
-
return transfer
|
23
|
-
else
|
24
|
-
raise ArgumentError, 'No Other Specified Payment Type!'
|
25
|
-
end
|
26
|
-
end
|
6
|
+
def process(payload, secret_key, signature)
|
7
|
+
raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank?
|
8
|
+
check_type(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature)
|
9
|
+
end
|
27
10
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
11
|
+
# Check the Event Type.
|
12
|
+
def check_type(payload)
|
13
|
+
result_type = payload.dig('data', 'type')
|
14
|
+
case result_type
|
15
|
+
# 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
|
26
|
+
else
|
27
|
+
raise ArgumentError, 'No Other Specified Payment Type!'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns a Hash Object
|
32
|
+
def return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj)
|
33
|
+
obj.instance_variables.each do |value|
|
34
|
+
instance_hash[:"#{value.to_s.tr('@', '')}"] = obj.instance_variable_get(value)
|
35
|
+
end
|
36
|
+
instance_hash.each(&:freeze).freeze
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
# Returns an Array Object
|
40
|
+
def return_obj_array(instance_array = [], obj)
|
41
|
+
obj.instance_variables.each do |value|
|
42
|
+
instance_array << obj.instance_variable_get(value)
|
43
|
+
end
|
44
|
+
instance_array.each(&:freeze).freeze
|
45
|
+
end
|
40
46
|
end
|
41
|
-
instance_array.each(&:freeze).freeze
|
42
47
|
end
|
43
48
|
end
|