spree_iugu_bank_slip 3.0.4.1 → 3.0.4.2

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
  SHA1:
3
- metadata.gz: 3351a1c664c65ad22c4adfbdf336f7e03268252e
4
- data.tar.gz: 288357b9df8cb4276f6accbb602b8d731f13bcef
3
+ metadata.gz: 95fc0f8d4b12e056ad1207dffd1c3cecd74f0a94
4
+ data.tar.gz: 657085b396ab4d63c4dbff82a043fb874ec4be4c
5
5
  SHA512:
6
- metadata.gz: 365a29461ef8d66a9ac27a4b482388d8e2dc428a3926d84b8808fee1acac56ffa45fc9890499cb4c230a862dda318d3ef44e1033094123ce38e5df0c16486cb7
7
- data.tar.gz: b51a574f0be1235b6683e3f6be1305ea95e5f8c10e743c4169236d000c3e4a42b0b10b7424c6bf5254920bcbcb1427ffa9e306e8a0f8dfddf8356a5d7e8c5964
6
+ metadata.gz: 358f8e306c2a2d4fee7fd98f9ced27d0b429f819b32d64434f498abbe682dd574e2af7b79f1987caee1f64b02fa66fb8daa1b273fa917c3c0e4412ca64421754
7
+ data.tar.gz: df676140b248b461d714a5739b18ba77e0cadac85a5e333750097ea5682c385d61b5b1f47477e2f5a3e3f8f05e98d188918465a4ee134cc48ed1f5bed6b7be9d
data/.travis.yml CHANGED
@@ -7,6 +7,6 @@ script:
7
7
  - bundle exec rspec
8
8
  language: ruby
9
9
  rvm:
10
+ - 2.1.5
10
11
  - 2.2.3
11
- - 2.2.4
12
- before_install: gem install ruby_dep -v 1.2.0
12
+ - 2.2.4
@@ -40,7 +40,7 @@ module Spree
40
40
  phone = billing_address[:phone]
41
41
  end
42
42
 
43
- notification_url = Spree::Store.current.url
43
+ notification_url = Spree::BankSlipConfig[:store_url]
44
44
  notification_url << Spree::Core::Engine.routes.url_helpers.bank_slip_status_changed_path(source.id)
45
45
 
46
46
  due_date = Date.today + Spree::BankSlipConfig[:days_to_due_date].days
@@ -147,8 +147,16 @@ module Spree
147
147
  #
148
148
  # @return [ActiveMerchant::Billing::Response]
149
149
  #
150
- def void(response_code, gateway_options)
150
+ def void(response_code, _gateway_options)
151
151
  bank_slip = Spree::BankSlip.find_by invoice_id: response_code
152
+ return ActiveMerchant::Billing::Response.new(false, Spree.t('bank_slip.messages.void_fail'), {}, {}) if bank_slip.nil?
153
+
154
+ # Verifica na Iugu se o boleto esta pendente
155
+ # se tiver, faz o cancelamento
156
+ invoice = Iugu::Invoice.fetch response_code
157
+ if invoice.status == 'pending'
158
+ invoice.cancel
159
+ end
152
160
  bank_slip.update_attribute(:status, 'canceled')
153
161
 
154
162
  ActiveMerchant::Billing::Response.new(true, Spree.t('bank_slip.messages.successfully_voided'), {}, authorization: response_code)
@@ -164,6 +172,14 @@ module Spree
164
172
  #
165
173
  def cancel(response_code)
166
174
  bank_slip = Spree::BankSlip.find_by invoice_id: response_code
175
+ return ActiveMerchant::Billing::Response.new(false, Spree.t('bank_slip.messages.void_fail'), {}, {}) if bank_slip.nil?
176
+
177
+ # Verifica na Iugu se o boleto esta pendente
178
+ # se tiver, faz o cancelamento
179
+ invoice = Iugu::Invoice.fetch response_code
180
+ if invoice.status == 'pending'
181
+ invoice.cancel
182
+ end
167
183
  bank_slip.update_attribute(:status, 'canceled')
