stp_client 0.3.0 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b35312a692c39818b9fb03f02b10dae9ed44de79d1333b64ef7da23bbdb4e638
4
- data.tar.gz: 65902abc627a5de9e20e37e213744f0f77c8c44571d8c5000c4a75151a4e5741
3
+ metadata.gz: 4013736c66bd4b1905fdc7393826500b44bd0c14d0e84be0ff4279185a24d993
4
+ data.tar.gz: 404bf60f4fc4b46329715d7688f0d6477f0dc05b2935102cd52f0fa18e87737d
5
5
  SHA512:
6
- metadata.gz: 675889febf324cfbca754443c114b0c99ca3499142ecf471bbe61588c07adf19e6dc7f8aaf7f4989ba79b126216d4d2790447a6f9c12fe1613b8b785394c58bc
7
- data.tar.gz: d1f14ac8556e19d1677e34d2c37d98eb6b86c51f88f157e4a2333c2dde26136e1e2e06af4349b26777469fd9b629170107328708f88d5844262268ecb000d92a
6
+ metadata.gz: f20436a5e1744208f2d215f12842b840f7c998c87020f671997e705c3e95d59abb1e6e02cf5df3db75320eaf613d26d65b5d0af0f7aa47a58385bef8b41fdf1e
7
+ data.tar.gz: 5d0eabdea19253004e4cdd1b6d82d791fd30b5b61f4eebb162ab94125bf07a1e337aa6b19e5b49dcad1bc8c5c8dac860729534275c884a166b73ee4fe75ba60d
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stp_client (0.2.1)
4
+ stp_client (0.4.3)
5
5
  crypto_yellowme (~> 0.4)
6
6
  faraday (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.2.4.1)
12
- activesupport (= 5.2.4.1)
13
- activesupport (5.2.4.1)
11
+ activemodel (5.2.4.3)
12
+ activesupport (= 5.2.4.3)
13
+ activesupport (5.2.4.3)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
@@ -18,7 +18,7 @@ GEM
18
18
  addressable (2.7.0)
19
19
  public_suffix (>= 2.0.2, < 5.0)
20
20
  bcrypt (3.1.13)
21
- concurrent-ruby (1.1.5)
21
+ concurrent-ruby (1.1.6)
22
22
  crack (0.4.3)
23
23
  safe_yaml (~> 1.0.0)
24
24
  crypto_yellowme (0.4.0)
@@ -29,13 +29,13 @@ GEM
29
29
  docile (1.3.2)
30
30
  faker (2.10.0)
31
31
  i18n (>= 1.6, < 1.8)
32
- faraday (1.0.0)
32
+ faraday (1.0.1)
33
33
  multipart-post (>= 1.2, < 3)
34
34
  hashdiff (1.0.1)
35
- i18n (1.7.0)
35
+ i18n (1.7.1)
36
36
  concurrent-ruby (~> 1.0)
37
37
  json (2.3.0)
38
- minitest (5.13.0)
38
+ minitest (5.14.1)
39
39
  multipart-post (2.1.1)
40
40
  public_suffix (4.0.3)
41
41
  rspec (3.9.0)
@@ -58,7 +58,7 @@ GEM
58
58
  simplecov-html (~> 0.10.0)
59
59
  simplecov-html (0.10.2)
60
60
  thread_safe (0.3.6)
61
- tzinfo (1.2.6)
61
+ tzinfo (1.2.7)
62
62
  thread_safe (~> 0.1)
63
63
  webmock (3.4.2)
64
64
  addressable (>= 2.3.6)
@@ -76,4 +76,4 @@ DEPENDENCIES
76
76
  webmock (~> 3.4.2)
77
77
 
78
78
  BUNDLED WITH
79
- 2.0.2
79
+ 2.1.2
data/lib/stp.rb CHANGED
@@ -5,7 +5,8 @@ require 'stp/structs/account'
5
5
  require 'stp/structs/payment_order'
6
6
  require 'stp/account'
7
7
  require 'stp/payment_order'
