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,42 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Subscribe
|
4
|
+
include K2ConnectRuby::K2Utilities::K2Validation, K2ConnectRuby::K2Utilities
|
5
|
+
attr_reader :location_url, :k2_response_body
|
6
|
+
attr_accessor :access_token, :webhook_secret
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
# Implemented a Case condition that minimises repetition
|
15
|
+
def webhook_subscribe(params)
|
16
|
+
params = validate_webhook_input(params)
|
17
|
+
validate_webhook(params)
|
18
|
+
k2_request_body = {
|
19
|
+
event_type: params[:event_type],
|
20
|
+
url: params[:url],
|
21
|
+
scope: params[:scope],
|
22
|
+
scope_reference: params[:scope_reference]
|
23
|
+
}
|
24
|
+
subscribe_hash = make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('webhook_subscriptions'), 'post', @access_token,'Subscription', k2_request_body)
|
25
|
+
@location_url = K2ConnectRuby::K2Utilities::K2Connection.make_request(subscribe_hash)
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@k2_response_body = K2Connect.make_request(query_hash)
|
34
|
-
end
|
35
|
-
@threads.each(&:join)
|
36
|
-
end
|
28
|
+
# Query Recent Webhook
|
29
|
+
def query_webhook(location_url = @location_url)
|
30
|
+
query_hash = make_hash(location_url, 'get', @access_token, 'Subscription', nil)
|
31
|
+
@k2_response_body = K2ConnectRuby::K2Utilities::K2Connection.make_request(query_hash)
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
# Query Specific Webhook URL
|
35
|
+
def query_resource_url(url)
|
36
|
+
query_webhook(url)
|
37
|
+
end
|
38
|
+
end
|
41
39
|
end
|
42
40
|
end
|
@@ -1,63 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(client_id, client_secret)
|
6
|
-
validate_client_credentials(client_id, client_secret)
|
7
|
-
@client_id = client_id
|
8
|
-
@client_secret = client_secret
|
9
|
-
end
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Entity
|
3
|
+
class K2Token
|
4
|
+
attr_reader :access_token, :token_response
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
client_id
|
14
|
-
client_secret
|
15
|
-
|
16
|
-
}
|
17
|
-
token_hash = K2AccessToken.make_hash(K2Config.path_url('oauth_token'), 'post', 'Access Token', token_params)
|
18
|
-
@access_token = K2Connect.make_request(token_hash)
|
19
|
-
end
|
6
|
+
def initialize(client_id, client_secret)
|
7
|
+
validate_client_credentials(client_id, client_secret)
|
8
|
+
@client_id = client_id
|
9
|
+
@client_secret = client_secret
|
10
|
+
end
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
12
|
+
def request_token
|
13
|
+
token_params = {
|
14
|
+
client_id: @client_id,
|
15
|
+
client_secret: @client_secret,
|
16
|
+
grant_type: 'client_credentials'
|
17
|
+
}
|
18
|
+
token_hash = K2ConnectRuby::K2Entity::K2Token.make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('oauth_token'), 'post', 'Access Token', token_params)
|
19
|
+
@access_token = K2ConnectRuby::K2Utilities::K2Connection.make_request(token_hash)
|
20
|
+
end
|
30
21
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
def revoke_token(access_token)
|
23
|
+
token_params = {
|
24
|
+
client_id: @client_id,
|
25
|
+
client_secret: @client_secret,
|
26
|
+
token: access_token
|
27
|
+
}
|
28
|
+
token_hash = K2ConnectRuby::K2Entity::K2Token.make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('revoke_token'), 'post', 'Access Token', token_params)
|
29
|
+
@token_response = K2ConnectRuby::K2Utilities::K2Connection.make_request(token_hash)
|
30
|
+
end
|
40
31
|
|
41
|
-
|
42
|
-
|
32
|
+
def introspect_token(access_token)
|
33
|
+
token_params = {
|
34
|
+
client_id: @client_id,
|
35
|
+
client_secret: @client_secret,
|
36
|
+
token: access_token
|
37
|
+
}
|
38
|
+
token_hash = K2ConnectRuby::K2Entity::K2Token.make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('introspect_token'), 'post', 'Access Token', token_params)
|
39
|
+
@token_response = K2ConnectRuby::K2Utilities::K2Connection.make_request(token_hash)
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
42
|
+
def token_info(access_token)
|
43
|
+
token_hash = K2ConnectRuby::K2Entity::K2Token.make_hash(K2ConnectRuby::K2Utilities::Config::K2Config.path_url('token_info'), 'get', 'Access Token', nil, false)
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
token_hash[:access_token] = access_token
|
46
|
+
@token_response = K2ConnectRuby::K2Utilities::K2Connection.make_request(token_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_client_credentials(client_id, client_secret)
|
50
|
+
raise ArgumentError, 'Nil or Empty Client Id or Secret!' if client_id.blank? || client_secret.blank?
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
class << K2ConnectRuby::K2Entity::K2Token
|
54
|
+
# Create a Hash containing important details accessible for K2Connect
|
55
|
+
def make_hash(path_url, request, class_type, body, requires_token = true)
|
56
|
+
{
|
57
|
+
path_url: path_url,
|
58
|
+
request_type: request,
|
59
|
+
class_type: class_type,
|
60
|
+
requires_token: requires_token,
|
61
|
+
params: body
|
62
|
+
}.with_indifferent_access
|
63
|
+
end
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
|
-
end
|
67
|
+
end
|
@@ -1,77 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
# Standard K2Error
|
3
|
+
class K2Errors < StandardError
|
4
|
+
attr_reader :status, :message
|
5
|
+
def initialize(msg = @message)
|
6
|
+
super(msg)
|
7
|
+
end
|
6
8
|
end
|
7
|
-
end
|
8
9
|
|
9
|
-
# For errors concerning the Status code returned from Kopo Kopo
|
10
|
-
class K2ConnectionError < K2Errors
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
# For errors concerning the Status code returned from Kopo Kopo
|
11
|
+
class K2ConnectionError < K2Errors
|
12
|
+
def initialize(error)
|
13
|
+
@error = error
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
16
|
+
def message
|
17
|
+
case @error
|
18
|
+
when 400.to_s
|
19
|
+
STDERR.puts("Bad Request.\n\tYour request is Invalid")
|
20
|
+
when 401.to_s
|
21
|
+
STDERR.puts("Unauthorized.\n Your API key is wrong")
|
22
|
+
when 403.to_s
|
23
|
+
STDERR.puts("Forbidden.\n The resource requested cannot be accessed")
|
24
|
+
when 404.to_s
|
25
|
+
STDERR.puts("Not Found.\n\tThe specified resource could not be found")
|
26
|
+
when 405.to_s
|
27
|
+
STDERR.puts("Method Not Allowed.\n You tried to access a resource with an invalid method")
|
28
|
+
when 406.to_s
|
29
|
+
STDERR.puts("Not Acceptable.\n You requested a format that isn't valid json")
|
30
|
+
when 410.to_s
|
31
|
+
STDERR.puts("Gone.\n The resource requested has been moved")
|
32
|
+
when 429.to_s
|
33
|
+
STDERR.puts("Too Many Requests.\n Request threshold has been exceeded")
|
34
|
+
when 500.to_s
|
35
|
+
STDERR.puts("Internal Server Error.\n We had a problem with our server. Try again later")
|
36
|
+
when 503.to_s
|
37
|
+
STDERR.puts("Service Unavailable.\n We're temporarily offline for maintenance. Please try again later")
|
38
|
+
else
|
39
|
+
STDERR.puts("Undefined Kopo Kopo Server Response.")
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
|
-
end
|
42
43
|
|
43
|
-
# Errors concerning the Validation module
|
44
|
-
class K2ValidateErrors < K2Errors
|
45
|
-
|
44
|
+
# Errors concerning the Validation module
|
45
|
+
class K2ValidateErrors < K2Errors
|
46
|
+
attr_reader :the_keys
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def initialize(the_keys)
|
49
|
+
super
|
50
|
+
@the_keys = the_keys
|
51
|
+
@status = :bad_request
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def loop_keys
|
55
|
+
STDERR.puts @message
|
56
|
+
@the_keys.each(&method(:puts))
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
def message
|
60
|
+
loop_keys
|
61
|
+
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
# Hash / Params has Empty Values within it
|
64
|
-
class K2EmptyParams < K2ValidateErrors
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
# Hash / Params has Empty Values within it
|
65
|
+
class K2EmptyParams < K2ValidateErrors
|
66
|
+
def initialize(the_keys)
|
67
|
+
@message = "Invalid Hash Object!\n The Following Parameter(s) are Empty: "
|
68
|
+
super
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
# Error for Incorrect Hash Key Symbols (K2Entity validate => input)
|
72
|
-
class K2IncorrectParams < K2ValidateErrors
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
# Error for Incorrect Hash Key Symbols (K2Entity validate => input)
|
73
|
+
class K2IncorrectParams < K2ValidateErrors
|
74
|
+
def initialize(the_keys)
|
75
|
+
@message = "Incorrect Hash/Parameters Object!\n The Following Parameter(s) are Incorrect: "
|
76
|
+
super
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
class K2Client
|
4
|
+
attr_accessor :api_secret_key,
|
5
|
+
:hash_body,
|
6
|
+
:k2_signature
|
7
|
+
|
8
|
+
# Initialize method
|
9
|
+
def initialize(api_secret_key)
|
10
|
+
raise ArgumentError, 'No Secret Key Given!' if api_secret_key.blank?
|
11
|
+
@api_secret_key = api_secret_key
|
12
|
+
end
|
13
|
+
|
14
|
+
# Method for parsing the Entire Request. Come back to it later to trim. L8r call it set_client_variables
|
15
|
+
def parse_request(the_request)
|
16
|
+
raise ArgumentError, 'Nil Request Parameter Input!' if the_request.blank?
|
17
|
+
|
18
|
+
# The Response Body.
|
19
|
+
@hash_body = JSON.parse(the_request.body.read)
|
20
|
+
# The Response Header
|
21
|
+
hash_header = JSON.parse(the_request.env.select { |k, _| k =~ /^HTTP_/ }.to_json)
|
22
|
+
# The K2 Signature
|
23
|
+
@k2_signature = hash_header['HTTP_X_KOPOKOPO_SIGNATURE']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,14 +1,19 @@
|
|
1
|
-
require 'k2-connect-ruby/k2_services/
|
1
|
+
require 'k2-connect-ruby/k2_services/k2_client'
|
2
2
|
|
3
3
|
require 'k2-connect-ruby/k2_services/payloads/k2_webhooks'
|
4
|
-
require 'k2-connect-ruby/k2_services/payloads/webhooks/
|
5
|
-
require 'k2-connect-ruby/k2_services/payloads/webhooks/m2m_transaction'
|
4
|
+
require 'k2-connect-ruby/k2_services/payloads/webhooks/b2b_transaction_received'
|
6
5
|
require 'k2-connect-ruby/k2_services/payloads/webhooks/customer_created'
|
7
|
-
require 'k2-connect-ruby/k2_services/payloads/webhooks/
|
8
|
-
require 'k2-connect-ruby/k2_services/payloads/webhooks/
|
6
|
+
require 'k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_received'
|
7
|
+
require 'k2-connect-ruby/k2_services/payloads/webhooks/buygoods_transaction_reversed'
|
9
8
|
require 'k2-connect-ruby/k2_services/payloads/webhooks/settlement_webhook'
|
10
9
|
|
11
10
|
require 'k2-connect-ruby/k2_services/payloads/k2_transaction'
|
12
11
|
require 'k2-connect-ruby/k2_services/payloads/transactions/transfer'
|
13
12
|
require 'k2-connect-ruby/k2_services/payloads/transactions/incoming_payment'
|
14
13
|
require 'k2-connect-ruby/k2_services/payloads/transactions/outgoing_payment'
|
14
|
+
|
15
|
+
module K2ConnectRuby
|
16
|
+
module K2Services
|
17
|
+
module PayloadProcess; end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,48 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
class K2Transaction
|
5
|
+
attr_reader :id,
|
6
|
+
:type,
|
7
|
+
:metadata,
|
8
|
+
:links_self,
|
9
|
+
:callback_url
|
10
|
+
|
11
|
+
def initialize(payload)
|
12
|
+
@id = payload.dig('data', 'id')
|
13
|
+
@type = payload.dig('data', 'type')
|
14
|
+
@metadata = payload.dig('data', 'attributes', 'metadata')
|
15
|
+
@links_self = payload.dig('data', 'attributes', '_links', 'self')
|
16
|
+
@callback_url = payload.dig('data', 'attributes', '_links', 'callback_url')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class CommonPayment < K2Transaction
|
21
|
+
include ActiveModel::Validations
|
22
|
+
|
23
|
+
attr_reader :status,
|
24
|
+
:initiation_time
|
25
|
+
|
26
|
+
validate :valid_payment_type
|
27
|
+
|
28
|
+
def initialize(payload)
|
29
|
+
super
|
30
|
+
@status = payload.dig('data', 'attributes', 'status')
|
31
|
+
@initiation_time = payload.dig('data', 'attributes', 'initiation_time') if @type.eql?('incoming_payment')
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def valid_payment_type; end
|
37
|
+
end
|
38
|
+
|
39
|
+
class OutgoingTransaction < CommonPayment
|
40
|
+
attr_reader :created_at,
|
41
|
+
:transfer_batches,
|
42
|
+
:total_value
|
43
|
+
|
44
|
+
def initialize(payload)
|
45
|
+
super
|
46
|
+
@created_at = payload.dig('data', 'attributes', 'created_at')
|
47
|
+
@currency = payload.dig('data', 'attributes', 'amount', 'currency')
|
48
|
+
@total_value = payload.dig('data', 'attributes', 'amount', 'value')
|
49
|
+
@transfer_batches = payload.dig('data', 'attributes', 'transfer_batches')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
14
53
|
end
|
15
54
|
end
|
16
|
-
|
17
|
-
class CommonPayment < K2Transaction
|
18
|
-
include ActiveModel::Validations
|
19
|
-
|
20
|
-
attr_reader :status,
|
21
|
-
:initiation_time
|
22
|
-
|
23
|
-
validate :valid_payment_type
|
24
|
-
|
25
|
-
def initialize(payload)
|
26
|
-
super
|
27
|
-
@status = payload.dig('data', 'attributes', 'status')
|
28
|
-
@initiation_time = payload.dig('data', 'attributes', 'initiation_time') if @type.eql?('incoming_payment')
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def valid_payment_type; end
|
34
|
-
end
|
35
|
-
|
36
|
-
class OutgoingTransaction < CommonPayment
|
37
|
-
attr_reader :created_at,
|
38
|
-
:transfer_batches,
|
39
|
-
:total_value
|
40
|
-
|
41
|
-
def initialize(payload)
|
42
|
-
super
|
43
|
-
@created_at = payload.dig('data', 'attributes', 'created_at')
|
44
|
-
@currency = payload.dig('data', 'attributes', 'amount', 'currency')
|
45
|
-
@total_value = payload.dig('data', 'attributes', 'amount', 'value')
|
46
|
-
@transfer_batches = payload.dig('data', 'attributes', 'transfer_batches')
|
47
|
-
end
|
48
|
-
end
|
@@ -1,59 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module K2ConnectRuby
|
2
|
+
module K2Services
|
3
|
+
module Payloads
|
4
|
+
class K2Webhooks
|
5
|
+
attr_reader :id,
|
6
|
+
:topic,
|
7
|
+
:created_at,
|
8
|
+
:links_self,
|
9
|
+
:event_type,
|
10
|
+
:links_resource,
|
11
|
+
:event_resource,
|
12
|
+
:resource_id
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
14
|
+
def initialize(payload)
|
15
|
+
@id = payload.dig('id')
|
16
|
+
@topic = payload.dig('topic')
|
17
|
+
@created_at = payload.dig('created_at')
|
18
|
+
# Event
|
19
|
+
@event_type = payload.dig('event', 'type')
|
20
|
+
@resource_id = payload.dig('event', 'resource', 'id') unless @event_type.eql?('Customer Created')
|
21
|
+
# Links
|
22
|
+
@links_self = payload.dig('_links', 'self')
|
23
|
+
@links_resource = payload.dig('_links', 'resource')
|
24
|
+
end
|
25
|
+
end
|
23
26
|
|
24
|
-
class K2CommonEvents <
|
25
|
-
|
27
|
+
class K2CommonEvents < K2Webhooks
|
28
|
+
REFERENCE_EXCEPTIONS = ["Merchant to Merchant Transaction", "Settlement Transfer"]
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
attr_reader :reference,
|
31
|
+
:origination_time,
|
32
|
+
:amount,
|
33
|
+
:currency,
|
34
|
+
:status
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def initialize(payload)
|
37
|
+
super
|
38
|
+
@reference = payload.dig('event', 'resource', 'reference') unless REFERENCE_EXCEPTIONS.include?(@event_type)
|
39
|
+
@origination_time = payload.dig('event', 'resource', 'origination_time')
|
40
|
+
@amount = payload.dig('event', 'resource', 'amount')
|
41
|
+
@currency = payload.dig('event', 'resource', 'currency')
|
42
|
+
@status = payload.dig('event', 'resource', 'status')
|
43
|
+
end
|
41
44
|
|
42
|
-
end
|
45
|
+
end
|
43
46
|
|
44
|
-
class Buygoods < K2CommonEvents
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
class Buygoods < K2CommonEvents
|
48
|
+
attr_reader :system,
|
49
|
+
:till_number,
|
50
|
+
:sender_phone_number,
|
51
|
+
:sender_first_name,
|
52
|
+
:sender_last_name
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def initialize(payload)
|
55
|
+
super
|
56
|
+
@system = payload.dig('event', 'resource', 'system')
|
57
|
+
@till_number = payload.dig('event', 'resource', 'till_number')
|
58
|
+
@sender_phone_number = payload.dig('event', 'resource', 'sender_phone_number')
|
59
|
+
@sender_first_name = payload.dig('event', 'resource', 'sender_first_name')
|
60
|
+
@sender_last_name = payload.dig('event', 'resource', 'sender_last_name')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
58
64
|
end
|
59
|
-
end
|
65
|
+
end
|