xhash_client 0.3.0 → 0.3.5

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.
@@ -0,0 +1,18 @@
1
+ module Xhash
2
+ class SAT < ApiClient
3
+ def self.get_rfc(
4
+ name: nil, last_name: nil, mothers_last_name: nil, birth_date: nil
5
+ )
6
+ url = 'sat/get-rfc'
7
+ body = {
8
+ name: name,
9
+ last_name: last_name,
10
+ mothers_last_name: mothers_last_name,
11
+ birth_date: birth_date
12
+ }
13
+ response = api_post(url: url, body: body)
14
+ raise Xhash::MissingRequiredFieldError.new(response) unless response[:rfc]
15
+ Xhash::RFC.new(*response.values_at(*Xhash::RFC.members))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module Xhash
2
+ CURP =
3
+ Struct.new(
4
+ :country_of_birth,
5
+ :created_at,
6
+ :curp,
7
+ :day_of_birth,
8
+ :gender,
9
+ :id,
10
+ :last_name,
11
+ :mothers_last_name,
12
+ :name,
13
+ :province_of_birth,
14
+ :updated_at
15
+ )
16
+ end
@@ -0,0 +1,49 @@
1
+ module Xhash
2
+ Customer =
3
+ Struct.new(
4
+ :id,
5
+ :name,
6
+ :last_name,
7
+ :mothers_last_name,
8
+ :gender,
9
+ :birth_date,
10
+ :birth_city,
11
+ :birth_country,
12
+ :curp,
13
+ :renapo_match,
14
+ :rfc,
15
+ :rfc_match,
16
+ :rfc_is_cancelled,
17
+ :zip_code,
18
+ :neighborhood,
19
+ :province,
20
+ :city,
21
+ :country,
22
+ :address,
23
+ :activity,
24
+ :electoral_key,
25
+ :clabe,
26
+ :ext_address,
27
+ :email,
28
+ :phone_number,
29
+ :in_black_list,
30
+ :black_list_name,
31
+ :liveness_video,
32
+ :liveness_check,
33
+ :document_id,
34
+ :client_id,
35
+ :external_customer_id,
36
+ :update_key,
37
+ :device_fingerprint_id,
38
+ :token_email,
39
+ :email_verified_at,
40
+ :token_sm,
41
+ :sms_verified_at,
42
+ :deleted_at,
43
+ :created_at,
44
+ :updated_at,
45
+ :ip_uniqueness,
46
+ :fingerprint_uniqueness,
47
+ :documents
48
+ )
49
+ end
@@ -0,0 +1,30 @@
1
+ module Xhash
2
+ Identification =
3
+ Struct.new(
4
+ :lines,
5
+ :cic,
6
+ :cic_digit_check,
7
+ :is_cic_digit_check_consistent,
8
+ :section_and_consecutive,
9
+ :date,
10
+ :date_check_digit,
11
+ :expiration_date,
12
+ :expiration_date_digit,
13
+ :nationality,
14
+ :emission_and_fuar,
15
+ :name,
16
+ :mothers_last_name,
17
+ :last_name,
18
+ :last_names,
19
+ :birth_date,
20
+ :gender,
21
+ :elector_key,
22
+ :curp,
23
+ :street,
24
+ :neighborhood,
25
+ :zip_code,
26
+ :city,
27
+ :province,
28
+ :type
29
+ )
30
+ end
@@ -0,0 +1,15 @@
1
+ module Xhash
2
+ ProofOfAddress =
3
+ Struct.new(
4
+ :full_name,
5
+ :full_address,
6
+ :street,
7
+ :neighborhood,
8
+ :zip_code,
9
+ :city,
10
+ :province,
11
+ :type,
12
+ :date,
13
+ :exception
14
+ )
15
+ end
@@ -0,0 +1,3 @@
1
+ module Xhash
2
+ RFC = Struct.new(:name, :last_name, :mothers_last_name, :birth_date, :rfc)
3
+ end
@@ -0,0 +1,3 @@
1
+ module Xhash
2
+ VERSION = '0.3.5'
3
+ end
Binary file
Binary file
@@ -0,0 +1,9 @@
1
+ require 'webmock/rspec'
2
+ require 'rspec'
3
+ require 'simplecov'
4
+
5
+ require 'xhash'
6
+
7
+ SimpleCov.start { add_filter '/spec/' }
8
+
9
+ RSpec.configure { |config| config.before(:all) { Xhash.api_key = 'api_key' } }
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xhash::SAT do
4
+ describe '.renapo' do
5
+ it 'successfully with valid CURP' do
6
+ curp = 'OESJ980828HDFLNR04'
7
+
8
+ stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
9
+ .to_return(
10
+ body:
11
+ JSON.dump(
12
+ {
13
+ result: true,
14
+ payload: {
15
+ curp: curp,
16
+ name: 'JERONIMO',
17
+ last_name: 'OLIVA',
18
+ mothers_last_name: 'SANCHEZ',
19
+ gender: 'H',
20
+ province_of_birth: 'DF',
21
+ day_of_birth: '1999-08-28 00:00:00',
22
+ updated_at: '2019-10-03 13:12:32',
23
+ created_at: '2019-10-03 13:12:32',
24
+ id: 76
25
+ }
26
+ }
27
+ ),
28
+ status: 200
29
+ )
30
+
31
+ curp_data = Xhash::DatabaseLookup.renapo(curp)
32
+
33
+ expect(curp_data).to be_a(Xhash::CURP)
34
+ expect(curp_data.name).to eq('JERONIMO')
35
+ expect(curp_data.last_name).to eq('OLIVA')
36
+ expect(curp_data.mothers_last_name).to eq('SANCHEZ')
37
+ expect(curp_data.day_of_birth).to eq('1999-08-28 00:00:00')
38
+ expect(curp_data.gender).to eq('H')
39
+ expect(curp_data.curp).to eq(curp)
40
+ end
41
+
42
+ it 'fails with invalid CURP' do
43
+ curp = 'JIQJ890611HDFXNN04'
44
+
45
+ stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
46
+ .to_return(
47
+ body:
48
+ JSON.dump(
49
+ {
50
+ result: true,
51
+ payload: {
52
+ id: 65,
53
+ curp: curp,
54
+ name: 'CURP INVALIDO',
55
+ last_name: '',
56
+ mothers_last_name: nil,
57
+ gender: 'H',
58
+ day_of_birth: nil,
59
+ country_of_birth: nil,
60
+ province_of_birth: nil,
61
+ proof_document_payload: nil,
62
+ proof_document_name: nil,
63
+ created_at: '2019-09-02 16:09:07',
64
+ updated_at: '2019-09-02 16:09:07'
65
+ }
66
+ }
67
+ ),
68
+ status: 200
69
+ )
70
+
71
+ begin
72
+ Xhash::DatabaseLookup.renapo(curp)
73
+ rescue => exception
74
+ expect(exception).to be_a(Xhash::InvalidFieldError)
75
+ expect(exception.message).to eq(Xhash::ErrorMessage::INVALID_CURP)
76
+ end
77
+ end
78
+
79
+ it 'fails with html error' do
80
+ curp = 'JIQJ890611HDFXNN04'
81
+
82
+ stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
83
+ .to_return(body: '<p>bad</p>', status: 200)
84
+
85
+ begin
86
+ Xhash::DatabaseLookup.renapo(curp)
87
+ rescue => exception
88
+ expect(exception).to be_a(Xhash::MalformedResponse)
89
+ end
90
+ end
91
+
92
+ it 'fails with malformed CURP' do
93
+ curp = 'asdf'
94
+
95
+ stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
96
+ .to_return(
97
+ body: JSON.dump({ result: false, payload: nil }), status: 200
98
+ )
99
+
100
+ begin
101
+ Xhash::DatabaseLookup.renapo(curp)
102
+ rescue => exception
103
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
104
+ expect(exception.message).to eq(Xhash::ErrorMessage::MISSING_CURP)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,208 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xhash::General do
4
+ describe '.store_data' do
5
+ it 'successfully creates a customer' do
6
+ stub_request(:post, 'https://xhash.dev/api/store-data').to_return(
7
+ body:
8
+ JSON.dump(
9
+ {
10
+ id: 1,
11
+ name: 'pedro',
12
+ last_name: 'can',
13
+ mothers_last_name: 'quintal',
14
+ birth_date: '1997-03-18 00:00:00',
15
+ rfc: 'JIQJ890611FC9',
16
+ curp: 'JIQJ890611HDFXNN04',
17
+ address: 'calle',
18
+ ext_address: 'asdfasdf',
19
+ gender: 'MALE',
20
+ clabe: '032180000118359719',
21
+ activity: '7129019',
22
+ email: 'emilio@xhash.tech',
23
+ phone_number: '9999503059',
24
+ zip_code: '97400',
25
+ external_customer_id: 'my-customer-id-1'
26
+ }
27
+ ),
28
+ status: 200
29
+ )
30
+
31
+ customer =
32
+ Xhash::General.store_data(
33
+ name: 'pedro',
34
+ last_name: 'can',
35
+ mothers_last_name: 'quintal',
36
+ birth_date: '1997-03-18',
37
+ rfc: 'JIQJ890611FC9',
38
+ curp: 'JIQJ890611HDFXNN04',
39
+ address: 'calle',
40
+ ext_address: 'asdfasdf',
41
+ gender: 'MALE',
42
+ clabe: '032180000118359719',
43
+ activity: '7129019',
44
+ email: 'emilio@xhash.tech',
45
+ phone_number: '9999503059',
46
+ zip_code: '97400',
47
+ external_customer_id: 'my-customer-id-1'
48
+ )
49
+
50
+ expect(customer).to be_a(Xhash::Customer)
51
+ expect(customer.id).to be_truthy
52
+ expect(customer.name).to eq('pedro')
53
+ expect(customer.last_name).to eq('can')
54
+ expect(customer.mothers_last_name).to eq('quintal')
55
+ expect(customer.birth_date).to eq('1997-03-18 00:00:00')
56
+ expect(customer.gender).to eq('MALE')
57
+ expect(customer.curp).to eq('JIQJ890611HDFXNN04')
58
+ expect(customer.rfc).to eq('JIQJ890611FC9')
59
+ expect(customer.email).to eq('emilio@xhash.tech')
60
+ expect(customer.external_customer_id).to eq('my-customer-id-1')
61
+ end
62
+
63
+ it 'fails to creates a customer by missing data' do
64
+ stub_request(:post, 'https://xhash.dev/api/store-data').to_return(
65
+ body:
66
+ JSON.dump(
67
+ {
68
+ curp: ['The curp field is required.'],
69
+ gender: ['The gender field is required.']
70
+ }
71
+ ),
72
+ status: 200
73
+ )
74
+
75
+ begin
76
+ customer =
77
+ Xhash::General.store_data(
78
+ name: 'pedro',
79
+ last_name: 'can',
80
+ mothers_last_name: 'quintal',
81
+ birth_date: '1997-03-18',
82
+ rfc: 'JIQJ890611FC9',
83
+ address: 'calle',
84
+ ext_address: 'asdfasdf',
85
+ clabe: '032180000118359719',
86
+ activity: '7129019',
87
+ email: 'emilio@xhash.tech',
88
+ phone_number: '9999503059',
89
+ zip_code: '97400',
90
+ external_customer_id: 'my-customer-id-1'
91
+ )
92
+ rescue => exception
93
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
94
+ expect(exception.message).to eq(
95
+ 'The curp field is required. The gender field is required.'
96
+ )
97
+ expect(exception.response[:curp]).to eq(['The curp field is required.'])
98
+ expect(exception.response[:gender]).to eq(
99
+ ['The gender field is required.']
100
+ )
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '.get_customer' do
106
+ it 'successfully fetch customer data' do
107
+ stub_request(:get, 'https://xhash.dev/api/get-customer/my-customer-id-1')
108
+ .to_return(
109
+ body:
110
+ JSON.dump(
111
+ {
112
+ payload: {
113
+ id: 1,
114
+ name: 'pedro',
115
+ last_name: 'can',
116
+ mothers_last_name: 'quintal',
117
+ birth_date: '1997-03-18 00:00:00',
118
+ rfc: 'JIQJ890611FC9',
119
+ curp: 'JIQJ890611HDFXNN04',
120
+ address: 'calle',
121
+ ext_address: 'asdfasdf',
122
+ gender: 'MALE',
123
+ clabe: '032180000118359719',
124
+ activity: '7129019',
125
+ email: 'emilio@xhash.tech',
126
+ phone_number: '9999503059',
127
+ zip_code: '97400',
128
+ external_customer_id: 'my-customer-id-1'
129
+ }
130
+ }
131
+ ),
132
+ status: 200
133
+ )
134
+
135
+ customer = Xhash::General.get_customer(customer_id: 'my-customer-id-1')
136
+
137
+ expect(customer).to be_a(Xhash::Customer)
138
+ expect(customer.id).to be_truthy
139
+ expect(customer.name).to eq('pedro')
140
+ expect(customer.external_customer_id).to eq('my-customer-id-1')
141
+ end
142
+
143
+ it 'fails to fetch a customer data with bad id' do
144
+ stub_request(:get, 'https://xhash.dev/api/get-customer/my-customer-id-2')
145
+ .to_return(
146
+ body:
147
+ JSON.dump({ customer_id: ['The selected customer id is invalid.'] }),
148
+ status: 200
149
+ )
150
+
151
+ begin
152
+ customer = Xhash::General.get_customer(customer_id: 'my-customer-id-2')
153
+ rescue => exception
154
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
155
+ expect(exception.message).to eq('The selected customer id is invalid.')
156
+ expect(exception.response[:customer_id]).to eq(
157
+ ['The selected customer id is invalid.']
158
+ )
159
+ end
160
+ end
161
+ end
162
+
163
+ describe '.store_file' do
164
+ it 'successfully store file to a customer' do
165
+ stub_request(:post, 'https://xhash.dev/api/store-file').to_return(
166
+ body: 'Image stored', status: 200
167
+ )
168
+
169
+ document = File.open('spec/files/ife_front.png')
170
+
171
+ response =
172
+ Xhash::General.store_file(
173
+ customer_id: 'my-customer-id-1',
174
+ document_type: Xhash::DocumentType::ID::INE_FRONT,
175
+ document: document
176
+ )
177
+
178
+ document.close
179
+ expect(response).to eq('Image stored')
180
+ end
181
+
182
+ it 'fails store file to unexisting user' do
183
+ stub_request(:post, 'https://xhash.dev/api/store-file').to_return(
184
+ body:
185
+ JSON.dump({ customer_id: ['The selected customer id is invalid.'] }),
186
+ status: 200
187
+ )
188
+
189
+ document = File.open('spec/files/ife_front.png')
190
+
191
+ begin
192
+ response =
193
+ Xhash::General.store_file(
194
+ customer_id: 'my-customer-id-1',
195
+ document_type: Xhash::DocumentType::ID::INE_FRONT,
196
+ document: document
197
+ )
198
+ rescue => exception
199
+ document.close
200
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
201
+ expect(exception.message).to eq('The selected customer id is invalid.')
202
+ expect(exception.response[:customer_id]).to eq(
203
+ ['The selected customer id is invalid.']
204
+ )
205
+ end
206
+ end
207
+ end
208
+ end