moip2 1.0.0 → 1.1.0

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 (66) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +6 -12
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +4 -4
  5. data/README.md +142 -14
  6. data/changelog.md +55 -3
  7. data/examples/ecommerce/payment-with-boleto.rb +129 -0
  8. data/examples/ecommerce/payment-with-credit-card.rb +119 -0
  9. data/examples/ecommerce/payment-with-hash.rb +101 -0
  10. data/examples/marketplace/create-classical-account-company.rb +74 -0
  11. data/examples/marketplace/create-classical-account-without-company.rb +47 -0
  12. data/examples/marketplace/moip-connect.rb +31 -0
  13. data/examples/marketplace/payment-with-escrow.rb +88 -0
  14. data/examples/marketplace/payment-with-pre-authorization.rb +87 -0
  15. data/examples/marketplace/shared-cart.rb +220 -0
  16. data/lib/moip2/api.rb +17 -2
  17. data/lib/moip2/balances_api.rb +18 -0
  18. data/lib/moip2/bank_accounts_api.rb +51 -0
  19. data/lib/moip2/client.rb +11 -11
  20. data/lib/moip2/connect_api.rb +2 -13
  21. data/lib/moip2/connect_client.rb +11 -0
  22. data/lib/moip2/entry_api.rb +21 -0
  23. data/lib/moip2/multi_payment_api.rb +8 -0
  24. data/lib/moip2/order_api.rb +2 -1
  25. data/lib/moip2/resource/balances.rb +12 -0
  26. data/lib/moip2/resource/bank_account.rb +12 -0
  27. data/lib/moip2/resource/entry.rb +13 -0
  28. data/lib/moip2/version.rb +1 -1
  29. data/lib/moip2/webhooks_api.rb +20 -4
  30. data/lib/moip2.rb +7 -0
  31. data/moip2.gemspec +2 -0
  32. data/spec/moip2/balances_api_spec.rb +22 -0
  33. data/spec/moip2/bank_accounts_api_spec.rb +173 -0
  34. data/spec/moip2/client_spec.rb +13 -76
  35. data/spec/moip2/connect_api_spec.rb +1 -1
  36. data/spec/moip2/connect_client_spec.rb +63 -0
  37. data/spec/moip2/customer_api_spec.rb +3 -3
  38. data/spec/moip2/entry_api_spec.rb +43 -0
  39. data/spec/moip2/multi_payment_api_spec.rb +32 -2
  40. data/spec/moip2/order_api_spec.rb +24 -1
  41. data/spec/moip2/response_spec.rb +2 -6
  42. data/spec/moip2/webhooks_spec.rb +87 -11
  43. data/spec/moip2_spec.rb +1 -1
  44. data/spec/spec_helper.rb +3 -14
  45. data/vcr_cassettes/bank_account_create_fail.yml +39 -0
  46. data/vcr_cassettes/bank_account_create_sucess.yml +41 -0
  47. data/vcr_cassettes/bank_account_deleted_existent.yml +38 -0
  48. data/vcr_cassettes/bank_account_deleted_nonexistent.yml +38 -0
  49. data/vcr_cassettes/bank_account_find_all.yml +9525 -0
  50. data/vcr_cassettes/bank_account_show_existent.yml +40 -0
  51. data/vcr_cassettes/bank_account_show_nonexistent.yml +38 -0
  52. data/vcr_cassettes/bank_account_update.yml +41 -0
  53. data/vcr_cassettes/capture_multi_payment_sucess.yml +44 -0
  54. data/vcr_cassettes/find_all_entries.yml +63 -0
  55. data/vcr_cassettes/find_all_orders_q_search.yml +39 -0
  56. data/vcr_cassettes/{get_webhooks.yml → find_all_webhooks.yml} +1 -1
  57. data/vcr_cassettes/find_all_webhooks_event.yml +42 -0
  58. data/vcr_cassettes/find_all_webhooks_limit.yml +48 -0
  59. data/vcr_cassettes/find_all_webhooks_multi_params.yml +38 -0
  60. data/vcr_cassettes/find_all_webhooks_no_filter.yml +58 -0
  61. data/vcr_cassettes/find_all_webhooks_offset.yml +58 -0
  62. data/vcr_cassettes/find_all_webhooks_resource_id.yml +38 -0
  63. data/vcr_cassettes/get_balances.yml +44 -0
  64. data/vcr_cassettes/show_entries.yml +43 -0
  65. data/vcr_cassettes/void_multi_payment_sucess.yml +46 -0
  66. metadata +50 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 015adab12411ead291fe058fd03c731acec47181