8
- require 'stp/stp_error'
8
+ require 'stp/errors/stp_error'
9
+ require 'stp/errors/account_already_exists'
9
10
 
10
11
  module STP
11
12
  def self.config
@@ -43,4 +44,12 @@ module STP
43
44
  def self.company
44
45
  @company
45
46
  end
47
+
48
+ def self.verbose
49
+ @verbose
50
+ end
51
+
52
+ def self.verbose=(verbose)
53
+ @verbose = verbose
54
+ end
46
55
  end
@@ -8,8 +8,10 @@ module STP
8
8
  req.headers['Content-Type'] = 'application/json'
9
9
  req.body = account.to_json
10
10
  end
11
+ puts response.body if STP.verbose
11
12
  hash = JSON.parse(response.body)
12
- raise STP::STPError.new(hash['message']) unless hash['id'] == 0
13
+ raise STP::Errors::AccountAlreadyExists.new(hash['id'], hash['descripcion']) if hash['id'] == 1 && hash['descripcion'] == 'Cuenta Duplicada'
14
+ raise STP::Errors::STPError.new(hash['id'], hash['descripcion']) unless hash['id'] == 0
13
15
  end
14
16
 
15
17
  def self.delete(account)
@@ -20,8 +22,9 @@ module STP
20
22
  req.headers['Content-Type'] = 'application/json'
21
23
  req.body = account.to_json
22
24
  end
25
+ puts response.body if STP.verbose
23
26
  hash = JSON.parse(response.body)
24
- raise STP::STPError.new(hash['message']) unless hash['id'] == 0
27
+ raise STP::Errors::STPError.new(hash['id'], hash['descripcion']) unless hash['id'] == 0
25
28
  end
26
29
  end
27
30
  end
@@ -0,0 +1,6 @@
1
+ module STP
2
+ module Errors
3
+ class AccountAlreadyExists < STPError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module STP
2
+ module Errors
3
+ class STPError < StandardError
4
+ def initialize(code = nil, message = nil)
5
+ @code = code
6
+ @message = message
7
+ end
8
+
9
+ def to_h
10
+ { code: @code, message: @message }
11
+ end
12
+
13
+ def to_s
14
+ to_h.to_s
15
+ end
16
+ end
17
+ end
18
+ end
@@ -13,7 +13,7 @@ module STP
13
13
  :economic_activity, # actividadEconomica
14
14
  :street, # calle
15
15
  :exterior_number, # numeroExterior
16
- :interior_nunmber, # numeroInterior
16
+ :interior_number, # numeroInterior
17
17
  :neighborhood, # colonia
18
18
  :municipality, # alcaldiaMunicipio
19
19
  :zip_code, # cp
@@ -34,12 +34,15 @@ module STP
34
34
  end
35
35
 
36
36
  def as_json(_options = {})
