moip2 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +644 -0
  3. data/.travis.yml +14 -3
  4. data/CONTRIBUTING.md +42 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +25 -6
  7. data/Guardfile +1 -2
  8. data/README.md +373 -74
  9. data/Rakefile +2 -2
  10. data/changelog.md +36 -0
  11. data/lib/moip2/accounts_api.rb +27 -0
  12. data/lib/moip2/api.rb +25 -2
  13. data/lib/moip2/auth/basic.rb +2 -5
  14. data/lib/moip2/auth/oauth.rb +0 -3
  15. data/lib/moip2/client.rb +45 -31
  16. data/lib/moip2/connect_api.rb +41 -0
  17. data/lib/moip2/customer_api.rb +16 -2
  18. data/lib/moip2/exceptions/invalid_enviroment_error.rb +0 -2
  19. data/lib/moip2/invoice_api.rb +8 -3
  20. data/lib/moip2/keys_api.rb +14 -14
  21. data/lib/moip2/multi_order_api.rb +1 -3
  22. data/lib/moip2/multi_payment_api.rb +1 -1
  23. data/lib/moip2/notifications_api.rb +33 -0
  24. data/lib/moip2/order_api.rb +18 -3
  25. data/lib/moip2/payment_api.rb +11 -1
  26. data/lib/moip2/refund_api.rb +5 -4
  27. data/lib/moip2/resource/account.rb +12 -0
  28. data/lib/moip2/resource/connect.rb +9 -0
  29. data/lib/moip2/resource/credit_card.rb +12 -0
  30. data/lib/moip2/resource/customer.rb +0 -4
  31. data/lib/moip2/resource/invoice.rb +0 -2
  32. data/lib/moip2/resource/keys.rb +1 -3
  33. data/lib/moip2/resource/multi_order.rb +2 -6
  34. data/lib/moip2/resource/multi_payment.rb +1 -3
  35. data/lib/moip2/resource/notification.rb +12 -0
  36. data/lib/moip2/resource/order.rb +0 -4
  37. data/lib/moip2/resource/payment.rb +0 -4
  38. data/lib/moip2/resource/refund.rb +1 -2
  39. data/lib/moip2/resource/webhooks.rb +11 -13
  40. data/lib/moip2/response.rb +7 -7
  41. data/lib/moip2/util/filters_encoder.rb +28 -0
  42. data/lib/moip2/version.rb +1 -1
  43. data/lib/moip2/webhooks_api.rb +16 -16
  44. data/lib/moip2.rb +10 -5
  45. data/moip2.gemspec +21 -7
  46. data/spec/moip2/accounts_api_spec.rb +189 -0
  47. data/spec/moip2/api_spec.rb +22 -4
  48. data/spec/moip2/auth/basic_spec.rb +8 -4
  49. data/spec/moip2/auth/oauth_spec.rb +4 -4
  50. data/spec/moip2/client_spec.rb +20 -27
  51. data/spec/moip2/connect_api_spec.rb +68 -0
  52. data/spec/moip2/customer_api_spec.rb +147 -72
  53. data/spec/moip2/invoice_spec.rb +51 -32
  54. data/spec/moip2/keys_spec.rb +16 -18
  55. data/spec/moip2/multi_order_api_spec.rb +99 -108
  56. data/spec/moip2/multi_payment_api_spec.rb +8 -11
  57. data/spec/moip2/notifications_api_spec.rb +104 -0
  58. data/spec/moip2/order_api_spec.rb +100 -20
  59. data/spec/moip2/payment_api_spec.rb +77 -17
  60. data/spec/moip2/refund_api_spec.rb +2 -4
  61. data/spec/moip2/resource/order_spec.rb +24 -28
  62. data/spec/moip2/response_spec.rb +0 -8
  63. data/spec/moip2/webhooks_spec.rb +18 -21
  64. data/spec/moip2_spec.rb +6 -13
  65. data/spec/spec_helper.rb +24 -10
  66. data/vcr_cassettes/_create_invoice.yml +42 -0
  67. data/vcr_cassettes/_get_invoice.yml +41 -0
  68. data/vcr_cassettes/account_doesnt_exist.yml +44 -0
  69. data/vcr_cassettes/account_exists.yml +46 -0
  70. data/vcr_cassettes/accounts_show_existent.yml +50 -0
  71. data/vcr_cassettes/accounts_show_nonexistent.yml +42 -0
  72. data/vcr_cassettes/cancel_payment.yml +43 -0
  73. data/vcr_cassettes/capture_payment.yml +42 -0
  74. data/vcr_cassettes/create_account_success_company.yml +87 -0
  75. data/vcr_cassettes/create_account_success_standalone.yml +74 -0
  76. data/vcr_cassettes/create_credit_card_customer.yml +41 -0
  77. data/vcr_cassettes/create_invoice.yml +10 -16
  78. data/vcr_cassettes/create_notification.yml +38 -0
  79. data/vcr_cassettes/create_notification_app.yml +38 -0
  80. data/vcr_cassettes/delete_credit_card_customer.yml +40 -0
  81. data/vcr_cassettes/delete_nonexistent_credit_card_customer.yml +40 -0
  82. data/vcr_cassettes/delete_nonexistent_notification.yml +40 -0
  83. data/vcr_cassettes/delete_notification.yml +36 -0
  84. data/vcr_cassettes/find_all_orders_filters.yml +56 -0
  85. data/vcr_cassettes/find_all_orders_limit.yml +48 -0
  86. data/vcr_cassettes/find_all_orders_multi_filters.yml +57 -0
  87. data/vcr_cassettes/find_all_orders_no_filter.yml +56 -0
  88. data/vcr_cassettes/generate_oauth_token.yml +42 -0
  89. data/vcr_cassettes/get_invoice.yml +10 -15
  90. data/vcr_cassettes/get_keys.yml +1 -1
  91. data/vcr_cassettes/get_notification.yml +38 -0
  92. data/vcr_cassettes/get_notifications_list.yml +38 -0
  93. data/vcr_cassettes/get_payment.yml +42 -0
  94. data/vcr_cassettes/get_payment_not_found.yml +40 -0
  95. data/vcr_cassettes/get_webhooks.yml +1 -1
  96. data/vcr_cassettes/list_invoices.yml +2 -2
  97. data/vcr_cassettes/refresh_oauth_token.yml +40 -0
  98. data/vcr_cassettes/update_invoice.yml +1 -1
  99. metadata +69 -7
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,42 @@
1
+ # Contributing
2
+ :clap::tada: Thank you for taking the time to contribute! :tada::clap:
3
+
4
+ We really value your willingness to contribute to this project. In order to higher the chances of your contribution being accepted, please refer to the following guidelines!
5
+
6
+ ## Steps
7
+
8
+ 1. Fork it!
9
+ 2. Create your feature branch: `git checkout -b feature/xyz develop`
10
+ 3. Commit your changes according to our commit message standards: `git commit -am 'feat(xyz) Added new functionality'`
11
+ 4. Push to your repo: `git push origin feature/xyz`
12
+ 5. Submit a pull request to `develop`
13
+
14
+ ## Workflow
15
+ This repo uses Gitflow as its branch management system. You can learn more about Gitflow [here](https://www.atlassian.com/git/tutorials/comparing-workflows#gitflow-workflow).
16
+ A few quick tips:
17
+ * All feature branches should be based on `develop` and have the format `feature/branch_name`.
18
+ * Minor bug fixes should be based on `master` and have the format `hotfix/branch_name`.
19
+
20
+ ### Commit Conventions
21
+ In order to make the changelog generation easier we recommend the use of messages based on [Conventional Commits](https://conventionalcommits.org/).
22
+
23
+ Examples:
24
+ ```
25
+ feat(orders): added `XYZ` helper function
26
+
27
+ commit description
28
+
29
+ footer notes
30
+ ```
31
+
32
+ ```
33
+ refactor(orders): refactored `ABC` helper function
34
+
35
+ The behaviour of `ABC` was inconsistent and (...)
36
+
37
+ BREAKING CHANGE: return type of `ABC` is now `String`
38
+ ```
39
+
40
+ ```
41
+ docs: updated documentation in Request.php
42
+ ```
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in moip2.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moip2 (0.1.3)
4
+ moip2 (0.1.5)
5
5
  httparty
6
6
  recursive-open-struct
7
7
 
@@ -9,6 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  addressable (2.3.8)
12
+ ast (2.3.0)
12
13
  celluloid (0.16.0)
13
14
  timers (~> 4.0.0)
14
15
  codeclimate-test-reporter (0.4.7)
@@ -35,8 +36,7 @@ GEM
35
36
  guard-compat (~> 1.1)
36
37
  rspec (>= 2.99.0, < 4.0)
37
38
  hitimes (1.2.2)
38
- httparty (0.13.7)
39
- json (~> 1.8)
39
+ httparty (0.14.0)
40
40
  multi_xml (>= 0.5.2)
41
41
  json (1.8.3)
42
42
  listen (2.10.0)
@@ -45,20 +45,26 @@ GEM
45
45
  rb-inotify (>= 0.9)
46
46
  lumberjack (1.0.9)
47
47
  method_source (0.8.2)
48
- multi_xml (0.5.5)
48
+ multi_xml (0.6.0)
49
49
  nenv (0.2.0)
50
50
  notiffany (0.0.6)
51
51
  nenv (~> 0.1)
52
52
  shellany (~> 0.0)
53
+ parallel (1.11.2)
54
+ parser (2.4.0.0)
55
+ ast (~> 2.2)
56
+ powerpack (0.1.1)
53
57
  pry (0.10.1)
54
58
  coderay (~> 1.1.0)
55
59
  method_source (~> 0.8.1)
56
60
  slop (~> 3.4)
61
+ rainbow (2.2.2)
62
+ rake
57
63
  rake (10.4.2)
58
64
  rb-fsevent (0.9.5)
59
65
  rb-inotify (0.9.5)
60
66
  ffi (>= 0.5.0)
61
- recursive-open-struct (0.6.5)
67
+ recursive-open-struct (1.0.2)
62
68
  rspec (3.3.0)
63
69
  rspec-core (~> 3.3.0)
64
70
  rspec-expectations (~> 3.3.0)
@@ -72,6 +78,14 @@ GEM
72
78
  diff-lcs (>= 1.2.0, < 2.0)
73
79
  rspec-support (~> 3.3.0)
74
80
  rspec-support (3.3.0)
81
+ rubocop (0.49.1)
82
+ parallel (~> 1.10)
83
+ parser (>= 2.3.3.1, < 3.0)
84
+ powerpack (~> 0.1)
85
+ rainbow (>= 1.99.1, < 3.0)
86
+ ruby-progressbar (~> 1.7)
87
+ unicode-display_width (~> 1.0, >= 1.0.1)
88
+ ruby-progressbar (1.8.1)
75
89
  safe_yaml (1.0.4)
76
90
  shellany (0.0.1)
77
91
  simplecov (0.10.0)
@@ -83,6 +97,7 @@ GEM
83
97
  thor (0.19.1)
84
98
  timers (4.0.1)
85
99
  hitimes
100
+ unicode-display_width (1.3.0)
86
101
  vcr (2.9.3)
87
102
  webmock (1.21.0)
88
103
  addressable (>= 2.3.6)
@@ -92,11 +107,15 @@ PLATFORMS
92
107
  ruby
93
108
 
94
109
  DEPENDENCIES
95
- bundler (~> 1.5)
110
+ bundler
96
111
  codeclimate-test-reporter
97
112
  guard-rspec
98
113
  moip2!
99
114
  rake
100
115
  rspec
116
+ rubocop (= 0.49.1)
101
117
  vcr
102
118
  webmock
119
+
120
+ BUNDLED WITH
121
+ 1.15.1
data/Guardfile CHANGED
@@ -4,6 +4,5 @@
4
4
  guard :rspec do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
7
+ watch("spec/spec_helper.rb") { "spec" }
8
8
  end
9
-
data/README.md CHANGED
@@ -1,10 +1,70 @@
1
+ <img src="https://gist.githubusercontent.com/joaolucasl/00f53024cecf16410d5c3212aae92c17/raw/1789a2131ee389aeb44e3a9d5333f59cfeebc089/moip-icon.png" align="right" />
2
+
1
3
  # Moip v2 Ruby SDK
4
+ > O jeito mais simples e rápido de integrar o Moip a sua aplicação Ruby
2
5
 
3
6
  [![Build Status](https://travis-ci.org/moip/moip-sdk-ruby.svg?branch=master)](https://travis-ci.org/moip/moip-sdk-ruby)
4
7
  [![Code Climate](https://codeclimate.com/github/moip/moip-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/moip/moip-sdk-ruby)
5
8
  [![Test Coverage](https://codeclimate.com/github/moip/moip-sdk-ruby/badges/coverage.svg)](https://codeclimate.com/github/moip/moip-sdk-ruby/coverage)
6
9
 
7
- O jeito mais simples e rápido de integrar o Moip a sua aplicação Ruby
10
+ **Índice**
11
+
12
+ - [Instalação](#instalação)
13
+ - [Configurando a autenticação](#configurando-a-autenticação)
14
+ - [Por BasicAuth](#por-basicauth)
15
+ - [Por OAuth](#por-oauth)
16
+ - [Configurando o ambiente](#configurando-o-ambiente)
17
+ - [Exemplos de Uso](#clientes):
18
+ - [Clientes](#clientes)
19
+ - [Criação](#criação)
20
+ - [Consulta](#consulta)
21
+ - [Adicionar cartão de crédito](#adicionar-cartão-de-crédito)
22
+ - [Deletar cartão de crédito](#deletar-cartão-de-crédito)
23
+ - [Pedidos](#pedidos)
24
+ - [Criação](#criação-1)
25
+ - [Consulta](#consulta-1)
26
+ - [Pedido Específico](#pedido-específico)
27
+ - [Todos os Pedidos](#todos-os-pedidos)
28
+ - [Sem Filtro](#sem-filtro)
29
+ - [Com Filtros](#com-filtros)
30
+ - [Com Paginação](#com-paginação)
31
+ - [Pagamentos](#pagamentos)
32
+ - [Criação](#criação-2)
33
+ - [Cartão de Crédito](#cartão-de-crédito)
34
+ - [Com Hash](#com-hash)
35
+ - [Com Dados do Cartão](#com-dados-do-cartão)
36
+ - [Com Boleto](#com-boleto)
37
+ - [Consulta](#consulta-2)
38
+ - [Capturar pagamento pré-autorizado](#capturar-pagamento-pré-autorizado)
39
+ - [Cancelar pagamento pré-autorizado](#cancelar-pagamento-pré-autorizado)
40
+ - [Reembolsos](#reembolsos)
41
+ - [Criação](#criação-3)
42
+ - [Valor Total](#valor-total)
43
+ - [Valor Parcial](#valor-parcial)
44
+ - [Consulta](#consulta-3)
45
+ - [Multipedidos](#multipedidos)
46
+ - [Criação](#criação-4)
47
+ - [Consulta](#consulta-4)
48
+ - [Multipagamentos](#multipagamentos)
49
+ - [Criação](#criação-5)
50
+ - [Consulta](#consulta-5)
51
+ - [Conta Moip](#conta-moip)
52
+ - [Criação](#criação-6)
53
+ - [Consulta](#consulta-6)
54
+ - [Verifica se usuário já possui Conta Moip](#verifica-se-usuário-já-possui-conta-moip)
55
+ - [OAuth (Moip Connect)](#oauth-(moip-connect))
56
+ - [Solicitar permissões de acesso ao usuário](#solicitar-permissões-de-acesso-ao-usuário)
57
+ - [Gerar Token OAuth](#gerar-token-oauth)
58
+ - [Atualizar Token OAuth](#atualizar-token-oauth)
59
+ - [Preferências de Notificação](#preferências-de-notificação)
60
+ - [Criação](#criação-7)
61
+ - [Consulta](#consulta-7)
62
+ - [Exclusão](#exclusão)
63
+ - [Listagem](#listagem)
64
+ - [Tratamento de Exceções](#tratamento-de-exceções)
65
+ - [Documentação](#documentação)
66
+ - [Licença](#licença)
67
+
8
68
 
9
69
  ## Instalação
10
70
 
@@ -14,91 +74,145 @@ Adicione a seguinte linha no seu Gemfile:
14
74
  gem "moip2"
15
75
  ```
16
76
 
17
- ## Configurando sua autenticação
18
- - Autenticando por BasicAuth
77
+ ## Configurando a autenticação
78
+ ### Por BasicAuth
19
79
  ```ruby
20
80
  auth = Moip2::Auth::Basic.new("TOKEN", "SECRET")
21
81
  ```
22
- - Autenticando por OAuth
82
+ ### Por OAuth
23
83
  ```ruby
24
84
  auth = Moip2::Auth::OAuth.new("TOKEN_OAUTH")
25
85
  ```
26
86
 
27
- Após deifinir o tipo de autenticação, é necessário gerar o client, informando em qual environment você quer executar suas ações:
87
+ ## Configurando o ambiente
88
+ Após definir o tipo de autenticação, é necessário gerar o client, informando em qual ambiente você quer executar suas ações:
28
89
  ```ruby
29
90
  client = Moip2::Client.new(:sandbox/:production, auth)
30
91
  ```
31
92
 
32
- Agora você pode instanciar a Api:
93
+ Após isso, é necessário instanciar um ponto de acesso a partir do qual você utilizará as funções da API:
94
+
33
95
  ```ruby
34
96
  api = Moip2::Api.new(client)
35
97
  ```
36
98
 
37
- ## Criando um Pedido
99
+ ## Clientes
100
+ ### Criação
101
+ ```ruby
102
+ customer = api.customer.create({
103
+ ownId: "meu_id_de_cliente",
104
+ fullname: "Jose Silva",
105
+ email: "josedasilva@email.com",
106
+ phone: {
107
+ #...
108
+ },
109
+ birthDate: "1988-12-30",
110
+ taxDocument: {
111
+ #...
112
+ },
113
+ shippingAddress: {
114
+ #...
115
+ },
116
+ fundingInstrument: {
117
+ # Campo opcional. Consulte a documentação da API.
118
+ }
119
+ })
120
+ ```
121
+ ### Consulta
122
+ ```ruby
123
+ customer = api.customer.show("CUS-V41BR451L")
124
+ ```
38
125
 
126
+ ### Adicionar cartão de crédito
39
127
  ```ruby
40
- order = api.order.create(
128
+ credit_card = api.customer.add_credit_card("CUSTOMER-ID",
41
129
  {
42
- own_id: "ruby_sdk_1",
43
- items: [
44
- {
45
- product: "Nome do produto",
46
- quantity: 1,
47
- detail: "Mais info...",
48
- price: 1000
49
- }
50
- ],
51
- customer: {
52
- own_id: "ruby_sdk_customer_1",
53
- fullname: "Jose da Silva",
54
- email: "sandbox_v2_1401147277@email.com",
55
- }
130
+ method: "CREDIT_CARD",
131
+ creditCard: {
132
+ expirationMonth: "05",
133
+ expirationYear: "22",
134
+ number: "5555666677778884",
135
+ cvc: "123",
136
+ holder: {
137
+ fullname: "Jose Portador da Silva",
138
+ birthdate: "1988-12-30",
139
+ taxDocument: {
140
+ type: "CPF",
141
+ number: "33333333333",
142
+ },
143
+ phone: {
144
+ countryCode: "55",
145
+ areaCode: "11",
146
+ number: "66778899",
147
+ },
148
+ },
149
+ },
56
150
  }
57
151
  )
58
152
  ```
59
153
 
60
- ### Pedido com dados completos do Comprador
154
+ ### Deletar cartão de crédito
155
+
156
+ > Retorna uma Exception do tipo `NotFoundError` caso não encontre o cartão de crédito para deletar
157
+
158
+ ```ruby
159
+ api.customer.delete_credit_card!("CREDIT-CARD-ID")
160
+ ```
161
+
162
+ > Retorna `false` caso não encontre o cartão de crédito para deletar
163
+
164
+ ```ruby
165
+ api.customer.delete_credit_card("CREDIT-CARD-ID")
166
+ ```
61
167
 
62
- Agora basta criar o pedido:
168
+ ## Pedidos
169
+ ### Criação
63
170
 
64
171
  ```ruby
65
- order = api.order.create(
172
+ order = api.order.create({
173
+ own_id: "ruby_sdk_1",
174
+ items: [
66
175
  {
67
- own_id: "ruby_sdk_1",
68
- items: [
69
- {
70
- product: "Nome do produto",
71
- quantity: 1,
72
- detail: "Mais info...",
73
- price: 1000
74
- }
75
- ],
76
- customer: {
77
- own_id: "ruby_sdk_customer_1",
78
- fullname: "Jose da Silva",
79
- email: "sandbox_v2_1401147277@email.com",
80
- birthdate: "1988-12-30",
81
- tax_document: { number: "33333333333", type: "CPF" },
82
- phone: { country_code: "55", area_code: "11", number: "66778899" },
83
- shipping_address:
84
- {
85
- street: "Avenida Faria Lima",
86
- street_number: 2927,
87
- complement: 8,
88
- district: "Itaim",
89
- city: "Sao Paulo",
90
- state: "SP",
91
- country: "BRA",
92
- zip_code: "01234000"
93
- }
94
- }
176
+ product: "Nome do produto",
177
+ quantity: 1,
178
+ detail: "Mais info...",
179
+ price: 1000
95
180
  }
96
- )
181
+ ],
182
+ customer: {
183
+ own_id: "ruby_sdk_customer_1",
184
+ fullname: "Jose da Silva",
185
+ email: "sandbox_v2_1401147277@email.com",
186
+ }
187
+ })
188
+ ```
189
+ ### Consulta
190
+ #### Pedido Específico
191
+ ```ruby
192
+ order = api.order.show("ORD-V41BR451L")
193
+ ```
194
+
195
+ #### Todos os Pedidos
196
+ ##### Sem Filtro
197
+ ```ruby
198
+ orders = api.order.find_all()
199
+ ```
200
+
201
+ ##### Com Filtros
202
+ ```ruby
203
+ orders = api.order.find_all(filters: { status: { in: ["PAID", "WAITING"] }, amount: { bt: [500, 1000] } })
97
204
  ```
98
205
 
99
- ## Criando um pagamento
206
+ ##### Com Paginação
207
+ ```ruby
208
+ orders = api.order.find_all(limit: 10, offset: 50)
209
+ ```
100
210
 
101
- ### Cartão de crédito com hash
211
+ ## Pagamentos
212
+
213
+ ### Criação
214
+ #### Cartão de Crédito
215
+ ##### Com Hash
102
216
 
103
217
  ```ruby
104
218
  api.payment.create(order.id,
@@ -107,7 +221,7 @@ api.payment.create(order.id,
107
221
  funding_instrument: {
108
222
  method: "CREDIT_CARD",
109
223
  credit_card: {
110
- hash: "valor do cartã criptografado vindo do JS",
224
+ hash: "valor do cartão criptografado vindo do JS",
111
225
  holder: {
112
226
  fullname: "Jose Portador da Silva",
113
227
  birthdate: "1988-10-10",
@@ -122,7 +236,8 @@ api.payment.create(order.id,
122
236
  )
123
237
  ```
124
238
 
125
- ### Cartão de crédito
239
+ ##### Com Dados do Cartão
240
+ > Esses método requer certificação PCI. [Consulte a documentação.](https://documentao-moip.readme.io/v2.0/reference#criar-pagamento)
126
241
 
127
242
  ```ruby
128
243
  api.payment.create(order.id,
@@ -133,20 +248,10 @@ api.payment.create(order.id,
133
248
  credit_card: {
134
249
  expiration_month: 04,
135
250
  expiration_year: 18,
136
- number: "4012001038443335",
251
+ number: "4002892240028922",
137
252
  cvc: "123",
138
253
  holder: {
139
- fullname: "Jose Portador da Silva",
140
- birthdate: "1988-10-10",
141
- tax_document: {
142
- type: "CPF",
143
- number: "22222222222"
144
- },
145
- phone: {
146
- country_code: "55",
147
- area_code: "11",
148
- number: "55667788"
149
- }
254
+ # ...
150
255
  }
151
256
  }
152
257
  }
@@ -154,26 +259,220 @@ api.payment.create(order.id,
154
259
  )
155
260
  ```
156
261
 
157
- ### Boleto
262
+ #### Com Boleto
158
263
 
159
264
  ```ruby
160
- api.payment.create(
265
+ api.payment.create(order.id,
161
266
  {
267
+ # ...
162
268
  funding_instrument: {
163
269
  method: "BOLETO",
164
270
  boleto: {
165
- expiration_date: "2015-09-30",
271
+ expiration_date: "2017-09-30",
166
272
  instruction_lines: {
167
273
  first: "Primeira linha do boleto",
168
274
  second: "Segunda linha do boleto",
169
275
  third: "Terceira linha do boleto"
170
276
  },
171
- logo_uri: "https://"
277
+ logo_uri: "https://sualoja.com.br/logo.jpg"
172
278
  }
173
279
  }
174
280
  }
175
281
  )
176
282
  ```
283
+
284
+ ### Consulta
285
+ ```ruby
286
+ pagamento = api.payment.show("PAY-CRUP19YU2VE1")
287
+ ```
288
+
289
+ ### Capturar pagamento pré-autorizado
290
+ ```ruby
291
+ api.payment.capture("PAY-KT5OSI01X8QU")
292
+ ```
293
+
294
+ ### Cancelar pagamento pré-autorizado
295
+ ```ruby
296
+ api.payment.void("PAY-IXNGCU456GG4")
297
+ ```
298
+
299
+ ## Reembolsos
300
+ ### Criação
301
+ #### Valor Total
302
+ ```ruby
303
+ reembolso = api.refund.create("ORD-V41BR451L")
304
+ ```
305
+ #### Valor Parcial
306
+ ```ruby
307
+ reembolso = api.refund.create("ORD-V41BR451L", amount: 2000)
308
+ ```
309
+
310
+ ### Consulta
311
+ ```ruby
312
+ reembolso = api.refund.show("REF-V41BR451L")
313
+ ```
314
+
315
+ ## Multipedidos
316
+ ### Criação
317
+ ```ruby
318
+ multi = api.multi_order.create(
319
+ {
320
+ ownId: "meu_multiorder_id",
321
+ orders: [
322
+ {
323
+ # Objeto Order 1
324
+ },
325
+ {
326
+ # Objeto Order 2
327
+ }
328
+ ]
329
+ }
330
+ )
331
+ ```
332
+ ### Consulta
333
+ ```ruby
334
+ multi = api.multi_order.show("MOR-V41BR451L")
335
+ ```
336
+ ### Nota
337
+ > 1. Essa função depende de permissões das contas associadas ao recebimento. [Consulte a documentação.](https://documentao-moip.readme.io/v2.0/reference#multipedidos)
338
+ > 2. Para reembolsos de multipedidos, é necessario reembolsar os pedidos individualmente. [Consulte a documentação.](https://documentao-moip.readme.io/v2.0/reference#multipedidos)
339
+
340
+ ## Multipagamentos
341
+ ### Criação
342
+ ```ruby
343
+ multi_pag = api.multi_payment.create("MOR-V41BR451L",
344
+ {
345
+ installmentCount: 1,
346
+ fundingInstrument: {
347
+ # ...
348
+ }
349
+ }
350
+ )
351
+ ```
352
+ ### Consulta
353
+ ```ruby
354
+ multi_pag = api.multi_payment.show("MPY-V41BR451L")
355
+ ```
356
+
357
+ ## Conta Moip
358
+ ### Criação
359
+ ```ruby
360
+ account = api.accounts.create(
361
+ {
362
+ email: {
363
+ address: "dev.moip@labs.moip.com.br",
364
+ },
365
+ person: {
366
+ name: "Joaquim José",
367
+ lastName: "Silva Silva",
368
+ taxDocument: {
369
+ type: "CPF",
370
+ number: "572.619.050-54",
371
+ },
372
+ identityDocument: {
373
+ type: "RG",
374
+ number: "35.868.057-8",
375
+ issuer: "SSP",
376
+ issueDate: "2000-12-12",
377
+ },
378
+ birthDate: "1990-01-01",
379
+ phone: {
380
+ countryCode: "55",
381
+ areaCode: "11",
382
+ number: "965213244",
383
+ },
384
+ address: {
385
+ street: "Av. Brigadeiro Faria Lima",
386
+ streetNumber: "2927",
387
+ district: "Itaim",
388
+ zipCode: "01234-000",
389
+ city: "S\u00E3o Paulo",
390
+ state: "SP",
391
+ country: "BRA",
392
+ },
393
+ },
394
+ type: "MERCHANT"
395
+ }
396
+ )
397
+ ```
398
+
399
+ ### Consulta
400
+ ```ruby
401
+ account = api.accounts.show("MPA-12312312312")
402
+ ```
403
+
404
+ ### Verifica se usuário já possui Conta Moip
405
+ ```ruby
406
+ api.accounts.exists?("123.456.789.10")
407
+ ```
408
+
409
+ ## OAuth (Moip Connect)
410
+ ### Solicitar permissões de acesso ao usuário
411
+ ```ruby
412
+ api.connect.authorize_url("APP-ID","http://localhost/moip/callback","RECEIVE_FUNDS,REFUND")
413
+ ```
414
+
415
+ ### Gerar token OAuth
416
+ ```ruby
417
+ api.connect.authorize(
418
+ client_id: "APP-YRYCCJ5P603B",
419
+ client_secret: "363cdf8ab70a4c5aa08017564c08efbe",
420
+ code: "4efde1f89d9acc3b12124ccfded146518465e423",
421
+ redirect_uri: "http://localhost/moip/callback",
422
+ grant_type: "authorization_code"
423
+ )
424
+ ```
425
+
426
+ ### Atualizar token OAuth
427
+ ```ruby
428
+ api.connect.authorize(
429
+ refresh_token: "1d5dc51e71674683b4ed79cd7a988fa1_v2",
430
+ grant_type: "refresh_token"
431
+ )
432
+ ```
433
+
434
+ ## Preferências de notificação
435
+
436
+ ### Criação
437
+ ```ruby
438
+ api.notifications.create(
439
+ events: ["ORDER.*", "PAYMENT.AUTHORIZED", "PAYMENT.CANCELLED"],
440
+ target: "http://requestb.in/1dhjesw1",
441
+ media: "WEBHOOK"
442
+ )
443
+ ```
444
+
445
+ ### Consulta
446
+ ```ruby
447
+ api.notifications.show("NOTIFICATION-ID")
448
+ ```
449
+
450
+ ### Exclusão
451
+ > Caso o notification não seja encontrado uma exceção do tipo `NotFoundError` será lançada, veja como tratar [aqui](#tratamento-de-exceções).
452
+
453
+ ```ruby
454
+ api.notifications.delete("NOTIFICATION-ID")
455
+ ```
456
+
457
+ ### Listagem
458
+ ```ruby
459
+ api.notifications.find_all
460
+ ```
461
+
462
+ ## Tratamento de Exceções
463
+
464
+ Caso algum recurso não seja encontrado uma exceção do tipo `NotFoundError` será lançada.
465
+
466
+ ```ruby
467
+ begin
468
+ api.payment.create(
469
+ # ...
470
+ )
471
+ rescue NotFoundError => e
472
+ puts e.message
473
+ end
474
+ ```
475
+
177
476
  ## Documentação
178
477
 
179
478
  [Documentação oficial](https://moip.com.br/referencia-api/)
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
3
  begin
4
- require 'rspec/core/rake_task'
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- task :default => :spec
8
+ task default: :spec
9
9
  rescue LoadError
10
10
  # no rspec available
11
11
  end