nequi 0.2.2 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b840f426c4a39622b1055963e0546cef67a5e43171f72c73366ecc68c27773d
4
- data.tar.gz: 9ec812ef15d0216b8b58e3aef80519bcf52b22ab98b1e9f45599d40955711727
3
+ metadata.gz: abbefb8ee00a9cf229ad5cf57d1df4e635d6f0b143f786a04c03e3e12455caa9
4
+ data.tar.gz: 8903c1e8f64d6610bf03b47292c04a7d6e13a5211da61bed2e406462210504ed
5
5
  SHA512:
6
- metadata.gz: 3a6b8ff1f05e8beb83413a2caa3df9374ee751b8eb78f0cf5660949820d0c43e0662f24a98a0d61da9df799914d987492665f8bdd886c59fd40a15452845ed79
7
- data.tar.gz: e6b432149f4ab6416640b11a2e76228bee84266e923016833b14b2c573800889014299e438a06b8d459ac194329cb06dbce3d907acbf9837a43c3d6bc9d1c97f
6
+ metadata.gz: '0188ce3485e7cfb95178e42b6da80df2806b41607c6265cdbf704cd72effb1f953da8108e1ce80c8f41889a5ff059d387524ab2cd000e1603da75478b90d26b1'
7
+ data.tar.gz: 553ca437e995578386248307b4a9fb3f29d8ea58fb3a16fe5fdae4845e379ade828f91df08dbd676b6c585bf24ca0f085a887b579bdb9e8a33decf236a60ec4c
data/lib/nequi.rb CHANGED
@@ -7,6 +7,7 @@ module Nequi
7
7
  require 'httparty'
8
8
  require 'base64'
9
9
  require 'json'
10
+ require 'time'
10
11
  require 'active_support/core_ext/integer/time'
11
12
 
12
13
  include HTTParty
@@ -22,14 +23,12 @@ module Nequi
22
23
 
23
24
  class Configuration
24
25
  attr_accessor :auth_uri, :phone, :auth_grant_type, :unregisteredpayment_endpoint,
25
- :client_id, :client_secret, :api_base_path, :api_key
26
+ :client_id, :client_secret, :api_base_path, :api_key, :nequi_status_payment
26
27
  end
27
28
 
28
29
  NEQUI_STATUS_CODE_SUCCESS = '200'.freeze
29
30
 
30
31
  def self.get_token