4
- data.tar.gz: cee1090c633e11fb965d57be09ff0f6970c33cf7
2
+ SHA256:
3
+ metadata.gz: 00d898f2cb2434c403e3c3bd39d3796bdb03f8c8f84d518f6b85007cda8abdfe
4
+ data.tar.gz: c6492ffd7175b9eb2f3ed6988193e209dbac777a022f1f60f670b417a0314abb
5
5
  SHA512:
6
- metadata.gz: 63ec3ecf7c8493d551fd136bd34c461a8722d60d6b291cda2f7d2df05894f553de8e35a3dc3c8fe70532f581ef10252f35357cae4030b6e74537eae36302faa9
7
- data.tar.gz: 73844787d62a4904870d36729665522ee0c9055b97fd3110be7568ee6f6cb13bc79e5d2ec31098fd3f7417448ab2acd2584be8e27403ea49069505fd67e89018
6
+ metadata.gz: 5f421da475b278633400cce50d16c982459440ae97f587a570101408fa805fd950b91d741a83aaea7871c4679866f905e2626d8d2b44d6359d45da1c80484018
7
+ data.tar.gz: 123a11f6907d8be0d5728d359bf724c76ca395ef0b8adab8bc372b48fafb5477dabfa2caba5298b3975488e33936c796eb5e30623a37336db08be7ad578b737f
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # Adapted from Thoughtbot's recommended config (https://github.com/thoughtbot/guides/blob/master/style/ruby/.rubocop.yml)
2
2
 
3
- Style/AccessorMethodName:
3
+ Naming/AccessorMethodName:
4
4
  Description: Check the naming of accessor methods for get_/set_.
5
5
  Enabled: false
6
6
 
@@ -19,7 +19,7 @@ Style/AsciiComments:
19
19
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments'
20
20
  Enabled: false
21
21
 
22
- Style/AsciiIdentifiers:
22
+ Naming/AsciiIdentifiers:
23
23
  Description: 'Use only ascii symbols in identifiers.'
24
24
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers'
25
25
  Enabled: false
@@ -139,7 +139,7 @@ Style/EvenOdd:
139
139
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
140
140
  Enabled: false
141
141
 
142
- Style/FileName:
142
+ Naming/FileName:
143
143
  Description: 'Use snake_case for source file names.'
144
144
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
145
145
  Enabled: false
@@ -264,7 +264,7 @@ Style/OneLineConditional:
264
264
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator'
265
265
  Enabled: false
266
266
 
267
- Style/OpMethod:
267
+ Naming/BinaryOperatorParameterName:
268
268
  Description: 'When defining binary operators, name the argument other.'
269
269
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#other-arg'
270
270
  Enabled: false
@@ -284,7 +284,7 @@ Style/PerlBackrefs:
284
284
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
285
285
  Enabled: false
286
286
 
287
- Style/PredicateName:
287
+ Naming/PredicateName:
288
288
  Description: 'Check the names of predicate methods.'
289
289
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark'
290
290
  NamePrefixBlacklist:
@@ -480,12 +480,6 @@ Lint/HandleExceptions:
480
480
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
481
481
  Enabled: false
482
482
 
483
- Lint/InvalidCharacterLiteral:
484
- Description: >-
485
- Checks for invalid character literals with a non-escaped
486
- whitespace character.
487
- Enabled: false
488
-
489
483
  Lint/LiteralInCondition:
490
484
  Description: 'Checks of literals used in conditions.'
