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.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -12
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -4
- data/README.md +142 -14
- data/changelog.md +55 -3
- data/examples/ecommerce/payment-with-boleto.rb +129 -0
- data/examples/ecommerce/payment-with-credit-card.rb +119 -0
- data/examples/ecommerce/payment-with-hash.rb +101 -0
- data/examples/marketplace/create-classical-account-company.rb +74 -0
- data/examples/marketplace/create-classical-account-without-company.rb +47 -0
- data/examples/marketplace/moip-connect.rb +31 -0
- data/examples/marketplace/payment-with-escrow.rb +88 -0
- data/examples/marketplace/payment-with-pre-authorization.rb +87 -0
- data/examples/marketplace/shared-cart.rb +220 -0
- data/lib/moip2/api.rb +17 -2
- data/lib/moip2/balances_api.rb +18 -0
- data/lib/moip2/bank_accounts_api.rb +51 -0
- data/lib/moip2/client.rb +11 -11
- data/lib/moip2/connect_api.rb +2 -13
- data/lib/moip2/connect_client.rb +11 -0
- data/lib/moip2/entry_api.rb +21 -0
- data/lib/moip2/multi_payment_api.rb +8 -0
- data/lib/moip2/order_api.rb +2 -1
- data/lib/moip2/resource/balances.rb +12 -0
- data/lib/moip2/resource/bank_account.rb +12 -0
- data/lib/moip2/resource/entry.rb +13 -0
- data/lib/moip2/version.rb +1 -1
- data/lib/moip2/webhooks_api.rb +20 -4
- data/lib/moip2.rb +7 -0
- data/moip2.gemspec +2 -0
- data/spec/moip2/balances_api_spec.rb +22 -0
- data/spec/moip2/bank_accounts_api_spec.rb +173 -0
- data/spec/moip2/client_spec.rb +13 -76
- data/spec/moip2/connect_api_spec.rb +1 -1
- data/spec/moip2/connect_client_spec.rb +63 -0
- data/spec/moip2/customer_api_spec.rb +3 -3
- data/spec/moip2/entry_api_spec.rb +43 -0
- data/spec/moip2/multi_payment_api_spec.rb +32 -2
- data/spec/moip2/order_api_spec.rb +24 -1
- data/spec/moip2/response_spec.rb +2 -6
- data/spec/moip2/webhooks_spec.rb +87 -11
- data/spec/moip2_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -14
- data/vcr_cassettes/bank_account_create_fail.yml +39 -0
- data/vcr_cassettes/bank_account_create_sucess.yml +41 -0
- data/vcr_cassettes/bank_account_deleted_existent.yml +38 -0
- data/vcr_cassettes/bank_account_deleted_nonexistent.yml +38 -0
- data/vcr_cassettes/bank_account_find_all.yml +9525 -0
- data/vcr_cassettes/bank_account_show_existent.yml +40 -0
- data/vcr_cassettes/bank_account_show_nonexistent.yml +38 -0
- data/vcr_cassettes/bank_account_update.yml +41 -0
- data/vcr_cassettes/capture_multi_payment_sucess.yml +44 -0
- data/vcr_cassettes/find_all_entries.yml +63 -0
- data/vcr_cassettes/find_all_orders_q_search.yml +39 -0
- data/vcr_cassettes/{get_webhooks.yml → find_all_webhooks.yml} +1 -1
- data/vcr_cassettes/find_all_webhooks_event.yml +42 -0
- data/vcr_cassettes/find_all_webhooks_limit.yml +48 -0
- data/vcr_cassettes/find_all_webhooks_multi_params.yml +38 -0
- data/vcr_cassettes/find_all_webhooks_no_filter.yml +58 -0
- data/vcr_cassettes/find_all_webhooks_offset.yml +58 -0
- data/vcr_cassettes/find_all_webhooks_resource_id.yml +38 -0
- data/vcr_cassettes/get_balances.yml +44 -0
- data/vcr_cassettes/show_entries.yml +43 -0
- data/vcr_cassettes/void_multi_payment_sucess.yml +46 -0
- metadata +50 -4
@@ -0,0 +1,101 @@
|
|
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
|
+
# TIP: Now you can access the Moip ID to save it to your database, if you want
|
42
|
+
# Ex.:
|
43
|
+
# Customer.find_by(id: 123).update!(moip_id: customer.id)
|
44
|
+
|
45
|
+
# Here we build the order data. You'll get the data from your database
|
46
|
+
# given your controller input, but here we simplify things with a hardcoded
|
47
|
+
# example
|
48
|
+
|
49
|
+
order = api.order.create(
|
50
|
+
own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
|
51
|
+
items: [
|
52
|
+
{
|
53
|
+
product: "Nome do produto",
|
54
|
+
quantity: 1,
|
55
|
+
detail: "Mais info...",
|
56
|
+
price: 1000,
|
57
|
+
},
|
58
|
+
],
|
59
|
+
customer: {
|
60
|
+
id: customer.id,
|
61
|
+
},
|
62
|
+
)
|
63
|
+
|
64
|
+
# Now with the order ID in hands, you can start creating payments
|
65
|
+
# It is common to use the `hash` method if you are using client-side
|
66
|
+
# encryption for card data.
|
67
|
+
payment = api.payment.create(order.id,
|
68
|
+
installment_count: 1,
|
69
|
+
funding_instrument: {
|
70
|
+
method: "CREDIT_CARD",
|
71
|
+
credit_card: {
|
72
|
+
# You can generate the following hash using a Moip Javascript SDK
|
73
|
+
# where you use the customer credit_card data and your public key
|
74
|
+
# to create the hash.
|
75
|
+
# Read more about creating credit card hash here:
|
76
|
+
# https://github.com/moip/moip-sdk-js
|
77
|
+
hash: "your-hash",
|
78
|
+
holder: {
|
79
|
+
fullname: "Integração Moip",
|
80
|
+
birthdate: "1988-12-30",
|
81
|
+
taxDocument: {
|
82
|
+
type: "CPF",
|
83
|
+
number: "33333333333",
|
84
|
+
},
|
85
|
+
phone: {
|
86
|
+
countryCode: "55",
|
87
|
+
areaCode: "11",
|
88
|
+
number: "000000000",
|
89
|
+
},
|
90
|
+
},
|
91
|
+
},
|
92
|
+
})
|
93
|
+
|
94
|
+
# Or a partial payment refunds, where the second parameter is
|
95
|
+
# the value of the refunds:
|
96
|
+
partial_payment_refund = api.refund.create(payment.id, amount: 2000)
|
97
|
+
|
98
|
+
# TIP: To get your application synchronized to Moip's platform,
|
99
|
+
# you should have a route that handles Webhooks.
|
100
|
+
# For further information on the possible webhooks, please refer to the official docs
|
101
|
+
# (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Here is an example of creating an Moip account using the Moip account API
|
2
|
+
|
3
|
+
auth = Moip2::Auth::OAuth.new("oauth")
|
4
|
+
|
5
|
+
client = Moip2::Client.new(:sandbox, auth)
|
6
|
+
|
7
|
+
api = Moip2::Api.new(client)
|
8
|
+
|
9
|
+
# Check if account exists
|
10
|
+
api.accounts.exists?("978.443.610-85")
|
11
|
+
|
12
|
+
# Create account
|
13
|
+
|
14
|
+
account = api.accounts.create(
|
15
|
+
email: {
|
16
|
+
address: "dev.moip@labs.moip.com.br",
|
17
|
+
},
|
18
|
+
person: {
|
19
|
+
name: "Joaquim José",
|
20
|
+
lastName: "Silva Silva",
|
21
|
+
taxDocument: {
|
22
|
+
type: "CPF",
|
23
|
+
number: "978.443.610-85",
|
24
|
+
},
|
25
|
+
identityDocument: {
|
26
|
+
type: "RG",
|
27
|
+
number: "35.868.057-8",
|
28
|
+
issuer: "SSP",
|
29
|
+
issueDate: "2000-12-12",
|
30
|
+
},
|
31
|
+
birthDate: "1990-01-01",
|
32
|
+
phone: {
|
33
|
+
countryCode: "55",
|
34
|
+
areaCode: "11",
|
35
|
+
number: "965213244",
|
36
|
+
},
|
37
|
+
address: {
|
38
|
+
street: "Av. Brigadeiro Faria Lima",
|
39
|
+
streetNumber: "2927",
|
40
|
+
district: "Itaim",
|
41
|
+
zipCode: "01234-000",
|
42
|
+
city: "S\u00E3o Paulo",
|
43
|
+
state: "SP",
|
44
|
+
country: "BRA",
|
45
|
+
},
|
46
|
+
},
|
47
|
+
company: {
|
48
|
+
name: "Company Test",
|
49
|
+
businessName: "Razão Social Test",
|
50
|
+
address: {
|
51
|
+
street: "Av. Brigadeiro Faria Lima",
|
52
|
+
streetNumber: "4530",
|
53
|
+
district: "Itaim",
|
54
|
+
city: "São Paulo",
|
55
|
+
state: "SP",
|
56
|
+
country: "BRA",
|
57
|
+
zipCode: "01234000",
|
58
|
+
},
|
59
|
+
mainActivity: {
|
60
|
+
cnae: "82.91-1/00",
|
61
|
+
description: "Atividades de cobranças e informações cadastrais",
|
62
|
+
},
|
63
|
+
taxDocument: {
|
64
|
+
type: "CNPJ",
|
65
|
+
number: "61.148.461/0001-09",
|
66
|
+
},
|
67
|
+
phone: {
|
68
|
+
countryCode: "55",
|
69
|
+
areaCode: "11",
|
70
|
+
number: "975142244",
|
71
|
+
},
|
72
|
+
},
|
73
|
+
type: "MERCHANT",
|
74
|
+
)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Here is an example of creating an Moip account using the Moip account API
|
2
|
+
|
3
|
+
auth = Moip2::Auth::OAuth.new("oauth")
|
4
|
+
|
5
|
+
client = Moip2::Client.new(:sandbox, auth)
|
6
|
+
|
7
|
+
api = Moip2::Api.new(client)
|
8
|
+
|
9
|
+
# Check if account exists
|
10
|
+
api.accounts.exists?("978.443.610-85")
|
11
|
+
|
12
|
+
# Create account
|
13
|
+
account = api.accounts.create(
|
14
|
+
email: {
|
15
|
+
address: "dev.moip@labs.moip.com.br",
|
16
|
+
},
|
17
|
+
person: {
|
18
|
+
name: "Joaquim José",
|
19
|
+
lastName: "Silva Silva",
|
20
|
+
taxDocument: {
|
21
|
+
type: "CPF",
|
22
|
+
number: "978.443.610-85",
|
23
|
+
},
|
24
|
+
identityDocument: {
|
25
|
+
type: "RG",
|
26
|
+
number: "35.868.057-8",
|
27
|
+
issuer: "SSP",
|
28
|
+
issueDate: "2000-12-12",
|
29
|
+
},
|
30
|
+
birthDate: "1990-01-01",
|
31
|
+
phone: {
|
32
|
+
countryCode: "55",
|
33
|
+
areaCode: "11",
|
34
|
+
number: "965213244",
|
35
|
+
},
|
36
|
+
address: {
|
37
|
+
street: "Av. Brigadeiro Faria Lima",
|
38
|
+
streetNumber: "2927",
|
39
|
+
district: "Itaim",
|
40
|
+
zipCode: "01234-000",
|
41
|
+
city: "S\u00E3o Paulo",
|
42
|
+
state: "SP",
|
43
|
+
country: "BRA",
|
44
|
+
},
|
45
|
+
},
|
46
|
+
type: "MERCHANT",
|
47
|
+
)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# We are going to create an oauth access token.
|
2
|
+
# In order to create an oauth acess token, you must create an application on Moip.
|
3
|
+
# Click on this link to go to Moip's dev docs and create your app:
|
4
|
+
# https://dev.moip.com.br/v2.0/reference#criar-um-app
|
5
|
+
|
6
|
+
gem "moip2"
|
7
|
+
|
8
|
+
auth = Moip2::Auth::OAuth.new("oauth")
|
9
|
+
|
10
|
+
client = Moip2::Client.new(:sandbox, auth)
|
11
|
+
|
12
|
+
api = Moip2::Api.new(client)
|
13
|
+
|
14
|
+
# Now you must require permission access:
|
15
|
+
api.connect.authorize_url("APP-DVLBF0ANBO1S", "https://meusite.com", "RECEIVE_FUNDS, REFUND")
|
16
|
+
# Read more here: https://dev.moip.com.br/v2.0/reference#solicitar-permissao
|
17
|
+
|
18
|
+
# Once the seller has granted your required accesses, you use the code from
|
19
|
+
# the response to generate the accessToken.
|
20
|
+
|
21
|
+
# Generate acessToken:
|
22
|
+
response = api.connect.authorize(
|
23
|
+
client_id: "your_id", # Ex.: APP-DVLBF0ANBO1S
|
24
|
+
client_secret: "your_secret",
|
25
|
+
code: "your_code",
|
26
|
+
redirect_uri: "https://meusite.com",
|
27
|
+
grant_type: "authorization_code",
|
28
|
+
)
|
29
|
+
|
30
|
+
# Get accessToken:
|
31
|
+
response[:access_token]
|
@@ -0,0 +1,88 @@
|
|
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
|
+
# Here we build the order data. You'll get the data from your database
|
13
|
+
# given your controller input, but here we simplify things with a hardcoded
|
14
|
+
# example
|
15
|
+
|
16
|
+
order = api.order.create(
|
17
|
+
own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
product: "Nome do produto",
|
21
|
+
quantity: 1,
|
22
|
+
detail: "Mais info...",
|
23
|
+
price: 1000,
|
24
|
+
},
|
25
|
+
],
|
26
|
+
customer: {
|
27
|
+
ownId: "meu_cliente_id_#{SecureRandom.hex(10)}",
|
28
|
+
fullname: "Integração Moip",
|
29
|
+
email: "integracaomoip@moip.com.br",
|
30
|
+
taxDocument: {
|
31
|
+
type: "CPF",
|
32
|
+
number: "22222222222",
|
33
|
+
},
|
34
|
+
phone: {
|
35
|
+
countryCode: "55",
|
36
|
+
areaCode: "11",
|
37
|
+
number: "66778899",
|
38
|
+
},
|
39
|
+
shippingAddress: {
|
40
|
+
city: "Sao Paulo",
|
41
|
+
complement: "8",
|
42
|
+
district: "Itaim",
|
43
|
+
street: "Avenida Faria Lima",
|
44
|
+
streetNumber: "2927",
|
45
|
+
zipCode: "01234000",
|
46
|
+
state: "SP",
|
47
|
+
country: "BRA",
|
48
|
+
},
|
49
|
+
},
|
50
|
+
)
|
51
|
+
|
52
|
+
payment = api.payment.create(order.id,
|
53
|
+
installment_count: 1,
|
54
|
+
escrow: {
|
55
|
+
description: "Teste escrow",
|
56
|
+
},
|
57
|
+
funding_instrument: {
|
58
|
+
method: "CREDIT_CARD",
|
59
|
+
credit_card: {
|
60
|
+
# You can generate the following hash using a Moip Javascript SDK
|
61
|
+
# where you use the customer credit_card data and your public key
|
62
|
+
# to create the hash.
|
63
|
+
# Read more about creating credit card hash here:
|
64
|
+
# https://dev.moip.com.br/v2.0/docs/criptografia-de-cartao
|
65
|
+
hash: "kJHoKZ2bIVFjEFPSQQxbpXL6t5VCMoGTB4eJ4GLHmUz8f8Ny/LSL20yqbn+bZQymydVJyo3lL2DMT0dsWMzimYILQH4vAF24VwM0hKxX7nVwqGpGCXwBwSJGCwR57lqDiI4RVhKTVJpu7FySfu+Hm9JWSk4fzPXQO/FRqIS5TJQWJSywjLmGwyYtTGsmHTSCwvPFg+0GcG/EkYjPesMc/ycxPixibrEId9Wz03QnLsHYzSBCnPqg8xq8WKYDX2x3dHV3GNsB4TEfVz4psynddDEpX/VhIk2e8cXQ0EoXKkWdJEJB4KFmqj39OhNevCBkF5ADvzFp73J0IxnjOf1AQA==",
|
66
|
+
holder: {
|
67
|
+
fullname: "Integração Moip",
|
68
|
+
birthdate: "1988-12-30",
|
69
|
+
taxDocument: {
|
70
|
+
type: "CPF",
|
71
|
+
number: "33333333333",
|
72
|
+
},
|
73
|
+
phone: {
|
74
|
+
countryCode: "55",
|
75
|
+
areaCode: "11",
|
76
|
+
number: "000000000",
|
77
|
+
},
|
78
|
+
},
|
79
|
+
},
|
80
|
+
})
|
81
|
+
|
82
|
+
# You can create a full payment refunds:
|
83
|
+
full_payment_refund = api.refund.create(payment.id)
|
84
|
+
|
85
|
+
# TIP: To get your application synchronized to Moip's platform,
|
86
|
+
# you should have a route that handles Webhooks.
|
87
|
+
# For further information on the possible webhooks, please refer to the official docs
|
88
|
+
# (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)
|
@@ -0,0 +1,87 @@
|
|
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
|
+
# Here we build the order data. You'll get the data from your database
|
13
|
+
# given your controller input, but here we simplify things with a hardcoded
|
14
|
+
# example
|
15
|
+
|
16
|
+
order = api.order.create(
|
17
|
+
own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
product: "Nome do produto",
|
21
|
+
quantity: 1,
|
22
|
+
detail: "Mais info...",
|
23
|
+
price: 1000,
|
24
|
+
},
|
25
|
+
],
|
26
|
+
customer: {
|
27
|
+
ownId: "meu_cliente_id_#{SecureRandom.hex(10)}",
|
28
|
+
fullname: "Integração Moip",
|
29
|
+
email: "integracaomoip@moip.com.br",
|
30
|
+
taxDocument: {
|
31
|
+
type: "CPF",
|
32
|
+
number: "22222222222",
|
33
|
+
},
|
34
|
+
phone: {
|
35
|
+
countryCode: "55",
|
36
|
+
areaCode: "11",
|
37
|
+
number: "66778899",
|
38
|
+
},
|
39
|
+
shippingAddress: {
|
40
|
+
city: "Sao Paulo",
|
41
|
+
complement: "8",
|
42
|
+
district: "Itaim",
|
43
|
+
street: "Avenida Faria Lima",
|
44
|
+
streetNumber: "2927",
|
45
|
+
zipCode: "01234000",
|
46
|
+
state: "SP",
|
47
|
+
country: "BRA",
|
48
|
+
},
|
49
|
+
},
|
50
|
+
)
|
51
|
+
|
52
|
+
# Create pre authorized payment
|
53
|
+
payment = api.payment.create(order.id,
|
54
|
+
installment_count: 1,
|
55
|
+
delayCapture: true,
|
56
|
+
funding_instrument: {
|
57
|
+
method: "CREDIT_CARD",
|
58
|
+
credit_card: {
|
59
|
+
# You can generate the following hash using a Moip Javascript SDK
|
60
|
+
# where you use the customer credit_card data and your public key
|
61
|
+
# to create the hash.
|
62
|
+
# Read more about creating credit card hash here:
|
63
|
+
# https://dev.moip.com.br/v2.0/docs/criptografia-de-cartao
|
64
|
+
hash: "kJHoKZ2bIVFjEFPSQQxbpXL6t5VCMoGTB4eJ4GLHmUz8f8Ny/LSL20yqbn+bZQymydVJyo3lL2DMT0dsWMzimYILQH4vAF24VwM0hKxX7nVwqGpGCXwBwSJGCwR57lqDiI4RVhKTVJpu7FySfu+Hm9JWSk4fzPXQO/FRqIS5TJQWJSywjLmGwyYtTGsmHTSCwvPFg+0GcG/EkYjPesMc/ycxPixibrEId9Wz03QnLsHYzSBCnPqg8xq8WKYDX2x3dHV3GNsB4TEfVz4psynddDEpX/VhIk2e8cXQ0EoXKkWdJEJB4KFmqj39OhNevCBkF5ADvzFp73J0IxnjOf1AQA==",
|
65
|
+
holder: {
|
66
|
+
fullname: "Integração Moip",
|
67
|
+
birthdate: "1988-12-30",
|
68
|
+
taxDocument: {
|
69
|
+
type: "CPF",
|
70
|
+
number: "33333333333",
|
71
|
+
},
|
72
|
+
phone: {
|
73
|
+
countryCode: "55",
|
74
|
+
areaCode: "11",
|
75
|
+
number: "000000000",
|
76
|
+
},
|
77
|
+
},
|
78
|
+
},
|
79
|
+
})
|
80
|
+
|
81
|
+
# Capture pre authorized payment
|
82
|
+
api.payment.catpure(payment.id)
|
83
|
+
|
84
|
+
# TIP: To get your application synchronized to Moip's platform,
|
85
|
+
# you should have a route that handles Webhooks.
|
86
|
+
# For further information on the possible webhooks, please refer to the official docs
|
87
|
+
# (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)
|
@@ -0,0 +1,220 @@
|
|
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::OAuth.new("oauth")
|
7
|
+
|
8
|
+
client = Moip2::Client.new(:sandbox, auth)
|
9
|
+
|
10
|
+
api = Moip2::Api.new(client)
|
11
|
+
|
12
|
+
# Here we build the multi order data. You'll get the data from your database
|
13
|
+
# given your controller input, but here we simplify things with a hardcoded
|
14
|
+
# example.
|
15
|
+
|
16
|
+
# In this example, we create a multi order with two orders for two different
|
17
|
+
# sellers and two different customers, where the first order of the multi order,
|
18
|
+
# the seller is the primary receiver, and the second one, the seller is the
|
19
|
+
# secondary receiver.
|
20
|
+
|
21
|
+
multi_order = api.multi_order.create(
|
22
|
+
own_id: "meu_id_de_multi_order_#{SecureRandom.hex(10)}",
|
23
|
+
orders: [
|
24
|
+
{
|
25
|
+
own_id: "meu_id_de_order_#{SecureRandom.hex(10)}",
|
26
|
+
items: [
|
27
|
+
{
|
28
|
+
product: "Produto 1",
|
29
|
+
quantity: 1,
|
30
|
+
detail: "Mais info...",
|
31
|
+
price: 3000,
|
32
|
+
},
|
33
|
+
],
|
34
|
+
customer: {
|
35
|
+
ownId: "id_do_cliente1_#{SecureRandom.hex(10)}",
|
36
|
+
fullname: "Joao Sousa",
|
37
|
+
email: "joao.sousa@email.com",
|
38
|
+
birthDate: "1988-12-30",
|
39
|
+
taxDocument: {
|
40
|
+
type: "CPF",
|
41
|
+
number: "22222222222",
|
42
|
+
},
|
43
|
+
phone: {
|
44
|
+
countryCode: "55",
|
45
|
+
areaCode: "11",
|
46
|
+
number: "66778899",
|
47
|
+
},
|
48
|
+
shippingAddress: {
|
49
|
+
street: "Avenida Faria Lima",
|
50
|
+
streetNumber: 2927,
|
51
|
+
complement: 8,
|
52
|
+
district: "Itaim",
|
53
|
+
city: "Sao Paulo",
|
54
|
+
state: "SP",
|
55
|
+
country: "BRA",
|
56
|
+
zipCode: "01234000",
|
57
|
+
},
|
58
|
+
},
|
59
|
+
receivers: [
|
60
|
+
{
|
61
|
+
moipAccount: {
|
62
|
+
id: "MPA-D63A62C73A92",
|
63
|
+
},
|
64
|
+
type: "PRIMARY",
|
65
|
+
},
|
66
|
+
],
|
67
|
+
},
|
68
|
+
{
|
69
|
+
own_id: "meu_segundo_id_de_order_#{SecureRandom.hex(10)}",
|
70
|
+
items: [
|
71
|
+
{
|
72
|
+
product: "Produto 2",
|
73
|
+
quantity: 1,
|
74
|
+
detail: "Mais info...",
|
75
|
+
price: 2600,
|
76
|
+
},
|
77
|
+
],
|
78
|
+
customer: {
|
79
|
+
ownId: "id_do_cliente2_#{SecureRandom.hex(10)}",
|
80
|
+
fullname: "Joao Sousa",
|
81
|
+
email: "joao.sousa@email.com",
|
82
|
+
birthDate: "1988-12-30",
|
83
|
+
taxDocument: {
|
84
|
+
type: "CPF",
|
85
|
+
number: "22222222222",
|
86
|
+
},
|
87
|
+
phone: {
|
88
|
+
countryCode: "55",
|
89
|
+
areaCode: "11",
|
90
|
+
number: "66778899",
|
91
|
+
},
|
92
|
+
shippingAddress: {
|
93
|
+
street: "Avenida Faria Lima",
|
94
|
+
streetNumber: 2927,
|
95
|
+
complement: 8,
|
96
|
+
district: "Itaim",
|
97
|
+
city: "Sao Paulo",
|
98
|
+
state: "SP",
|
99
|
+
country: "BRA",
|
100
|
+
zipCode: "01234000",
|
101
|
+
},
|
102
|
+
},
|
103
|
+
receivers: [
|
104
|
+
{
|
105
|
+
moipAccount: {
|
106
|
+
id: "MPA-D63A62C73A92",
|
107
|
+
},
|
108
|
+
type: "PRIMARY",
|
109
|
+
},
|
110
|
+
{
|
111
|
+
moipAccount: {
|
112
|
+
id: "MPA-HBKKXIFCY1N3",
|
113
|
+
},
|
114
|
+
type: "SECONDARY",
|
115
|
+
amount: {
|
116
|
+
fixed: 55,
|
117
|
+
},
|
118
|
+
},
|
119
|
+
],
|
120
|
+
},
|
121
|
+
{
|
122
|
+
own_id: "meu_terceiro_id_de_order_#{SecureRandom.hex(10)}",
|
123
|
+
items: [
|
124
|
+
{
|
125
|
+
product: "Produto 3",
|
126
|
+
quantity: 2,
|
127
|
+
detail: "Mais info...",
|
128
|
+
price: 4000,
|
129
|
+
},
|
130
|
+
],
|
131
|
+
customer: {
|
132
|
+
ownId: "id_do_cliente3_#{SecureRandom.hex(10)}",
|
133
|
+
fullname: "Joao Sousa",
|
134
|
+
email: "joao.sousa@email.com",
|
135
|
+
birthDate: "1988-12-30",
|
136
|
+
taxDocument: {
|
137
|
+
type: "CPF",
|
138
|
+
number: "22222222222",
|
139
|
+
},
|
140
|
+
phone: {
|
141
|
+
countryCode: "55",
|
142
|
+
areaCode: "11",
|
143
|
+
number: "66778899",
|
144
|
+
},
|
145
|
+
shippingAddress: {
|
146
|
+
street: "Avenida Faria Lima",
|
147
|
+
streetNumber: 2927,
|
148
|
+
complement: 8,
|
149
|
+
district: "Itaim",
|
150
|
+
city: "Sao Paulo",
|
151
|
+
state: "SP",
|
152
|
+
country: "BRA",
|
153
|
+
zipCode: "01234000",
|
154
|
+
},
|
155
|
+
},
|
156
|
+
receivers: [
|
157
|
+
{
|
158
|
+
moipAccount: {
|
159
|
+
id: "MPA-D63A62C73A92",
|
160
|
+
},
|
161
|
+
type: "PRIMARY",
|
162
|
+
},
|
163
|
+
{
|
164
|
+
moipAccount: {
|
165
|
+
id: "MPA-HBKKXIFCY1N3",
|
166
|
+
},
|
167
|
+
type: "SECONDARY",
|
168
|
+
amount: {
|
169
|
+
percentual: 40,
|
170
|
+
},
|
171
|
+
},
|
172
|
+
],
|
173
|
+
},
|
174
|
+
],
|
175
|
+
)
|
176
|
+
|
177
|
+
# Now with the order ID in hands, you can start creating payments
|
178
|
+
# It is common to use the `hash` method if you are using client-side
|
179
|
+
# encryption for card data.
|
180
|
+
multi_payment = api.multi_payment.create(
|
181
|
+
multi_order.id,
|
182
|
+
funding_instrument: {
|
183
|
+
method: "BOLETO",
|
184
|
+
boleto: {
|
185
|
+
expirationDate: "2020-01-01",
|
186
|
+
instructionLines: {
|
187
|
+
first: "First line of instructions",
|
188
|
+
second: "Second line of instructions",
|
189
|
+
third: "Third line of instructions",
|
190
|
+
},
|
191
|
+
},
|
192
|
+
},
|
193
|
+
)
|
194
|
+
|
195
|
+
# This is how you can create a boleto refund to a bank account:
|
196
|
+
payment_refund = api.refund.create(
|
197
|
+
payment.id, refundingInstrument: {
|
198
|
+
method: "BANK_ACCOUNT",
|
199
|
+
bankAccount: {
|
200
|
+
bankNumber: "237",
|
201
|
+
agencyNumber: "12345",
|
202
|
+
agencyCheckNumber: "0",
|
203
|
+
accountNumber: "12345678",
|
204
|
+
accountCheckNumber: "7",
|
205
|
+
type: "CHECKING",
|
206
|
+
holder: {
|
207
|
+
taxDocument: {
|
208
|
+
type: "CPF",
|
209
|
+
number: "22222222222",
|
210
|
+
},
|
211
|
+
fullname: "Demo Moip",
|
212
|
+
},
|
213
|
+
},
|
214
|
+
}
|
215
|
+
)
|
216
|
+
|
217
|
+
# TIP: To get your application synchronized to Moip's platform,
|
218
|
+
# you should have a route that handles Webhooks.
|
219
|
+
# For further information on the possible webhooks, please refer to the official docs
|
220
|
+
# (https://dev.moip.com.br/v2.0/reference#lista-de-webhooks-disponíveis)
|
data/lib/moip2/api.rb
CHANGED
@@ -14,6 +14,14 @@ module Moip2
|
|
14
14
|
Moip2::PaymentApi.new(client)
|
15
15
|
end
|
16
16
|
|
17
|
+
def balances
|
18
|
+
Moip2::BalancesApi.new(client)
|
19
|
+
end
|
20
|
+
|
21
|
+
def entries
|
22
|
+
Moip2::EntryApi.new(client)
|
23
|
+
end
|
24
|
+
|
17
25
|
def invoice
|
18
26
|
Moip2::InvoiceApi.new client
|
19
27
|
end
|
@@ -42,9 +50,16 @@ module Moip2
|
|
42
50
|
Moip2::AccountsApi.new(client)
|
43
51
|
end
|
44
52
|
|
53
|
+
def bank_accounts
|
54
|
+
Moip2::BankAccountsApi.new(client)
|
55
|
+
end
|
56
|
+
|
57
|
+
def webhooks
|
58
|
+
Moip2::WebhooksApi.new(client)
|
59
|
+
end
|
60
|
+
|
45
61
|
def connect
|
46
|
-
|
47
|
-
connect_client = Client.new(client.env, client.auth, host, client.opts)
|
62
|
+
connect_client = Moip2::ConnectClient.new(client.env, client.auth, client.opts)
|
48
63
|
Moip2::ConnectApi.new(connect_client)
|
49
64
|
end
|
50
65
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Moip2
|
2
|
+
class BalancesApi
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
client.opts[:headers]["Accept"] = "application/json;version=2.1"
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def base_path
|
11
|
+
"/v2/balances"
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
Resource::Balances.new(client, client.get(base_path))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|