37
+ name = @name.present? ? I18n.transliterate(@name) : nil,
38
+ paternal_surname = @paternal_surname.present? ? I18n.transliterate(@paternal_surname) : nil,
39
+ maternal_surname = @maternal_surname.present? ? I18n.transliterate(@maternal_surname) : nil,
37
40
  {
38
41
  cuenta: @account,
39
42
  empresa: @company,
40
- nombre: @name,
41
- apellidoPaterno: @paternal_surname,
42
- apellidoMaterno: @maternal_surname,
43
+ nombre: name,
44
+ apellidoPaterno: paternal_surname,
45
+ apellidoMaterno: maternal_surname,
43
46
  rfcCurp: @rfc,
44
47
  fechaNacimiento: @birthdate,
45
48
  genero: @sex,
@@ -47,7 +50,7 @@ module STP
47
50
  actividadEconomica: @economic_activity,
48
51
  calle: @street,
49
52
  numeroExterior: @exterior_number,
50
- numeroInterior: @interior_nunmber,
53
+ numeroInterior: @interior_number,
51
54
  colonia: @neighborhood,
52
55
  alcaldiaMunicipio: @municipality,
53
56
  cp: @zip_code,
@@ -1,3 +1,3 @@
1
1
  module STP
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -21,7 +21,7 @@ RSpec.describe STP::Account do
21
21
  account.economic_activity = 'programador'
22
22
  account.street = Faker::Address.street_name
23
23
  account.exterior_number = Faker::Address.building_number
24
- account.interior_nunmber = Faker::Address.building_number
24
+ account.interior_number = Faker::Address.building_number
25
25
  account.neighborhood = Faker::Address.community
26
26
  account.municipality = Faker::Address.community
27
27
  account.zip_code = Faker::Number.number(digits: 5)
@@ -61,7 +61,7 @@ RSpec.describe STP::Account do
61
61
  end
62
62
 
63
63
  context 'fails when' do
64
- context 'repeating account and rfcCurp' do
64
+ context 'random error' do
65
65
  let(:account_obj) do
66
66
  account = STP::Structs::Account.new
67
67
  account.account = '01010101'
@@ -75,7 +75,7 @@ RSpec.describe STP::Account do
75
75
  account.economic_activity = 'programador'
76
76
  account.street = Faker::Address.street_name
77
77
  account.exterior_number = Faker::Address.building_number
78
- account.interior_nunmber = Faker::Address.building_number
78
+ account.interior_number = Faker::Address.building_number
79
79
  account.neighborhood = Faker::Address.community
80
80
  account.municipality = Faker::Address.community
81
81
  account.zip_code = Faker::Number.number(digits: 5)
@@ -92,7 +92,41 @@ RSpec.describe STP::Account do
92
92
  )
93
93
  end
94
94
 
95
- it { expect {subject}.to raise_error(STP::STPError) }
95
+ it { expect {subject}.to raise_error(STP::Errors::STPError) }
96
+ end
97
+
98
+ context 'repeating account and rfcCurp' do
99
+ let(:account_obj) do
100
+ account = STP::Structs::Account.new
101
+ account.account = '01010101'
102
+ account.name = Faker::Name.first_name
103
+ account.paternal_surname = Faker::Name.last_name
104
+ account.maternal_surname = Faker::Name.last_name
105
+ account.rfc = 'RFC'
106
+ account.birthdate = Faker::Date.birthday(min_age: 6, max_age: 65)
107
+ account.sex = 'male'
108
+ account.state = 'Mérida'
109
+ account.economic_activity = 'programador'
110
+ account.street = Faker::Address.street_name
111
+ account.exterior_number = Faker::Address.building_number
112
+ account.interior_number = Faker::Address.building_number
113
+ account.neighborhood = Faker::Address.community
114
+ account.municipality = Faker::Address.community
115
+ account.zip_code = Faker::Number.number(digits: 5)
116
+ account.country = 'México'
117
+ account.email = Faker::Internet.email
118
+ account.identification_id = 'id'
119
+ account.phone = Faker::PhoneNumber.phone_number
120
+ account
121
+ end
122
+
123
+ before do
124
+ stub_request(:put, "#{STP.api_uri}/cuentaModule/fisica").to_return(
125
+ body: JSON.dump(STPTestHelpers::ACCOUNT_CREATE_MOCK_ERROR(1, 'Cuenta Duplicada')), status: 200
126
+ )
127
+ end
128
+
129
+ it { expect {subject}.to raise_error(STP::Errors::AccountAlreadyExists) }
96
130
  end
97
131
  end
98
132
  end
@@ -21,7 +21,7 @@ RSpec.describe STP::Account do
21
21
  account.economic_activity = 'programador'
22
22
  account.street = Faker::Address.street_name
23
23
  account.exterior_number = Faker::Address.building_number
24
- account.interior_nunmber = Faker::Address.building_number
24
+ account.interior_number = Faker::Address.building_number
25
25
  account.neighborhood = Faker::Address.community
26
26
  account.municipality = Faker::Address.community
27
27
  account.zip_code = Faker::Number.number(digits: 5)
@@ -41,7 +41,7 @@ RSpec.describe STP::Account do
41
41
  allow(STP::Account).to receive(:create).
