nequi 0.1.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 +7 -0
- data/lib/nequi/version.rb +5 -0
- data/lib/nequi.rb +137 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80c402009a6d5aebd975b4bc279d3baf931e5c5a8cbf1d8f130256bcf0814d02
|
4
|
+
data.tar.gz: 45208682a9bd6de66902de08330597e0a4f78a01c67877e1a12aa346692b4156
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0a90fec403f52b0e1e05589ab82e084fdca818830642c6b8a25b5ee7e778e17a40f24e8ce70109673572334abe6f8941a00a76a7750b02df1be09635fe26e4e
|
7
|
+
data.tar.gz: 6ed35c9a6ea740bc0b39271ceebdc0e4a2daae7c97b37ad67df742baee6138fcf65192dd02b0b88e9ea89b07477ff1ffaefa8fbc98a02bb100e02c041e8b2948
|
data/lib/nequi.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "nequi/version"
|
4
|
+
|
5
|
+
module Nequi
|
6
|
+
class Error < StandardError; end
|
7
|
+
require 'securerandom'
|
8
|
+
require 'httparty'
|
9
|
+
require 'base64'
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
self.configuration ||= Configuration.new
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
class Configuration
|
22
|
+
attr_accessor :auth_uri,
|
23
|
+
:auth_grant_type,
|
24
|
+
:client_id,
|
25
|
+
:client_secret,
|
26
|
+
:api_base_path,
|
27
|
+
:api_key,
|
28
|
+
:unregisteredpayment_endpoint
|
29
|
+
end
|
30
|
+
|
31
|
+
NEQUI_STATUS_CODE_SUCCESS = '200'.freeze
|
32
|
+
format :json
|
33
|
+
|
34
|
+
def self.get_token
|
35
|
+
return @token if @token
|
36
|
+
|
37
|
+
headers = {
|
38
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
39
|
+
'Accept' => 'application/json',
|
40
|
+
'Authorization' => "Basic #{Base64.strict_encode64("#{configuration.client_id}:#{configuration.client_secret}")}"
|
41
|
+
}
|
42
|
+
|
43
|
+
body = { 'grant_type' => configuration.auth_grant_type }
|
44
|
+
|
45
|
+
response = HTTParty.post(configuration.auth_url, body: body, headers: headers)
|
46
|
+
|
47
|
+
if response.code == 200 && !response.body.empty?
|
48
|
+
response_body = JSON.parse(response.body)
|
49
|
+
|
50
|
+
@token = {
|
51
|
+
access_token: response_body['access_token'],
|
52
|
+
token_type: response_body['token_type'],
|
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
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.call(amount, phone)
|
63
|
+
current_time = Time.now
|
64
|
+
formatted_timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S.%6N %z')
|
65
|
+
message_id = SecureRandom.uuid
|
66
|
+
|
67
|
+
headers = {
|
68
|
+
'Content-Type' => 'application/json',
|
69
|
+
'Accept' => 'application/json',
|
70
|
+
'Authorization' => "Bearer #{get_token[:access_token]}",
|
71
|
+
'x-api-key' => configuration.api_key
|
72
|
+
}
|
73
|
+
|
74
|
+
body = {
|
75
|
+
"RequestMessage" => {
|
76
|
+
"RequestHeader" => {
|
77
|
+
"Channel" => "PNP04-C001",
|
78
|
+
"RequestDate" => formatted_timestamp,
|
79
|
+
"MessageID" => message_id,
|
80
|
+
"ClientID" => configuration.client_id,
|
81
|
+
"Destination" => {
|
82
|
+
"ServiceName" => "PaymentsService",
|
83
|
+
"ServiceOperation" => "unregisteredPayment",
|
84
|
+
"ServiceRegion" => "C001",
|
85
|
+
"ServiceVersion" => "1.2.0"
|
86
|
+
}
|
87
|
+
},
|
88
|
+
"RequestBody" => {
|
89
|
+
"any" => {
|
90
|
+
"unregisteredPaymentRQ" => {
|
91
|
+
"phoneNumber" => "#{phone}",
|
92
|
+
"code" => "NIT_1",
|
93
|
+
"value" => "#{amount}"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}.to_json
|
99
|
+
|
100
|
+
logs = [{ 'type' => 'info', 'msg' => "Ready to send Petitions" }]
|
101
|
+
response = HTTParty.post(
|
102
|
+
"#{configuration.api_base_path + configuration.unregisteredpayment_endpoint}",
|
103
|
+
body: body,
|
104
|
+
headers: headers)
|
105
|
+
|
106
|
+
if response.code.to_i == 200 && !response.body.empty?
|
107
|
+
logs << { 'type' => 'info', 'msg' => "Petition returned HTTP 200" }
|
108
|
+
|
109
|
+
begin
|
110
|
+
json_response = JSON.parse(response.body)
|
111
|
+
|
112
|
+
status = json_response['ResponseMessage']['ResponseHeader']['Status']
|
113
|
+
|
114
|
+
status_code = status ? status['StatusCode'] : ''
|
115
|
+
status_desc = status ? status['StatusDesc'] : ''
|
116
|
+
|
117
|
+
if status_code == '200'
|
118
|
+
logs << { 'type' => 'success', 'msg' => 'Solicitud de pago realizada correctamente' }
|
119
|
+
|
120
|
+
payment = json_response['ResponseMessage']['ResponseBody']['any']['unregisteredPaymentRS']
|
121
|
+
trn_id = payment ? payment['transactionId'].to_s.strip : ''
|
122
|
+
|
123
|
+
logs << { 'type' => 'success', 'msg' => 'Id Transacción: ' + trn_id }
|
124
|
+
else
|
125
|
+
raise 'Error ' + status_code + ' = ' + status_desc
|
126
|
+
end
|
127
|
+
|
128
|
+
rescue StandardError => e
|
129
|
+
raise e
|
130
|
+
end
|
131
|
+
else
|
132
|
+
raise 'Unable to connect to Nequi, please check the information sent.'
|
133
|
+
end
|
134
|
+
|
135
|
+
logs
|
136
|
+
end
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nequi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- geocodinglife
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.21.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.21.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.8'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.8.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.8'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.8.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: vcr
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '6.2'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '6.2'
|
61
|
+
description: Nequi gem provides a convenient way to integrate with Nequi payments
|
62
|
+
systems for processing payments and other related operations.
|
63
|
+
email:
|
64
|
+
- geocodinglife@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/nequi.rb
|
70
|
+
- lib/nequi/version.rb
|
71
|
+
homepage: https://github.com/geocodinglife/nequi
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata:
|
75
|
+
homepage_uri: https://github.com/geocodinglife/nequi
|
76
|
+
source_code_uri: https://github.com/geocodinglife/nequi
|
77
|
+
changelog_uri: https://github.com/geocodinglife/nequi/CHANGELOG.md
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.6.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.4.14
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Ruby gem to connect with Nequi payments systems.
|
97
|
+
test_files: []
|