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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nequi.rb +24 -36
  3. metadata +21 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80c402009a6d5aebd975b4bc279d3baf931e5c5a8cbf1d8f130256bcf0814d02
4
- data.tar.gz: 45208682a9bd6de66902de08330597e0a4f78a01c67877e1a12aa346692b4156
3
+ metadata.gz: adfe516c81ff1c4430a521fc5697e16c052664956bdf2d157c6d7b0d02526aa2
4
+ data.tar.gz: ff85c2b1b6bc1cd7748ac8f62ab9c1a2d702c1b14d4f051fb7d8fa7bb3af15cb
5
5
  SHA512:
6
- metadata.gz: a0a90fec403f52b0e1e05589ab82e084fdca818830642c6b8a25b5ee7e778e17a40f24e8ce70109673572334abe6f8941a00a76a7750b02df1be09635fe26e4e
7
- data.tar.gz: 6ed35c9a6ea740bc0b39271ceebdc0e4a2daae7c97b37ad67df742baee6138fcf65192dd02b0b88e9ea89b07477ff1ffaefa8fbc98a02bb100e02c041e8b2948
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
- :auth_grant_type,
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.auth_url, body: body, headers: headers)
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
- @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
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.call(amount, phone)
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' => 'info', 'msg' => "Ready to send Petitions" }]
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
- if response.code.to_i == 200 && !response.body.empty?
107
- logs << { 'type' => 'info', 'msg' => "Petition returned HTTP 200" }
89
+ unregisteredpayment = configuration.api_base_path + configuration.unregisteredpayment_endpoint
108
90
 
109
- begin
110
- json_response = JSON.parse(response.body)
91
+ response = HTTParty.post(unregisteredpayment, body: body, headers: headers)
92
+
93
+ response_body = JSON.parse(response.body)
111
94
 
112
- status = json_response['ResponseMessage']['ResponseHeader']['Status']
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 == '200'
118
- logs << { 'type' => 'success', 'msg' => 'Solicitud de pago realizada correctamente' }
105
+ if status_code.include?('200')
106
+ logs << { 'type' => 'success', 'message' => 'Payment request send success fully' }
119
107
 
120
- payment = json_response['ResponseMessage']['ResponseBody']['any']['unregisteredPaymentRS']
108
+ payment = any_data['unregisteredPaymentRS']
121
109
  trn_id = payment ? payment['transactionId'].to_s.strip : ''
122
110
 
123
- logs << { 'type' => 'success', 'msg' => 'Id Transacción: ' + trn_id }
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.0
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: