moip2 1.2.1 → 1.3.1

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 (35) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +1 -1
  3. data/PULL_REQUEST_TEMPLATE.md +13 -0
  4. data/README.md +106 -1
  5. data/changelog.md +21 -1
  6. data/examples/marketplace/create-classical-account-company.rb +4 -2
  7. data/examples/marketplace/create-classical-account-without-company.rb +4 -1
  8. data/lib/moip2.rb +3 -0
  9. data/lib/moip2/accounts_api.rb +14 -2
  10. data/lib/moip2/api.rb +4 -0
  11. data/lib/moip2/entry_api.rb +1 -1
  12. data/lib/moip2/payment_api.rb +4 -0
  13. data/lib/moip2/resource/escrow.rb +9 -0
  14. data/lib/moip2/resource/transfer.rb +9 -0
  15. data/lib/moip2/transfer_api.rb +50 -0
  16. data/lib/moip2/version.rb +1 -1
  17. data/spec/moip2/accounts_api_spec.rb +24 -4
  18. data/spec/moip2/payment_api_spec.rb +14 -0
  19. data/spec/moip2/transfers_spec.rb +155 -0
  20. data/vcr_cassettes/account_doesnt_exist_for_email.yml +44 -0
  21. data/vcr_cassettes/account_doesnt_exist_for_tax_document.yml +44 -0
  22. data/vcr_cassettes/account_exists_for_email.yml +46 -0
  23. data/vcr_cassettes/account_exists_for_tax_document.yml +46 -0
  24. data/vcr_cassettes/create_transfer_success.yml +44 -0
  25. data/vcr_cassettes/find_all_transfers_filters.yml +80 -0
  26. data/vcr_cassettes/find_all_transfers_limit.yml +56 -0
  27. data/vcr_cassettes/find_all_transfers_multi_params.yml +42 -0
  28. data/vcr_cassettes/find_all_transfers_no_query_params.yml +76 -0
  29. data/vcr_cassettes/find_all_transfers_offset.yml +79 -0
  30. data/vcr_cassettes/find_all_transfers_status.yml +76 -0
  31. data/vcr_cassettes/get_transfer.yml +83 -0
  32. data/vcr_cassettes/get_transfer_not_found.yml +42 -0
  33. data/vcr_cassettes/release_escrow.yml +43 -0
  34. data/vcr_cassettes/revert_transfer.yml +42 -0
  35. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c3950765e5a024400c5733ce2359fd79bbec429696dd56d6273729a5a6ef234c
4
- data.tar.gz: 2962c0b09e7098b0882b12f37168091c030c5711e5de7987fa1e1d2e8c58ba66
2
+ SHA1:
3
+ metadata.gz: 9e8a812821aad96dca62b0879d12cd9d980e31fd
4
+ data.tar.gz: 290160cd134386f6cecb44958931a3cab4e4d7e5
5
5
  SHA512:
6
- metadata.gz: 5e7e46aa99da3768b4adb297e93516f58b40880e98020fa7d9e7e73fb9141172b0913ce2de0979d15c7033938035ebcce0a1237e6be7124261e4d94b9b2515d1
7
- data.tar.gz: 4d9d13afc47ffca7f06c8b6e789a1242741b140038ac6b6d54c03fcea8ce45cffe54af6c0614b8c34043fb4c2376d18545e346840dc210d967c8dd8b550a0a3c
6
+ metadata.gz: ce8dd6e7ab5d2b9196ec7b43e570fc0154d595ec39987f2d0ade40884aae0dbf90be03c10117ada4d9e3b2ad1417019381f1331329897da199a4e05f5b5bfbfe
7
+ data.tar.gz: 645180e622c6f8c7fc441ecca446924b845866f0bee060da5f1bf35808ebef47e6747009580bc9fdfa765b4c5f8f3655495bb5894370ed96b961bf8924fe79d7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moip2 (1.2.0)
4
+ moip2 (1.3.0)
5
5
  httparty
6
6
  recursive-open-struct
7
7
 
@@ -0,0 +1,13 @@
1
+ ## PR Summary
2
+
3
+ ## Detailed description
4
+ #### Example:
5
+ - Created Foo
6
+ - Fixed bar when xyz happened
7
+
8
+ ## Checklist
9
+ - [ ] Added tests
10
+ - [ ] All existing and new tests pass
11
+ - [ ] Updated README (if appropriate)
12
+ - [ ] Code lints (Rubocop) successfully
13
+ - [ ] Commits are according to our commit guidelines
data/README.md CHANGED
@@ -61,6 +61,16 @@
61
61
  - [Listagem](#listagem)
62
62
  - [Atualizar conta bancária](#atualizar-conta-bancaria)
63
63
  - [Deletar conta bancária](#deletar-conta-bancaria)
64
+ - [Transferência](#transferência)
65
+ - [Criação](#criação-8)
66
+ -[Conta Bancária](#conta-bancária)
67
+ -[Conta Moip](#conta-moip-1)
68
+ - [Consulta](#consulta-9)
69
+ - [Listagem](#listagem-2)
70
+ - [Reversão](#reversão)
71
+ - [Custódia](#custódia)
72
+ - [Pagamento com custódia](#pagamento-com-custódia)
73
+ - [Liberação de custódia](#liberação-de-custódia)
64
74
  - [OAuth (Moip Connect)](#oauth-(moip-connect))
65
75
  - [Solicitar permissões de acesso ao usuário](#solicitar-permissões-de-acesso-ao-usuário)
66
76
  - [Gerar Token OAuth](#gerar-token-oauth)
@@ -81,6 +91,7 @@
81
91
  - [Tratamento de Exceções](#tratamento-de-exceções)
82
92
  - [Documentação](#documentação)
83
93
  - [Licença](#licença)
94
+ - [Comunidade Slack](#comunidade-slack-) [![Slack](https://user-images.githubusercontent.com/4432322/37355972-ba0e9f32-26c3-11e8-93d3-39917eb24109.png)](https://slackin-cqtchmfquq.now.sh)
84
95
 
85
96
 
86
97
  ## Instalação
@@ -435,7 +446,12 @@ account = api.accounts.show("MPA-12312312312")
435
446
 
436
447
  ### Verifica se usuário já possui Conta Moip
437
448
  ```ruby
438
- api.accounts.exists?("123.456.789.10")
449
+ api.accounts.exists?({tax_document: "123.456.789.10"})
450
+ ```
451
+
452
+ ### ou
453
+ ```ruby
454
+ api.accounts.exists?({email: "dev.moip@labs.moip.com.br"})
439
455
  ```
440
456
 
441
457
  ## Conta bancária
@@ -491,6 +507,91 @@ api.bank_accounts.update("BKA-DWTSK16UQI9N",
491
507
  api.bank_accounts.delete("BKA-DWTSK16UQI9N")
492
508
  ```
493
509
 
510
+ ## Transferência
511
+ ### Criação
512
+ #### Conta Bancária
513
+ ```ruby
514
+ transfer = api.transfer.create(
515
+ amount: 500,
516
+ transferInstrument: {
517
+ method: "BANK_ACCOUNT",
518
+ bankAccount: {
519
+ type: "CHECKING",
520
+ bankNumber: "001",
521
+ agencyNumber: "1111",
522
+ agencyCheckNumber: "2",
523
+ accountNumber: "9999",
524
+ accountCheckNumber: "8",
525
+ holder: {
526
+ fullname: "Nome do Portador",
527
+ taxDocument: {
528
+ type: "CPF",
529
+ number: "22222222222",
530
+ },
531
+ },
532
+ },
533
+ },
534
+ )
535
+ ```
536
+
537
+
538
+ #### Conta Moip
539
+ ```ruby
540
+ transfer = api.transfer.create(
541
+ amount: 500,
542
+ transferInstrument: {
543
+ method: "MOIP_ACCOUNT",
544
+ moipAccount: {
545
+ id: "MPA-B0D880F21EF1",
546
+ },
547
+ },
548
+ )
549
+ ```
550
+
551
+ ### Consulta
552
+ ```ruby
553
+ transfer = api.transfer.show("TRA-28HRLYNLMUFH")
554
+ ```
555
+
556
+ ### Listagem
557
+ ```ruby
558
+ transfers = api.transfer.find_all()
559
+ ```
560
+
561
+ ### Reversão
562
+ ```ruby
563
+ transfer = api.transfer.reverse("TRA-B0W5FD5FCADG")
564
+ ```
565
+ ## Custódia
566
+ ### Pagamento com custódia
567
+ ```ruby
568
+ payment = api.payment.create(order.id,
569
+ {
570
+ installment_count: 1,
571
+ escrow: {
572
+ description: 'Custódia de pagamento'
573
+ },
574
+ funding_instrument: {
575
+ method: "CREDIT_CARD",
576
+ credit_card: {
577
+ expiration_month: 04,
578
+ expiration_year: 18,
579
+ number: "4002892240028922",
580
+ cvc: "123",
581
+ holder: {
582
+ # ...
583
+ }
584
+ }
585
+ }
586
+ }
587
+ )
588
+ ```
589
+
590
+ ### Liberação de custódia
591
+ ```ruby
592
+ escrow = api.payment.release("ECW-JO3U4WIXD0CK")
593
+ ```
594
+
494
595
  ## OAuth (Moip Connect)
495
596
  ### Solicitar permissões de acesso ao usuário
496
597
  ```ruby
@@ -608,3 +709,7 @@ end
608
709
  ## Licença
609
710
 
610
711
  [The MIT License](https://github.com/moip/moip-sdk-ruby/blob/master/LICENSE.txt)
712
+
713
+ ## Comunidade Slack [![Slack](https://user-images.githubusercontent.com/4432322/37355972-ba0e9f32-26c3-11e8-93d3-39917eb24109.png)](https://slackin-cqtchmfquq.now.sh)
714
+
715
+ Tem dúvidas? Fale com a gente no [Slack](https://slackin-cqtchmfquq.now.sh/)!
@@ -1,3 +1,23 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+
8
+ <a name="v1.3.0"></a>
9
+ # [](https://github.com/moip/moip-sdk-ruby/compare/v1.2.1...v1.3.0) (2018-02-19)
10
+
11
+
12
+ #### Features
13
+
14
+ * **Transfer**
15
+ * add transfers support ([4f89d76](https://github.com/moip/moip-sdk-ruby/commit/4f89d76))
16
+
17
+ * **Escrow**
18
+ * add release escrow feature ([ef61c2d](https://github.com/moip/moip-sdk-ruby/commit/ef61c2d))
19
+
20
+
1
21
  <a name="v1.2.1"></a>
2
22
  ## v1.2.1 (2017-12-11)
3
23
 
@@ -6,7 +26,7 @@
6
26
 
7
27
  * **invoices**
8
28
  * fix params on invoice list ((eb12108))
9
-
29
+
10
30
 
11
31
  <a name="v1.2.0"></a>
12
32
  ## v1.2.0 (2017-12-7)
@@ -7,10 +7,12 @@ client = Moip2::Client.new(:sandbox, auth)
7
7
  api = Moip2::Api.new(client)
8
8
 
9
9
  # Check if account exists
10
- api.accounts.exists?("978.443.610-85")
10
+ api.accounts.exists?({tax_document: "978.443.610-85"})
11
11
 
12
- # Create account
12
+ # or
13
+ api.accounts.exists?({email: "dev.moip@labs.moip.com.br"})
13
14
 
15
+ # Create account
14
16
  account = api.accounts.create(
15
17
  email: {
16
18
  address: "dev.moip@labs.moip.com.br",
@@ -7,7 +7,10 @@ client = Moip2::Client.new(:sandbox, auth)
7
7
  api = Moip2::Api.new(client)
8
8
 
9
9
  # Check if account exists
10
- api.accounts.exists?("978.443.610-85")
10
+ api.accounts.exists?({tax_document: "978.443.610-85"})
11
+
12
+ # or
13
+ api.accounts.exists?({email: "dev.moip@labs.moip.com.br"})
11
14
 
12
15
  # Create account
13
16
  account = api.accounts.create(
@@ -11,6 +11,7 @@ require "moip2/resource/account"
11
11
  require "moip2/resource/order"
12
12
  require "moip2/resource/entry"
13
13
  require "moip2/resource/payment"
14
+ require "moip2/resource/transfer"
14
15
  require "moip2/resource/multi_order"
15
16
  require "moip2/resource/multi_payment"
16
17
  require "moip2/resource/customer"
@@ -23,6 +24,7 @@ require "moip2/resource/credit_card"
23
24
  require "moip2/resource/notification"
24
25
  require "moip2/resource/balances"
25
26
  require "moip2/resource/bank_account"
27
+ require "moip2/resource/escrow"
26
28
 
27
29
  require "moip2/response"
28
30
  require "moip2/client"
@@ -31,6 +33,7 @@ require "moip2/order_api"
31
33
  require "moip2/entry_api"
32
34
  require "moip2/multi_order_api"
33
35
  require "moip2/payment_api"
36
+ require "moip2/transfer_api"
34
37
  require "moip2/multi_payment_api"
35
38
  require "moip2/customer_api"
36
39
  require "moip2/invoice_api"
@@ -14,8 +14,10 @@ module Moip2
14
14
  Resource::Account.new client, client.post(base_path, account)
15
15
  end
16
16
 
17
- def exists?(tax_document)
18
- response = client.get("#{base_path}/exists?tax_document=#{tax_document}")
17
+ def exists?(data)
18
+ raise "Use: {email: 'dev@moip.com'} or {tax_document: '999.999.999-99'}" unless has_attribute_to_search(data)
19
+
20
+ response = client.get("#{base_path}/exists?#{to_search(data)}")
19
21
 
20
22
  response.success?
21
23
  end
@@ -23,5 +25,15 @@ module Moip2
23
25
  def show(id)
24
26
  Resource::Account.new client, client.get("#{base_path}/#{id}")
25
27
  end
28
+
29
+ private
30
+
31
+ def has_attribute_to_search(data)
32
+ data.key?(:tax_document) || data.key?(:email)
33
+ end
34
+
35
+ def to_search(data)
36
+ data.key?(:tax_document) ? "tax_document=#{data[:tax_document]}" : "email=#{data[:email]}"
37
+ end
26
38
  end
27
39
  end
@@ -14,6 +14,10 @@ module Moip2
14
14
  Moip2::PaymentApi.new(client)
15
15
  end
16
16
 
17
+ def transfer
18
+ Moip2::TransferApi.new(client)
19
+ end
20
+
17
21
  def balances
18
22
  Moip2::BalancesApi.new(client)
19
23
  end
@@ -13,7 +13,7 @@ module Moip2
13
13
  def show(id)
14
14
  Resource::Entry.new client, client.get("#{base_path}/#{id}")
15
15
  end
16
-
16
+
17
17
  def find_all
18
18
  Resource::Entry.new client, client.get("#{base_path}")
19
19
  end
@@ -21,5 +21,9 @@ module Moip2
21
21
  def void(payment_id)
22
22
  Resource::Payment.new client.post("/v2/payments/#{payment_id}/void", nil)
23
23
  end
24
+
25
+ def release(escrow_id)
26
+ Resource::Escrow.new client.post("/v2/escrows/#{escrow_id}/release", nil)
27
+ end
24
28
  end
25
29
  end
@@ -0,0 +1,9 @@
1
+ module Moip2
2
+ module Resource
3
+ class Escrow < SimpleDelegator
4
+ def intialize(response)
5
+ super(response)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Moip2
2
+ module Resource
3
+ class Transfer < SimpleDelegator
4
+ def intialize(response)
5
+ super(response)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ module Moip2
2
+ class TransferApi
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def create(transfer)
10
+ Resource::Transfer.new client.post(base_path, transfer)
11
+ end
12
+
13
+ def show(transfers_id)
14
+ Resource::Transfer.new client.get("#{base_path}/#{transfers_id}")
15
+ end
16
+
17
+ def find_all(limit: nil, offset: nil, filters: nil, status: nil)
18
+ response = client.get(uri_encode(limit, offset, filters, status))
19
+ Resource::Transfer.new json_to_object(response)
20
+ end
21
+
22
+ def reverse(transfers_id)
23
+ Resource::Transfer.new client.post("#{base_path}/#{transfers_id}/reverse", nil)
24
+ end
25
+
26
+ private
27
+
28
+ def base_path
29
+ "/v2/transfers"
30
+ end
31
+
32
+ def uri_encode(limit, offset, filters, status)
33
+ encoded_filters = Moip2::Util::FiltersEncoder.encode(filters)
34
+
35
+ params = {
36
+ limit: limit,
37
+ offset: offset,
38
+ filters: encoded_filters,
39
+ status: status,
40
+ }.reject { |_, value| value.nil? }
41
+ query_string = URI.encode_www_form(params)
42
+ path = "#{base_path}?#{query_string}"
43
+ end
44
+
45
+ def json_to_object(json)
46
+ json.transfers.map! { |transfer| Resource::Transfer.new transfer }
47
+ json
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Moip2
2
- VERSION = "1.2.1".freeze
2
+ VERSION = "1.3.1".freeze
3
3
  end
@@ -144,8 +144,8 @@ describe Moip2::AccountsApi do
144
144
  describe "#exists" do
145
145
  describe "with a registered tax document" do
146
146
  let(:existence_check) do
147
- VCR.use_cassette("account_exists") do
148
- accounts_api.exists?("436.130.670-21")
147
+ VCR.use_cassette("account_exists_for_tax_document") do
148
+ accounts_api.exists?({tax_document: "436.130.670-21"})
149
149
  end
150
150
  end
151
151
 
@@ -154,8 +154,28 @@ describe Moip2::AccountsApi do
154
154
 
155
155
  describe "with a non registered tax document" do
156
156
  let(:existence_check) do
157
- VCR.use_cassette("account_doesnt_exist") do
158
- accounts_api.exists?("555.000.123-40")
157
+ VCR.use_cassette("account_doesnt_exist_for_tax_document") do
158
+ accounts_api.exists?({tax_document: "555.000.123-40"})
159
+ end
160
+ end
161
+
162
+ it { expect(existence_check).to be false }
163
+ end
164
+
165
+ describe "with a registered email" do
166
+ let(:existence_check) do
167
+ VCR.use_cassette("account_exists_for_email") do
168
+ accounts_api.exists?({email: "dev.moip.1503312536@labs.moip.com.br"})
169
+ end
170
+ end
171
+
172
+ it { expect(existence_check).to be true }
173
+ end
174
+
175
+ describe "with a non registered email" do
176
+ let(:existence_check) do
177
+ VCR.use_cassette("account_doesnt_exist_for_email") do
178
+ accounts_api.exists?({email: "dev.moip.0123456789@labs.moip.com.br"})
159
179
  end
160
180
  end
161
181
 
@@ -133,4 +133,18 @@ describe Moip2::PaymentApi do
133
133
  it { expect(cancelled_payment.funding_instrument).to_not be_nil }
134
134
  it { expect(cancelled_payment.installment_count).to eq 1 }
135
135
  end
136
+
137
+ describe "#release" do
138
+ let(:payment_api_oauth) { described_class.new(sandbox_oauth_client) }
139
+ let (:released_escrow) do
140
+ VCR.use_cassette("release_escrow") do
141
+ payment_api_oauth.release("ECW-JO3U4WIXD0CK")
142
+ end
143
+ end
144
+
145
+ it { expect(released_escrow.id).to eq "ECW-JO3U4WIXD0CK" }
146
+ it { expect(released_escrow.status).to eq "RELEASED" }
147
+ it { expect(released_escrow.description).to eq "Custódia de pagamento" }
148
+ it { expect(released_escrow.amount).to eq 2000 }
149
+ end
136
150
  end