491
485
  Enabled: false
@@ -641,4 +635,4 @@ Rails/TimeZone:
641
635
 
642
636
  Rails/Validation:
643
637
  Description: 'Use validates :attribute, hash of validations.'
644
- Enabled: false
638
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "https://rubygems.org"
2
-
3
2
  # Specify your gem's dependencies in moip2.gemspec
4
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moip2 (0.1.5)
4
+ moip2 (1.0.0)
5
5
  httparty
6
6
  recursive-open-struct
7
7
 
@@ -36,7 +36,7 @@ GEM
36
36
  guard-compat (~> 1.1)
37
37
  rspec (>= 2.99.0, < 4.0)
38
38
  hitimes (1.2.2)
39
- httparty (0.14.0)
39
+ httparty (0.15.5)
40
40
  multi_xml (>= 0.5.2)
41
41
  json (1.8.3)
42
42
  listen (2.10.0)
@@ -64,7 +64,7 @@ GEM
64
64
  rb-fsevent (0.9.5)
65
65
  rb-inotify (0.9.5)
66
66
  ffi (>= 0.5.0)
67
- recursive-open-struct (1.0.2)
67
+ recursive-open-struct (1.0.5)
68
68
  rspec (3.3.0)
69
69
  rspec-core (~> 3.3.0)
70
70
  rspec-expectations (~> 3.3.0)
@@ -118,4 +118,4 @@ DEPENDENCIES
118
118
  webmock
119
119
 
120
120
  BUNDLED WITH