168
184
 
169
185
  ActiveMerchant::Billing::Response.new(true, Spree.t('bank_slip.messages.successfully_voided'), {}, authorization: response_code)
@@ -31,12 +31,16 @@
31
31
  </div>
32
32
  </div>
33
33
  <div class="row">
34
- <div class="col-sm-12">
34
+ <div class="col-sm-6">
35
35
  <%= label_tag(:doc_customer_attr, Spree.t(:doc_customer_attr) + ': ') + tag(:br) %>
36
36
  <%= select_tag :doc_customer_attr,
37
37
  options_for_select(@user_attr.collect { |item| [Spree.t(item), item] }, @config.doc_customer_attr),
38
38
  class: 'select2', include_blank: true %>
39
39
  </div>
40
+ <div class="col-sm-6">
41
+ <%= label_tag(:store_url, Spree.t(:store_url) + ': ') + tag(:br) %>
42
+ <%= text_field_tag :store_url, @config.store_url, class: 'form-control' %>
43
+ </div>
40
44
  </div>
41
45
  </div>
42
46
  </div>
@@ -18,6 +18,7 @@ en:
18
18
  paid_in: Paid In
19
19
  invoice_id: Invoice ID
20
20
  generate_bank_slip: Generate Billet
21
+ store_url: Store URL
21
22
  bank_slip:
22
23
  messages:
23
24
  iugu_fail: Request to Iugu fail!
@@ -18,6 +18,7 @@ pt-BR:
18
18
  paid_in: Pago Em
19
19
  invoice_id: "Número Boleto"
20
20
  generate_bank_slip: Gerar boleto
21
+ store_url: URL da loja
21
22
  bank_slip:
22
23
  messages:
23
24
  iugu_fail: "Requisição falhou!"
@@ -6,6 +6,7 @@ module Spree
6
6
  preference :days_to_due_date, :integer, default: 3 # Dias para a data de vencimento
7
7
  preference :ignore_due_email, :boolean, default: true # Ignorar email de cobranca
8
8
  preference :log_requests, :boolean, default: false # Salva no log os parametros enviados e recebidos nas requisicoes
9
+ preference :store_url, :string, default: '' # URL da loja para a montagem da url de retorno
9
10
 
10
11
  end
11
12
  end
@@ -21,6 +21,16 @@ describe Spree::BankSlipsController, type: :controller do
21
21
  end
22
22
 
23
23
  it 'should change status to canceled' do