42
42
  and_return(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS())
43
43
  end
44
-
44
+
45
45
  before do
46
46
  stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
47
47
  body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS()), status: 200
@@ -59,7 +59,7 @@ RSpec.describe STP::Account do
59
59
  account.rfc = 'RFCURP'
60
60
  account
61
61
  end
62
-
62
+
63
63
  before do
64
64
  stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
65
65
  body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_SUCCESS()), status: 200
@@ -85,7 +85,7 @@ RSpec.describe STP::Account do
85
85
  account.economic_activity = 'programador'
86
86
  account.street = Faker::Address.street_name
87
87
  account.exterior_number = Faker::Address.building_number
88
- account.interior_nunmber = Faker::Address.building_number
88
+ account.interior_number = Faker::Address.building_number
89
89
  account.neighborhood = Faker::Address.community
90
90
  account.municipality = Faker::Address.community
91
91
  account.zip_code = Faker::Number.number(digits: 5)
@@ -95,14 +95,14 @@ RSpec.describe STP::Account do
95
95
  account.phone = Faker::PhoneNumber.phone_number
96
96
  account
97
97
  end
98
-
98
+
99
99
  before do
100
100
  stub_request(:delete, "#{STP.api_uri}/cuentaModule/fisica").to_return(
101
101
  body: JSON.dump(STPTestHelpers::ACCOUNT_DELETE_MOCK_ERROR(-2)), status: 200
102
102
  )
103
103
  end
104
104
 
105
- it { expect {subject}.to raise_error(STP::STPError) }
105
+ it { expect {subject}.to raise_error(STP::Errors::STPError) }
106
106
  end
107
107
  end
108
108
  end
@@ -96,7 +96,7 @@ RSpec.describe STP::PaymentOrder do
96
96
  end
97
97
 
98
98
  it { expect(subject['id']).to eq -2 }
99
- it { expect(subject['descripcionError']).not_to be_nil }
99
+ it { expect(subject['descripcion']).not_to be_nil }
100
100
  end
101
101
  end
102
102
  end
@@ -1,7 +1,7 @@
1
1
  module STPTestHelpers
2
2
  def self.PAYMENT_ORDER_MOCK_ERROR(error_code)
3
3
  {
4
- 'descripcionError' => 'regular error msg',
4
+ 'descripcion' => 'regular error msg',
5
5
  'id' => error_code,
6
6
  }
7
7
  end
@@ -16,9 +16,9 @@ module STPTestHelpers
16
16
  }
17
17
  end
18
18
 
19
- def self.ACCOUNT_CREATE_MOCK_ERROR(error_code)
19
+ def self.ACCOUNT_CREATE_MOCK_ERROR(error_code, message='regular error msg')
20
20
  {
21
- 'descripcionError' => 'regular error msg',
21
+ 'descripcion' => message,
22
22
  'id' => error_code,
23
23
  }
24
24
  end
@@ -32,7 +32,7 @@ module STPTestHelpers
32
32
 
33
33
  def self.ACCOUNT_DELETE_MOCK_ERROR(error_code)
34
34
  {
35
- 'descripcionError' => 'regular error msg',
35
+ 'descripcion' => 'regular error msg',
36
36
  'id' => error_code,
37
37
  }
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -109,8 +109,9 @@ files:
109
109
  - Rakefile
110
110
  - lib/stp.rb
111
111
  - lib/stp/account.rb
112
+ - lib/stp/errors/account_already_exists.rb
113
+ - lib/stp/errors/stp_error.rb
112
114
  - lib/stp/payment_order.rb
113
- - lib/stp/stp_error.rb
114
115
  - lib/stp/structs/account.rb
115
116
  - lib/stp/structs/payment_order.rb
116
117
  - lib/stp/version.rb
@@ -141,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.7.6
145
+ rubygems_version: 3.1.2
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: STP Client is a ruby integration to STP services
@@ -1,4 +0,0 @@
1
- module STP
2
- class STPError < StandardError
3
- end
4
- end