nequi 0.1.0 → 0.1.2
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/lib/nequi.rb +24 -36
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adfe516c81ff1c4430a521fc5697e16c052664956bdf2d157c6d7b0d02526aa2
|
4
|
+
data.tar.gz: ff85c2b1b6bc1cd7748ac8f62ab9c1a2d702c1b14d4f051fb7d8fa7bb3af15cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9b66de2efb9b1bedeee29bff7f433c63abc1adc7606665ca006adfce15f8d9cae87ac029e2f7c7faee762f2f6c741d00b1b4561dd56d343c413decef0e6042
|
7
|
+
data.tar.gz: 718a6028c356c1187b1978dd45f111307a2f0b5de7fb20dd95857feb3be4cf30b008c16440ec380536ac8273ba3b869c7a96ee31e3cc8194e8126ff880a01c94
|
data/lib/nequi.rb
CHANGED
@@ -7,6 +7,8 @@ module Nequi
|
|
7
7
|
require 'securerandom'
|
8
8
|
require 'httparty'
|
9
9
|
require 'base64'
|
10
|
+
require 'active_support/core_ext/integer/time'
|
11
|
+
|
10
12
|
include HTTParty
|
11
13
|
|
12
14
|
class << self
|
@@ -19,13 +21,8 @@ module Nequi
|
|
19
21
|
end
|
20
22
|
|
21
23
|
class Configuration
|
22
|
-
attr_accessor :auth_uri,
|
23
|
-
:
|
24
|
-
:client_id,
|
25
|
-
:client_secret,
|
26
|
-
:api_base_path,
|
27
|
-
:api_key,
|
28
|
-
:unregisteredpayment_endpoint
|
24
|
+
attr_accessor :auth_uri, :auth_grant_type, :unregisteredpayment_endpoint,
|
25
|
+
:client_id, :client_secret, :api_base_path, :api_key
|
29
26
|
end
|
30
27
|
|
31
28
|
NEQUI_STATUS_CODE_SUCCESS = '200'.freeze
|
@@ -42,24 +39,14 @@ module Nequi
|
|
42
39
|
|
43
40
|
body = { 'grant_type' => configuration.auth_grant_type }
|
44
41
|
|
45
|
-
response = HTTParty.post(configuration.
|
46
|
-
|
47
|
-
if response.code == 200 && !response.body.empty?
|
48
|
-
response_body = JSON.parse(response.body)
|
42
|
+
response = HTTParty.post(configuration.auth_uri, body: body, headers: headers)
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
expires_at: Time.now + 2.hours #response_body['expires_in'].to_i.seconds
|
54
|
-
}
|
55
|
-
|
56
|
-
else
|
57
|
-
raise "Failed to authenticate with Nequi. HTTP status code: #{response.code}"
|
58
|
-
end
|
59
|
-
@token
|
44
|
+
raise "Failed to authenticate with Nequi. HTTP status code: #{response.code}" unless (response.code == 200 && !response.body.empty?)
|
45
|
+
response_body = JSON.parse(response.body)
|
46
|
+
@token = { access_token: response_body['access_token'], token_type: response_body['token_type'], expires_at: Time.now + 2.hours }
|
60
47
|
end
|
61
48
|
|
62
|
-
def self.
|
49
|
+
def self.charge(amount, phone)
|
63
50
|
current_time = Time.now
|
64
51
|
formatted_timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S.%6N %z')
|
65
52
|
message_id = SecureRandom.uuid
|
@@ -97,30 +84,31 @@ module Nequi
|
|
97
84
|
}
|
98
85
|
}.to_json
|
99
86
|
|
100
|
-
logs = [{ 'type' => '
|
101
|
-
response = HTTParty.post(
|
102
|
-
"#{configuration.api_base_path + configuration.unregisteredpayment_endpoint}",
|
103
|
-
body: body,
|
104
|
-
headers: headers)
|
87
|
+
logs = [{ 'type' => 'information', 'message' => "Ready to send Petitions" }]
|
105
88
|
|
106
|
-
|
107
|
-
logs << { 'type' => 'info', 'msg' => "Petition returned HTTP 200" }
|
89
|
+
unregisteredpayment = configuration.api_base_path + configuration.unregisteredpayment_endpoint
|
108
90
|
|
109
|
-
|
110
|
-
|
91
|
+
response = HTTParty.post(unregisteredpayment, body: body, headers: headers)
|
92
|
+
|
93
|
+
response_body = JSON.parse(response.body)
|
111
94
|
|
112
|
-
|
95
|
+
if response.code.include?("200") && !response_body['ResponseMessage']['ResponseBody'].nil?
|
96
|
+
logs << { 'type' => 'information', 'message' => "Petition returned HTTP 200" }
|
97
|
+
|
98
|
+
begin
|
99
|
+
any_data = response_body['ResponseMessage']['ResponseBody']['any']
|
113
100
|
|
101
|
+
status = response_body['ResponseMessage']['ResponseHeader']['Status']
|
114
102
|
status_code = status ? status['StatusCode'] : ''
|
115
103
|
status_desc = status ? status['StatusDesc'] : ''
|
116
104
|
|
117
|
-
if status_code
|
118
|
-
logs << { 'type' => 'success', '
|
105
|
+
if status_code.include?('200')
|
106
|
+
logs << { 'type' => 'success', 'message' => 'Payment request send success fully' }
|
119
107
|
|
120
|
-
payment =
|
108
|
+
payment = any_data['unregisteredPaymentRS']
|
121
109
|
trn_id = payment ? payment['transactionId'].to_s.strip : ''
|
122
110
|
|
123
|
-
logs << { 'type' => 'success', '
|
111
|
+
logs << { 'type' => 'success', 'message' => 'Transaction Id: ' + trn_id }
|
124
112
|
else
|
125
113
|
raise 'Error ' + status_code + ' = ' + status_desc
|
126
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nequi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geocodinglife
|
@@ -58,6 +58,26 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '6.2'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.18'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.18.1
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.18'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.18.1
|
61
81
|
description: Nequi gem provides a convenient way to integrate with Nequi payments
|
62
82
|
systems for processing payments and other related operations.
|
63
83
|
email:
|