24
+ stub_iugu({ filename: 'fetch', method: :get, url: 'https://api.iugu.com/v1/invoices/1',
25
+ headers: {
26
+ 'Accept'=>'application/json', 'Accept-Charset'=>'utf-8',
27
+ 'Accept-Encoding'=>'gzip, deflate', 'Accept-Language'=>'pt-br;q=0.9,pt-BR',
28
+ 'Content-Length'=>'2', 'Content-Type'=>'application/json; charset=utf-8',
29
+ 'User-Agent'=>'Iugu RubyLibrary'
30
+ }, body: '{}' })
31
+ stub_iugu({ filename: 'canceled', method: :put, body: '{}',
32
+ url: 'https://api.iugu.com/v1/invoices/1/cancel' })
33
+
24
34
  request_params = {
25
35
  bank_slip_id: slip.id,
26
36
  data: {
@@ -24,6 +24,7 @@ describe 'Bank Slip Settings', { type: :feature, js: true } do
24
24
  Spree::BankSlipConfig[:iugu_api_token] = ''
25
25
  Spree::BankSlipConfig[:days_to_due_date] = 3
26
26
  Spree::BankSlipConfig[:ignore_due_email] = true
27
+ Spree::BankSlipConfig[:store_url] = true
27
28
  Iugu.api_key = ''
28
29
  end
29
30
 
@@ -59,5 +60,13 @@ describe 'Bank Slip Settings', { type: :feature, js: true } do
59
60
  expect(find_field('doc_customer_attr').value).to eq 'authentication_token'
60
61
  end
61
62
 
63
+ it 'can edit store url' do
64
+ fill_in 'store_url', with: 'http://localhost'
65
+ click_button 'Update'
66
+
67
+ expect(Spree::BankSlipConfig[:store_url]).to eq 'http://localhost'
68
+ expect(find_field('store_url').value).to eq 'http://localhost'
69
+ end
70
+
62
71
  end
63
72
  end
@@ -0,0 +1,131 @@
1
+ {
2
+ "id": "1",
3
+ "due_date": "2016-01-09",
4
+ "currency": "BRL",
5
+ "discount_cents": null,
6
+ "email": "spree@example.com",
7
+ "items_total_cents": 1000,
8
+ "notification_url": null,
9
+ "return_url": null,
10
+ "status": "canceled",
11
+ "tax_cents": null,
12
+ "updated_at": "2016-01-06T13:24:21-02:00",
13
+ "total_cents": 1000,
14
+ "total_paid_cents": 0,
15
+ "paid_at": null,
16
+ "taxes_paid_cents": null,
17
+ "paid_cents": null,
18
+ "cc_emails": null,
19
+ "financial_return_date": null,
20
+ "payable_with": "all",
21
+ "overpaid_cents": null,
22
+ "ignore_due_email": true,
23
+ "ignore_canceled_email": true,
24
+ "advance_fee_cents": null,
25
+ "secure_id": "1",
26
+ "secure_url": "http://localhost:3000",
27
+ "customer_id": null,
28
+ "customer_ref": null,
29
+ "customer_name": null,
30
+ "user_id": null,
31
+ "total": "R$ 10,00",
32
+ "taxes_paid": "R$ 0,00",
33
+ "total_paid": "R$ 0,00",
34
+ "total_overpaid": "R$ 0,00",
35
+ "fines_on_occurrence_day": null,
36
+ "total_on_occurrence_day": null,
37
+ "fines_on_occurrence_day_cents": null,
38
+ "total_on_occurrence_day_cents": null,
39
+ "advance_fee": null,
40
+ "paid": "R$ 0,00",
41
+ "interest": null,
42
+ "discount": null,
43
+ "created_at": "06/01, 13:24 h",
44
+ "refundable": null,
45
+ "installments": null,
46
+ "transaction_number": 1111,
47
+ "payment_method": null,
48
+ "created_at_iso": "2016-01-06T13:24:20-02:00",
49
+ "updated_at_iso": "2016-01-06T13:24:21-02:00",
50
+ "financial_return_dates": null,
51
+ "bank_slip": {
52
+ "digitable_line": "00000000000000000000000000000000000000000000000",
53
+ "barcode_data": "00000000000000000000000000000000000000000000",
54
+ "barcode": "http://localhost:3000"
55
+ },
56
+ "items": [
57
+ {
58
+ "id": "34F9D7F67E5244EF99796936CF208E35",
59
+ "description": "Item Um",
60
+ "price_cents": 1000,
61
+ "quantity": 1,
62
+ "created_at": "2016-01-06T13:24:20-02:00",
63
+ "updated_at": "2016-01-06T13:24:20-02:00",
64
+ "price": "R$ 10,00"
65
+ }
66
+ ],
67
+ "variables": [
68
+ {
69
+ "id": "06B21226727C4121AC4BDB524DC0DA45",
70
+ "variable": "payer.address.country",
71
+ "value": "Brasil"
72
+ },
73
+ {
74
+ "id": "1D6D9BAA1D4E44F8A428B409371BF12F",
75
+ "variable": "payer.address.zip_code",
76
+ "value":"12122-00"
77
+ },
78
+ {
79
+ "id": "2D26D1E24B1240D1A42EF4826AF758E7",
80
+ "variable": "payer.phone",
81
+ "value": "12121212"
82
+ },
83
+ {
84
+ "id": "34B880D1A6EA4A8F81583B8093AFC548",
85
+ "variable": "payer.phone_prefix",
86
+ "value": "11"
87
+ },
88
+ {
89
+ "id": "5242B104C9F942A6A2891EB17B6AD3B1",
90
+ "variable": "payer.name",
91
+ "value": "Nome do Cliente"
92
+ },
93
+ {
94
+ "id": "605E45FCC8444E22A28BF38A2409582B",
95
+ "variable": "payer.address.number",
96
+ "value": "700"
97
+ },
98
+ {
99
+ "id": "726310D0E206478E8F5609813C35387B",
100
+ "variable": "payment_data.transaction_number",
101
+ "value": "1111"
102
+ },
103
+ {
104
+ "id": "9DEA3D530F12427896818A60BABF753A",
105
+ "variable": "payer.address.street",
106
+ "value": "Rua Tal"
107
+ },
108
+ {
109
+ "id": "A4BD3C27296C440A8EC7F983F75132D8",
110
+ "variable": "payer.cpf_cnpj",
111
+ "value": "12312312312"
112
+ },
113
+ {
114
+ "id": "E66AF99801BA4071ABBD80FDA6A1B534",
115
+ "variable": "payer.address.city",
116
+ "value": "São Paulo"
117
+ },
118
+ {
119
+ "id": "E9197DB3A6A74B9BBA4BCDF2E9553774",
120
+ "variable": "payer.email",
121
+ "value": "spree@example.com"
122
+ },
123
+ {
124
+ "id": "F2711AED42874D61ACC2D893EAAA43E0",
125
+ "variable": "payer.address.state",
126
+ "value": "SP"
127
+ }
128
+ ],
129
+ "custom_variables": [],
130
+ "logs": []
131
+ }
@@ -14,7 +14,7 @@ describe Spree::PaymentMethod::BankSlip, type: :model do
14
14
  it 'payment method should not be auto captured' do
15
15
  expect(object.auto_capture).to be_falsey
16
16
  end
17
-
17
+
18
18
  context 'authorize' do
19
19
 
20
20
  it 'should authorize when Iugu create the invoice' do
@@ -31,7 +31,7 @@ describe Spree::PaymentMethod::BankSlip, type: :model do
31
31
  end
32
32
 
33
33
  it 'should unauthorize when Iugu return error' do
34
- stub_iugu 'create_error'
34
+ stub_iugu({ filename: 'create_error' })
35
35
  Spree::BankSlipConfig[:days_to_due_date] = -10
36
36
  response = object.authorize '1599', slip, slip.payment.gateway_options
37
37
 
@@ -48,12 +48,32 @@ describe Spree::PaymentMethod::BankSlip, type: :model do
48
48
  end
49
49
 
50
50
  context 'void' do
51
+
52
+ let(:headers) do
53
+ {
54
+ 'Accept'=>'application/json', 'Accept-Charset'=>'utf-8',
55
+ 'Accept-Encoding'=>'gzip, deflate', 'Accept-Language'=>'pt-br;q=0.9,pt-BR',
56
+ 'Content-Length'=>'2', 'Content-Type'=>'application/json; charset=utf-8',
57
+ 'User-Agent'=>'Iugu RubyLibrary'
58
+ }
59
+ end
60
+
51
61
  it 'should void successfully' do
52
- object.void '1', slip.payment.gateway_options
62
+ response_code = '1'
63
+ stub_iugu({ filename: 'fetch', method: :get, url: "https://api.iugu.com/v1/invoices/#{response_code}",
64
+ headers: headers, body: '{}' })
65
+ stub_iugu({ filename: 'canceled', method: :put, body: '{}',
66
+ url: "https://api.iugu.com/v1/invoices/#{response_code}/cancel" })
67
+
68
+ object.void response_code, slip.payment.gateway_options
53
69
  expect(slip.reload.canceled?).to be_truthy
54
70
  end
55
71
 
56
72
  it 'should return error when bank slip not found' do
73
+ response_code = '10'
74
+ stub_iugu({ filename: 'fetch', method: :get, url: "https://api.iugu.com/v1/invoices/#{response_code}",
75
+ headers: headers, body: '{}' })
76
+
57
77
  response = object.void 10, slip.payment.gateway_options
58
78
  expect(response.success?).to be_falsey
59
79
  expect(slip.reload.canceled?).to be_falsey
@@ -61,30 +81,35 @@ describe Spree::PaymentMethod::BankSlip, type: :model do
61
81
  end
62
82
 
63
83
  context 'cancel' do
84
+
85
+ let(:headers) do
86
+ {
87
+ 'Accept'=>'application/json', 'Accept-Charset'=>'utf-8',
88
+ 'Accept-Encoding'=>'gzip, deflate', 'Accept-Language'=>'pt-br;q=0.9,pt-BR',
89
+ 'Content-Length'=>'2', 'Content-Type'=>'application/json; charset=utf-8',
90
+ 'User-Agent'=>'Iugu RubyLibrary'
91
+ }
92
+ end
93
+
64
94
  it 'should cancel successfully' do
95
+ response_code = '1'
96
+ stub_iugu({ filename: 'fetch', method: :get, url: "https://api.iugu.com/v1/invoices/#{response_code}",
97
+ headers: headers, body: '{}' })
98
+ stub_iugu({ filename: 'canceled', method: :put, body: '{}',
99
+ url: "https://api.iugu.com/v1/invoices/#{response_code}/cancel" })
100
+
65
101
  object.cancel 1
66
102
  expect(slip.reload.canceled?).to be_truthy
67
103
  end
68
104
 
69
105
  it 'should return error when bank slip not found' do
106
+ response_code = '10'
107
+ stub_iugu({ filename: 'fetch', method: :get, url: "https://api.iugu.com/v1/invoices/#{response_code}",
108
+ headers: headers, body: '{}' })
109
+
70
110
  response = object.cancel 10
71
111
  expect(response.success?).to be_falsey
72
112
  end
73
113
  end
74
114
 
75
- def stub_iugu(filename = 'create')
76
- create_response = JSON.parse File.read("spec/fixtures/iugu_responses/#{filename}.json")
77
-
78
- # Stub da criacao da fatura
79
- stub_request(:post, 'https://api.iugu.com/v1/invoices').
80
- with(headers: {'Accept'=>'application/json',
81
- 'Accept-Charset'=>'utf-8',
82
- 'Accept-Encoding'=>'gzip, deflate',
83
- 'Accept-Language'=>'pt-br;q=0.9,pt-BR',
84
- 'Content-Type'=>'application/json; charset=utf-8',
85
- 'User-Agent'=>'Iugu RubyLibrary'},
86
- body: hash_including({'method' => 'bank_slip'})).
87
- to_return(body: create_response.to_json, status: 200)
88
- end
89
-
90
115
  end
@@ -0,0 +1,21 @@
1
+ def stub_iugu(params = {})
2
+ conf = {
3
+ filename: 'create',
4
+ method: :post,
5
+ url: 'https://api.iugu.com/v1/invoices',
6
+ headers: {'Accept'=>'application/json',
7
+ 'Accept-Charset'=>'utf-8',
8
+ 'Accept-Encoding'=>'gzip, deflate',
9
+ 'Accept-Language'=>'pt-br;q=0.9,pt-BR',
10
+ 'Content-Type'=>'application/json; charset=utf-8',
11
+ 'User-Agent'=>'Iugu RubyLibrary'},
12
+ body: hash_including({'method' => 'bank_slip'})
13
+ }.merge(params)
14
+
15
+ create_response = JSON.parse File.read("spec/fixtures/iugu_responses/#{conf[:filename]}.json")
16
+
17
+ stub_request(conf[:method], conf[:url]).
18
+ with(headers: conf[:headers],
19
+ body: conf[:body]).
20
+ to_return(body: create_response.to_json, status: 200)
21
+ end
@@ -2,16 +2,11 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_iugu_bank_slip'
5
- s.version = '3.0.4.1'
5
+ s.version = '3.0.4.2'
6
6
  s.summary = 'Boleto do Iugu como forma de pagamento no Spree Commerce'
7
7
  s.description = s.summary
8
+ s.required_ruby_version = '>= 2.1.0'
8
9
 
9
- begin
10
- require 'ruby_dep/travis'
11
- s.required_ruby_version = RubyDep::Travis.new.version_constraint
12
- rescue LoadError
13
- abort "Install 'ruby_dep' gem before building this gem"
14
- end
15
10
 
16
11
  s.author = 'Zaez Team'
17
12
  s.email = 'contato@zaez.net'
@@ -45,5 +40,4 @@ Gem::Specification.new do |s|
45
40
  s.add_development_dependency 'guard-rspec'
46
41
  s.add_development_dependency 'guard-shell'
47
42
  s.add_development_dependency 'http_logger'
48
- s.add_development_dependency 'ruby_dep', '~> 1.2'
49
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_iugu_bank_slip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4.1
4
+ version: 3.0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaez Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -318,20 +318,6 @@ dependencies:
318
318
  - - ">="
319
319
  - !ruby/object:Gem::Version
320
320
  version: '0'
321
- - !ruby/object:Gem::Dependency
322
- name: ruby_dep
323
- requirement: !ruby/object:Gem::Requirement
324
- requirements:
325
- - - "~>"
326
- - !ruby/object:Gem::Version
327
- version: '1.2'
328
- type: :development
329
- prerelease: false
330
- version_requirements: !ruby/object:Gem::Requirement
331
- requirements:
332
- - - "~>"
333
- - !ruby/object:Gem::Version
334
- version: '1.2'
335
321
  description: Boleto do Iugu como forma de pagamento no Spree Commerce
336
322
  email: contato@zaez.net
337
323
  executables: []
@@ -372,6 +358,7 @@ files:
372
358
  - lib/spree_iugu_bank_slip/factories.rb
373
359
  - spec/controllers/spree/bank_slips_controller_spec.rb
374
360
  - spec/features/admin/bank_slip_settings_spec.rb
361
+ - spec/fixtures/iugu_responses/canceled.json
375
362
  - spec/fixtures/iugu_responses/create.json
376
363
  - spec/fixtures/iugu_responses/create_error.json
377
364
  - spec/fixtures/iugu_responses/fetch.json
@@ -379,6 +366,7 @@ files:
379
366
  - spec/models/spree/payment_method/bank_slip_spec.rb
380
367
  - spec/spec_helper.rb
381
368
  - spec/support/capybara_login.rb
369
+ - spec/support/stub_iugu.rb
382
370
  - spree_iugu_bank_slip.gemspec
383
371
  homepage: http://zaez.net
384
372
  licenses: []
@@ -389,12 +377,9 @@ require_paths:
389
377
  - lib
390
378
  required_ruby_version: !ruby/object:Gem::Requirement
391
379
  requirements:
392
- - - "~>"
393
- - !ruby/object:Gem::Version
394
- version: '2.2'
395
380
  - - ">="
396
381
  - !ruby/object:Gem::Version
397
- version: 2.2.3
382
+ version: 2.1.0
398
383
  required_rubygems_version: !ruby/object:Gem::Requirement
399
384
  requirements:
400
385
  - - ">="
@@ -410,6 +395,7 @@ summary: Boleto do Iugu como forma de pagamento no Spree Commerce
410
395
  test_files:
411
396
  - spec/controllers/spree/bank_slips_controller_spec.rb
412
397
  - spec/features/admin/bank_slip_settings_spec.rb
398
+ - spec/fixtures/iugu_responses/canceled.json
413
399
  - spec/fixtures/iugu_responses/create.json
414
400
  - spec/fixtures/iugu_responses/create_error.json
415
401
  - spec/fixtures/iugu_responses/fetch.json
@@ -417,3 +403,4 @@ test_files:
417
403
  - spec/models/spree/payment_method/bank_slip_spec.rb
418
404
  - spec/spec_helper.rb
419
405
  - spec/support/capybara_login.rb
406
+ - spec/support/stub_iugu.rb