121
- 1.15.1
121
+ 1.16.0.pre.2
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Code Climate](https://codeclimate.com/github/moip/moip-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/moip/moip-sdk-ruby)
8
8
  [![Test Coverage](https://codeclimate.com/github/moip/moip-sdk-ruby/badges/coverage.svg)](https://codeclimate.com/github/moip/moip-sdk-ruby/coverage)
9
9
 
10
- **Índice**
10
+ **Índice**
11
11
 
12
12
  - [Instalação](#instalação)
13
13
  - [Configurando a autenticação](#configurando-a-autenticação)
@@ -28,6 +28,7 @@
28
28
  - [Sem Filtro](#sem-filtro)
29
29
  - [Com Filtros](#com-filtros)
30
30
  - [Com Paginação](#com-paginação)
31
+ - [Consulta Valor Específico](#consulta-valor-específico)
31
32
  - [Pagamentos](#pagamentos)
32
33
  - [Criação](#criação-2)
33
34
  - [Cartão de Crédito](#cartão-de-crédito)
@@ -48,19 +49,35 @@
48
49
  - [Multipagamentos](#multipagamentos)
49
50
  - [Criação](#criação-5)
50
51
  - [Consulta](#consulta-5)
52
+ - [Capturar multipagamento pré-autorizado](#capturar-multipagamento-pré-autorizado)
53
+ - [Cancelar multipagamento pré-autorizado](#cancelar-multipagamento-pré-autorizado)
51
54
  - [Conta Moip](#conta-moip)
52
55
  - [Criação](#criação-6)
53
56
  - [Consulta](#consulta-6)
54
57
  - [Verifica se usuário já possui Conta Moip](#verifica-se-usuário-já-possui-conta-moip)
58
+ - [Conta Bancária](#conta-bancária)
59
+ - [Criação](#criação-7)
60
+ - [Consulta](#consulta-7)
61
+ - [Listagem](#listagem)
62
+ - [Atualizar conta bancária](#atualizar-conta-bancaria)
63
+ - [Deletar conta bancária](#deletar-conta-bancaria)
55
64
  - [OAuth (Moip Connect)](#oauth-(moip-connect))
56
65
  - [Solicitar permissões de acesso ao usuário](#solicitar-permissões-de-acesso-ao-usuário)
57
66
  - [Gerar Token OAuth](#gerar-token-oauth)
58
67
  - [Atualizar Token OAuth](#atualizar-token-oauth)
68
+ - [Obter Chave Pública](#obter-chave-pública)
59
69
  - [Preferências de Notificação](#preferências-de-notificação)
60
- - [Criação](#criação-7)
61
- - [Consulta](#consulta-7)
70
+ - [Criação](#criação-8)
71
+ - [Consulta](#consulta-8)
62
72
  - [Exclusão](#exclusão)
63
73
  - [Listagem](#listagem)
74
+ - [Webhooks](#webhooks)
75
+ - [Todos Webhooks](#todos-webhooks)
76
+ - [Com Paginação](#com-paginação2)
77
+ - [Evento Específico](#evento-específico)
78
+ - [Recurso Específico](#recurso-específico)
79
+ - [Saldo Moip](#saldo-moip)
80
+ - [Consulta](#consulta-10)
64
81
  - [Tratamento de Exceções](#tratamento-de-exceções)
65
82
  - [Documentação](#documentação)
66
83
  - [Licença](#licença)
@@ -96,6 +113,13 @@ Após isso, é necessário instanciar um ponto de acesso a partir do qual você
96
113
  api = Moip2::Api.new(client)
97
114
  ```
98
115
 
116
+ Você pode customizar o client passando um hash de opções na inicialização. Essas opções serão passadas adiante para o client HTTParty, que aceita as opções descritas [na documentação](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods).
117
+
118
+ Por exemplo, para alterar o timeout das requisições para 5 segundos:
119
+ ```ruby
120
+ client = Moip2::Client.new(:sandbox/:production, auth, timeout: 5)
121
+ ```
122
+
99
123
  ## Clientes
100
124
  ### Criação
101
125
  ```ruby
@@ -125,7 +149,7 @@ customer = api.customer.show("CUS-V41BR451L")
125
149
 
126
150
  ### Adicionar cartão de crédito
127
151
  ```ruby
128
- credit_card = api.customer.add_credit_card("CUSTOMER-ID",
152
+ credit_card = api.customer.add_credit_card("CUSTOMER-ID",
129
153
  {
130
154
  method: "CREDIT_CARD",
131
155
  creditCard: {
@@ -153,18 +177,12 @@ credit_card = api.customer.add_credit_card("CUSTOMER-ID",
153
177
 
154
178
  ### Deletar cartão de crédito
155
179
 
156
- > Retorna uma Exception do tipo `NotFoundError` caso não encontre o cartão de crédito para deletar
180
+ > Retorna uma Exception do tipo `NotFoundError` caso não encontre o cartão de crédito para deletar.
157
181
 
158
182
  ```ruby
159
183
  api.customer.delete_credit_card!("CREDIT-CARD-ID")
160
184
  ```
161
185
 
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
- ```
167
-
168
186
  ## Pedidos
169
187
  ### Criação
170
188
 
@@ -208,10 +226,15 @@ orders = api.order.find_all(filters: { status: { in: ["PAID", "WAITING"] }, amou
208
226
  orders = api.order.find_all(limit: 10, offset: 50)
209
227
  ```
210
228
 
229
+ ##### Consulta Valor Específico
230
+ ```ruby
231
+ orders = api.order.find_all(q: "your_value")
232
+ ```
233
+
211
234
  ## Pagamentos
212
235
 
213
236
  ### Criação
214
- #### Cartão de Crédito
237
+ #### Cartão de Crédito
215
238
  ##### Com Hash
216
239
 
217
240
  ```ruby
@@ -236,7 +259,7 @@ api.payment.create(order.id,
236
259
  )
237
260
  ```
238
261
 
239
- ##### Com Dados do Cartão
262
+ ##### Com Dados do Cartão
240
263
  > Esses método requer certificação PCI. [Consulte a documentação.](https://documentao-moip.readme.io/v2.0/reference#criar-pagamento)
241
264
 
242
265
  ```ruby
@@ -344,7 +367,7 @@ multi_pag = api.multi_payment.create("MOR-V41BR451L",
344
367
  {
345
368
  installmentCount: 1,
346
369
  fundingInstrument: {
347
- # ...
370
+ # ...
348
371
  }
349
372
  }
350
373
  )
@@ -354,6 +377,15 @@ multi_pag = api.multi_payment.create("MOR-V41BR451L",
354
377
  multi_pag = api.multi_payment.show("MPY-V41BR451L")
355
378
  ```
356
379
 
380
+ ### Capturar multipagamento pré-autorizado
381
+ ```ruby
382
+ multi = api.multi_payment.capture("MPY-V41BR451L")
383
+ ```
384
+ ### Cancelar multipagamento pré-autorizado
385
+ ```ruby
386
+ multi = api.multi_payment.void("MPY-V41BR451L")
387
+ ```
388
+
357
389
  ## Conta Moip
358
390
  ### Criação
359
391
  ```ruby
@@ -406,6 +438,59 @@ account = api.accounts.show("MPA-12312312312")
406
438
  api.accounts.exists?("123.456.789.10")
407
439
  ```
408
440
 
441
+ ## Conta bancária
442
+ ### Criação
443
+ ```ruby
444
+ bank_account = api.bank_accounts.create("MPA-14C9EE706C55",
445
+ bank_number: "237",
446
+ agency_number: "12345",
447
+ agency_check_number: "0",
448
+ account_number: "12345678",
449
+ account_check_number: "7",
450
+ type: "CHECKING",
451
+ holder: {
452
+ tax_document: {
453
+ type: "CPF",
454
+ number: "164.664.426-32",
455
+ },
456
+ fullname: "Sales Machine da Silva",
457
+ })
458
+ ```
459
+
460
+ ### Consulta
461
+ ```ruby
462
+ api.bank_accounts.show("BKA-DWTSK16UQI9N")
463
+ ```
464
+
465
+ ### Listagem
466
+ ```ruby
467
+ api.bank_accounts.find_all("MPA-14C9EE706C55")
468
+ ```
469
+
470
+ ### Atualizar conta bancaria
471
+ ```ruby
472
+ api.bank_accounts.update("BKA-DWTSK16UQI9N",
473
+ bank_number: "237",
474
+ agency_number: "12345",
475
+ agency_check_number: "0",
476
+ account_number: "87654323",
477
+ account_check_number: "7",
478
+ type: "CHECKING",
479
+ holder: {
480
+ tax_document: {
481
+ type: "CPF",
482
+ number: "164.664.426-32",
483
+ },
484
+ fullname: "Sales Machine da Silva",
485
+ })
486
+ ```
487
+
488
+ ### Deletar conta bancaria
489
+ > Retorna uma Exception do tipo `NotFoundError` caso não encontre a conta bancária para deletar
490
+ ```ruby
491
+ api.bank_accounts.delete("BKA-DWTSK16UQI9N")
492
+ ```
493
+
409
494
  ## OAuth (Moip Connect)
410
495
  ### Solicitar permissões de acesso ao usuário
411
496
  ```ruby
@@ -431,6 +516,11 @@ api.connect.authorize(
431
516
  )
432
517
  ```
433
518
 
519
+ ### Obter Chave Pública
520
+ ```ruby
521
+ keys = api.keys.show
522
+ ```
523
+
434
524
  ## Preferências de notificação
435
525
 
436
526
  ### Criação
@@ -459,6 +549,44 @@ api.notifications.delete("NOTIFICATION-ID")
459
549
  api.notifications.find_all
460
550
  ```
461
551
 
552
+ ## Webhooks
553
+ ### Consulta
554
+
555
+ ##### Todos Webhooks
556
+ ```ruby
557
+ webhooks = api.webhooks.find_all
558
+ ```
559
+
560
+ ##### Com Paginação
561
+ ```ruby
562
+ webhooks = api.webhooks.find_all(limit: 10, offset: 50)
563
+ ```
564
+
565
+ ##### Consulta Evento
566
+ ```ruby
567
+ webhooks = api.webhooks.find_all(event: "PAYMENT.WAITING")
568
+ ```
569
+
570
+ ##### Consulta Valor Específico
571
+ ```ruby
572
+ webhooks = api.webhooks.find_all(resource_id: "PAY-REJJ9F12MF7R")
573
+ ```
574
+
575
+
576
+ ## Saldo Moip
577
+ ### Consulta
578
+ ```ruby
579
+ api.balances.show()
580
+ ```
581
+
582
+ ### Show all entries
583
+ ```ruby
584
+ api.entries.find_all
585
+ ```
586
+ ### Show one entry
587
+ ```ruby
588
+ api.entries.show(entry_id)
589
+ ```
462
590
  ## Tratamento de Exceções
463
591
 
464
592
  Caso algum recurso não seja encontrado uma exceção do tipo `NotFoundError` será lançada.
data/changelog.md CHANGED
@@ -1,3 +1,58 @@
1
+ <a name="v1.1.0"></a>
2
+ ## v1.1.0 (2017-11-14)
3
+
4
+
5
+ #### Features
6
+
7
+ * Create method to generate OAuth token ((cc5dcad7))
8
+ * **Accounts**
9
+ * added `create` method and Account resource ((a8ec5469))
10
+ * added `create` method and Account resource ((399b49b9))
11
+ * **Balances** added initial support ( `show`) ((8b46be43))
12
+ * **Connect** Create method to generate authorize url ((8fcbd67d))
13
+ * **Customer**
14
+ * Overload method to delete credit card ((1b920029))
15
+ * Create method to delete a credit card from customer ((71e1b6a9))
16
+ * Create method to add credit card to customer ((edc5c67e))
17
+ * **MultiPayment**
18
+ * added `void` ((c7eb0a99))
19
+ * added `.capture` ((a8b4fcbc))
20
+ * **Notifications**
21
+ * Add method to delete a notification preference ((79354cb0))
22
+ * Add parameter to create notification to apps ((98735f0a))
23
+ * Add method to find all notification preferences ((c97383f0))
24
+ * Add method to get a notification ((7e853d6c))
25
+ * Add method to create notification preference ((80c09bbb))
26
+ * **Order** added `q` param support for ownID searches ((24ba5138))
27
+ * **Payment** Add show, void and capture methods to Payment ((4f266390))
28
+ * **accounts**
29
+ * added #show ((1da02bee))
30
+ * added #exists? ((e97fbd2d))
31
+ * added #show ((cebf937a))
32
+ * added #exists? ((d75ad84c))
33
+ * **api**
34
+ * add balances and entries APIs endpoints ((30d4b932))
35
+ * Added .accounts ((4ed3d625))
36
+ * Added .accounts ((74df6adb))
37
+ * **bank-accounts**
38
+ * add show, delete, update and find_all actions ((401c3ef6))
39
+ * add create action ((0afde060))
40
+ * **entries** add action show and index ((3a95df1e))
41
+ * **order**
42
+ * added `filters` support to `find_all` ((55d3cb8b))
43
+ * added `find_all` ((7e66c07d))
44
+ * **response**
45
+ * added ability to handle non-json response payloads ((526e53d6))
46
+ * added ability to handle non-json response payloads ((593966ad))
47
+ * **webhooks**
48
+ * add webhooks endpoint ((f9247ceb))
49
+
50
+ #### Bug Fixes
51
+
52
+ * **Balances** added needed `Accept` header ((bb928548))
53
+
54
+
55
+
1
56
  <a name="1.0.0"></a>
2
57
  ## 1.0.0 (2017-09-26)
3
58
 
@@ -31,6 +86,3 @@
31
86
  * added `find_all` ((7e66c07d))
32
87
  * **Response**
33
88
  * added ability to handle non-json response payloads ((526e53d6))
34
-
35
-
36
-
@@ -0,0 +1,129 @@
1
+ # Tip: This setup section generally goes in other files,
2
+ # and you access them in your controllers as globals,
3
+ # instead of reinstantiating them every time.
4
+ gem "moip2"
5
+
6
+ auth = Moip2::Auth::Basic.new("TOKEN", "SECRET")
7
+
8
+ client = Moip2::Client.new(:sandbox, auth)
9
+
10
+ api = Moip2::Api.new(client)
11
+
12
+ # If you want to persist your customer data and save later, now is
13
+ # the time to create it.
14
+ # TIP: Don't forget to generate your `own_id` or use one you already have
15
+
16
+ customer = api.customer.create(
17
+ ownId: "meu_cliente_id_#{SecureRandom.hex(10)}",
18
+ fullname: "Integração Moip",
19
+ email: "integracaomoip@moip.com.br",
20
+ taxDocument: {
21
+ type: "CPF",
22
+ number: "22222222222",
23
+ },
24
+ phone: {
25
+ countryCode: "55",
26
+ areaCode: "11",
27
+ number: "66778899",
28
+ },
29
+ shippingAddress: {
30
+ city: "Sao Paulo",
31
+ complement: "8",
32
+ district: "Itaim",
33
+ street: "Avenida Faria Lima",
34
+ streetNumber: "2927",
35
+ zipCode: "01234000",
36
+ state: "SP",
37
+ country: "BRA",
38
+ },
39
+ )
40
+
41
+ # Here we build the order data. You'll get the data from your database
42
+ # given your controller input, but here we simplify things with a hardcoded
43
+ # example
44
+
45
+ order = api.order.create(
46
+ own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
47
+ items: [
48
+ {
49
+ product: "Nome do produto",
50
+ quantity: 1,
51
+ detail: "Mais info...",
52
+ price: 1000,
53
+ },
54
+ ],
55
+ customer: {
56
+ ownId: "meu_cliente_id_#{SecureRandom.hex(10)}",
57
+ fullname: "Integração Moip",
58
+ email: "integracaomoip@moip.com.br",
59
+ taxDocument: {
60
+ type: "CPF",
61
+ number: "22222222222",
62
+ },
63
+ phone: {
64
+ countryCode: "55",
65
+ areaCode: "11",
66
+ number: "66778899",
67
+ },
68
+ shippingAddress: {
69
+ city: "Sao Paulo",
70
+ complement: "8",
71
+ district: "Itaim",
72
+ street: "Avenida Faria Lima",
73
+ streetNumber: "2927",
74
+ zipCode: "01234000",
75
+ state: "SP",
76
+ country: "BRA",
77
+ },
78
+ },
79
+ )
80
+
81
+ # Now with the order ID in hands, you can start creating payments.
82
+ # Here is an example of creating a boleto payment:
83
+ payment = api.payment.create(
84
+ order.id, funding_instrument: {
85
+ method: "BOLETO",
86
+ boleto: {
87
+ expirationDate: "2020-01-01",
88
+ instructionLines: {
89
+ first: "First line of instructions",
90
+ second: "Second line of instructions",
91
+ third: "Third line of instructions",
92
+ },
93
+ },
94
+ }
95
+ )
96
+
97
+ # This is how you get the boleto from the payment response and be able to show
98
+ # it in your checkout
99
+ boleto = payment[:_links][:pay_boleto][:print_href]
100
+
101
+ # Example of getting boleto line code
102
+ boleto_line_code = payment[:funding_instrument][:boleto][:line_code]
103
+
104
+ # This is how you can create a boleto refund to a bank account:
105
+ order_refund = api.refund.create(
106
+ order.id, refundingInstrument: {
107
+ method: "BANK_ACCOUNT",
108
+ bankAccount: {
109
+ bankNumber: "237",
110
+ agencyNumber: "12345",
111
+ agencyCheckNumber: "0",
112
+ accountNumber: "12345678",
113
+ accountCheckNumber: "7",
114
+ type: "CHECKING",
115
+ holder: {
116
+ taxDocument: {
117
+ type: "CPF",
118
+ number: "22222222222",
119
+ },
120
+ fullname: "Demo Moip",
121
+ },
122
+ },
123
+ }
124
+ )
125
+
126
+ # TIP: To get your application synchronized to Moip's platform,
127
+ # you should have a route that handles Webhooks.
128
+ # For further information on the possible webhooks, please refer to the official docs
129
+ # (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)
@@ -0,0 +1,119 @@
1
+ # Tip: This setup section generally goes in other files,
2
+ # and you access them in your controllers as globals,
3
+ # instead of reinstantiating them every time.
4
+ gem "moip2"
5
+
6
+ auth = Moip2::Auth::Basic.new("TOKEN", "SECRET")
7
+
8
+ client = Moip2::Client.new(:sandbox, auth)
9
+
10
+ api = Moip2::Api.new(client)
11
+
12
+ # If you want to persist your customer data and save later, now is
13
+ # the time to create it.
14
+ # TIP: Don't forget to generate your `own_id` or use one you already have
15
+
16
+ customer = api.customer.create(
17
+ ownId: "meu_cliente_id_#{SecureRandom.hex(10)}",
18
+ fullname: "Integração Moip",
19
+ email: "integracaomoip@moip.com.br",
20
+ taxDocument: {
21
+ type: "CPF",
22
+ number: "22222222222",
23
+ },
24
+ phone: {
25
+ countryCode: "55",
26
+ areaCode: "11",
27
+ number: "66778899",
28
+ },
29
+ shippingAddress: {
30
+ city: "Sao Paulo",
31
+ complement: "8",
32
+ district: "Itaim",
33
+ street: "Avenida Faria Lima",
34
+ streetNumber: "2927",
35
+ zipCode: "01234000",
36
+ state: "SP",
37
+ country: "BRA",
38
+ },
39
+ )
40
+
41
+ # Creating a credit card for a customer
42
+ customer_credit_card = api.customer.add_credit_card(
43
+ customer.id,
44
+ method: "CREDIT_CARD",
45
+ creditCard: {
46
+ expirationMonth: "05",
47
+ expirationYear: "22",
48
+ number: "5555666677778884",
49
+ cvc: "123",
50
+ holder: {
51
+ fullname: "Jose Portador da Silva",
52
+ birthdate: "1988-12-30",
53
+ taxDocument: {
54
+ type: "CPF",
55
+ number: "33333333333",
56
+ },
57
+ phone: {
58
+ countryCode: "55",
59
+ areaCode: "11",
60
+ number: "66778899",
61
+ },
62
+ },
63
+ },
64
+ )
65
+
66
+ # TIP: Now you can access the Moip ID to save it to your database, if you want
67
+ # Ex.:
68
+ # Customer.find_by(id: 123).update!(moip_id: customer.id)
69
+
70
+ # Here we build the order data. You'll get the data from your database
71
+ # given your controller input, but here we simplify things with a hardcoded
72
+ # example
73
+
74
+ order = api.order.create(
75
+ own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
76
+ items: [
77
+ {
78
+ product: "Nome do produto",
79
+ quantity: 1,
80
+ detail: "Mais info...",
81
+ price: 1000,
82
+ },
83
+ ],
84
+ customer: {
85
+ id: customer.id,
86
+ },
87
+ )
88
+
89
+ payment = api.payment.create(
90
+ order.id,
91
+ installment_count: 1,
92
+ funding_instrument: {
93
+ method: "CREDIT_CARD",
94
+ credit_card: {
95
+ id: customer_credit_card.credit_card.id,
96
+ holder: {
97
+ fullname: "Integração Moip",
98
+ birthdate: "1988-12-30",
99
+ taxDocument: {
100
+ type: "CPF",
101
+ number: "33333333333",
102
+ },
103
+ phone: {
104
+ countryCode: "55",
105
+ areaCode: "11",
106
+ number: "000000000",
107
+ },
108
+ },
109
+ },
110
+ },
111
+ )
112
+
113
+ # You can create a full payment refunds:
114
+ full_payment_refund = api.refund.create(payment.id)
115
+
116
+ # TIP: To get your application synchronized to Moip's platform,
117
+ # you should have a route that handles Webhooks.
118
+ # For further information on the possible webhooks, please refer to the official docs
119
+ # (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)