31
- return @token if @token
32
-
33
32
  headers = {
34
33
  'Content-Type' => 'application/x-www-form-urlencoded',
35
34
  'Accept' => 'application/json',
@@ -46,17 +45,17 @@ module Nequi
46
45
  @token = { access_token: response_body['access_token'], token_type: response_body['token_type'], expires_at: Time.now + 15.minutes }
47
46
  end
48
47
 
49
- def self.charge(amount, phone)
48
+ def self.payment_request(amount, phone, product_id)
50
49
  current_time = Time.now
51
- formatted_timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S.%6N %z')
52
- random_number = rand(1_000_000_000..9_999_999_999).to_s
53
- random_number = random_number.rjust(10, '0')
50
+ utc_time = current_time.utc
51
+ formatted_timestamp = utc_time.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
54
52
 
53
+ access_token = get_token[:access_token]
55
54
 
56
55
  headers = {
57
56
  'Content-Type' => 'application/json',
58
57
  'Accept' => 'application/json',
59
- 'Authorization' => "Bearer #{get_token[:access_token]}",
58
+ 'Authorization' => "Bearer #{access_token}",
60
59
  'x-api-key' => configuration.api_key
61
60
  }
62
61
 
@@ -65,8 +64,8 @@ module Nequi
65
64
  "RequestHeader" => {
66
65
  "Channel" => "PNP04-C001",
67
66
  "RequestDate" => formatted_timestamp,
68
- "MessageID" => random_number,
69
- "ClientID" => "#{configuration.client_id}",
67
+ "MessageID" => product_id,
68
+ "ClientID" => configuration.client_id,
70
69
  "Destination" => {
71
70
  "ServiceName" => "PaymentsService",
72
71
  "ServiceOperation" => "unregisteredPayment",
@@ -77,51 +76,33 @@ module Nequi
77
76
  "RequestBody" => {
78
77
  "any" => {
79
78
  "unregisteredPaymentRQ" => {
80
- "phoneNumber" => "#{phone}",
79
+ "phoneNumber" => phone,
81
80
  "code" => "NIT_1",
82
- "value" => "#{amount}"
81
+ "value" => amount
83
82
  }
84
83
  }
85
84
  }
86
85
  }
87
86
  }.to_json
88
87
 
89
- logs = [{ 'type' => 'information', 'message' => "Ready to send Petitions" }]
90
-
91
- unregisteredpayment = configuration.api_base_path + configuration.unregisteredpayment_endpoint
92
-
93
- response = HTTParty.post(unregisteredpayment, body: body, headers: headers)
94
-
95
- response_body = JSON.parse(response.body)
96
-
97
- if response.code.to_i == 200 && !response_body['ResponseMessage']['ResponseBody'].nil?
98
- logs << { 'type' => 'information', 'message' => "Petition returned HTTP 200" }
99
-
100
- begin
101
- any_data = response_body['ResponseMessage']['ResponseBody']['any']
102
-
103
- status = response_body['ResponseMessage']['ResponseHeader']['Status']
104
- status_code = status ? status['StatusCode'] : ''
105
- status_desc = status ? status['StatusDesc'] : ''
106
-
107
- if status_code == '200'
108
- logs << { 'type' => 'success', 'message' => 'Payment request send success fully' }
88
+ unregisteredpayment = configuration.api_base_path + configuration.unregisteredpayment_endpoint
109
89
 
110
- payment = any_data['unregisteredPaymentRS']
111
- trn_id = payment ? payment['transactionId'].to_s.strip : ''
90
+ response = HTTParty.post(unregisteredpayment, body: body, headers: headers)
112
91
 
113
- logs << { 'type' => 'success', 'message' => 'Transaction Id: ' + trn_id }
114
- else
115
- raise 'Error ' + status_code + ' = ' + status_desc
116
- end
92
+ response_status = response["ResponseMessage"]["ResponseHeader"]["Status"]
93
+ status_code = response_status["StatusCode"]
94
+ status_description = response_status["StatusDesc"]
117
95
 
118
- rescue StandardError => e
119
- raise e
120
- end
121
- else
122
- raise 'Unable to connect to Nequi, please check the information sent.'
123
- end
96
+ return {
97
+ type: 'Error',
98
+ status: status_code,
99
+ api_status: status_code,
100
+ message: status_description
101
+ } unless response_status.include?({ "StatusCode"=>"0", "StatusDesc"=>"SUCCESS" })
124
102
 
125
- logs
103
+ response_any = response["ResponseMessage"]["ResponseBody"]["any"]
104
+ success_id = response_any["unregisteredPaymentRS"]["transactionId"]
105
+ # Nequi::StatusCheckJob.set(wait: 2.minutes).perform_later(product_id, configuration, access_token, success_id)
106
+ { type: 'success', status: response.code, api_status: status_code, message: 'Payment request send success fully'}
126
107
  end
127
108
  end
@@ -0,0 +1,68 @@
1
+ # lib/nequi_status_check_job.rb
2
+
3
+ module Nequi
4
+ class StatusCheckJob < Struct.new(:product_id, :configuration, :token, :success_id)
5
+ require 'httparty'
6
+ require 'base64'
7
+ require 'json'
8
+ require 'time'
9
+ require 'active_support/core_ext/integer/time'
10
+
11
+
12
+ def perform
13
+
14
+ current_time = Time.now
15
+ utc_time = current_time.utc
16
+ formatted_timestamp = utc_time.strftime('%Y-%m-%dT%H:%M:%S.%LZ')
17
+
18
+ headers = {
19
+ 'Content-Type' => 'application/json',
20
+ 'Accept' => 'application/json',
21
+ 'Authorization' => "Bearer #{token}",
22
+ 'x-api-key' => configuration.api_key
23
+ }
24
+
25
+ body = {
26
+ "RequestMessage" => {
27
+ "RequestHeader" => {
28
+ "Channel" => "PNP04-C001",
29
+ "RequestDate" => formatted_timestamp,
30
+ "MessageID" => product_id,
31
+ "ClientID" => configuration.client_id,
32
+ "Destination" => {
33
+ "ServiceName" => "PaymentsService",
34
+ "ServiceOperation" => "getStatusPayment",
35
+ "ServiceRegion" => "C001",
36
+ "ServiceVersion" => "1.0.0"
37
+ }
38
+ },
39
+ "RequestBody" => {
40
+ "any" => {
41
+ "getStatusPaymentRQ" => {
42
+ "codeQR": success_id
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }.to_json
48
+
49
+ nequi_status_payment_url = configuration.api_base_path + configuration.nequi_status_payment
50
+
51
+ response = HTTParty.post(nequi_status_payment_url, body: body, headers: headers)
52
+
53
+
54
+ response_status = response["ResponseMessage"]["ResponseHeader"]["Status"]
55
+ status_code = response_status["StatusCode"]
56
+ status_description = response_status["StatusDesc"]
57
+
58
+
59
+ if status_description = response_status["StatusDesc"] == "SUCCESS"
60
+ logs = { type: 'success', status: response.code, api_status: status_code, message: 'Payment request send success fully'}
61
+
62
+ Rails.logger.info(logs)
63
+ else
64
+ { type: 'success', status: response.code, api_status: status_code, message: ":wClient don't accept charge"}
65
+ end
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nequi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - geocodinglife
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-25 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -78,6 +78,26 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 3.18.1
81
+ - !ruby/object:Gem::Dependency
82
+ name: sidekiq
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '7.1'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 7.1.2
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '7.1'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 7.1.2
81
101
  description: Nequi gem provides a convenient way to integrate with Nequi payments
82
102
  systems for processing payments and other related operations.
83
103
  email:
@@ -88,6 +108,7 @@ extra_rdoc_files: []
88
108
  files:
89
109
  - lib/nequi.rb
90
110
  - lib/nequi/version.rb
111
+ - lib/nequi_status_check_job.rb
91
112
  homepage: https://github.com/geocodinglife/nequi
92
113
  licenses:
93
114
  - MIT