getnet_api 1.0.3 → 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 +4 -4
- data/.github/workflows/ruby.yml +14 -2
- data/.gitignore +2 -0
- data/Gemfile.lock +8 -8
- data/README.md +27 -6
- data/lib/getnet_api/base.rb +14 -18
- data/lib/getnet_api/boleto.rb +0 -1
- data/lib/getnet_api/customer.rb +5 -5
- data/lib/getnet_api/payment.rb +23 -29
- data/lib/getnet_api/pix.rb +35 -0
- data/lib/getnet_api/version.rb +2 -2
- data/lib/getnet_api.rb +5 -7
- data/spec/lib/getnet_api/address_spec.rb +77 -0
- data/spec/lib/getnet_api/base_spec.rb +6 -8
- data/spec/lib/getnet_api/boleto_spec.rb +49 -0
- data/spec/lib/getnet_api/card_spec.rb +69 -0
- data/spec/lib/getnet_api/card_verification_spec.rb +30 -0
- data/spec/lib/getnet_api/configure_spec.rb +9 -0
- data/spec/lib/getnet_api/credit_spec.rb +68 -0
- data/spec/lib/getnet_api/customer_spec.rb +130 -0
- data/spec/lib/getnet_api/order_spec.rb +30 -0
- data/spec/lib/getnet_api/payment_cancel_spec.rb +121 -0
- data/spec/lib/getnet_api/payment_spec.rb +163 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/vcr_cassettes/{getnet_api/base/build_request.yml → GetnetApi_Base/_build_request/builds_and_executes_request_based_on.yml} +12 -12
- data/spec/vcr_cassettes/GetnetApi_CardVerification/_verify/performs_the_request_and_returns_the_verification_result.yml +110 -0
- data/spec/vcr_cassettes/GetnetApi_Customer/_create/performs_the_request.yml +64 -0
- data/spec/vcr_cassettes/GetnetApi_Customer/_create/performs_the_request_and_returns_the_number_token.yml +112 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/test/correctly_requests_for_cancelling.yml +67 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_cancelling_a_payment/correctly_execute_the_request.yml +118 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_paying_by_boleto/correctly_requests_for_boleto_payment.yml +60 -0
- data/spec/vcr_cassettes/GetnetApi_Payment/_create/when_paying_by_credit/correctly_requests_for_credit_payment.yml +63 -0
- data/spec/vcr_cassettes/getnet_api/base/valid_bearer.yml +5 -5
- data/spec/vcr_cassettes/getnet_api/cardtoken/get.yml +8 -63
- data/spec/vcr_cassettes/getnet_api/payment_cancel/create.yml +62 -0
- metadata +43 -8
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::CardVerification do
|
4
|
+
describe '.verify', :vcr do
|
5
|
+
let(:card_token) do
|
6
|
+
card_number = '5155901222280001' # see https://developers.getnet.com.br/api#section/Cartoes-para-Teste
|
7
|
+
GetnetApi::CardToken.get(card_number)['number_token']
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:card) do
|
11
|
+
GetnetApi::Card.new(
|
12
|
+
number_token: card_token,
|
13
|
+
cardholder_name: 'JOAO DA SILVA',
|
14
|
+
security_code: '123',
|
15
|
+
brand: 'Mastercard',
|
16
|
+
expiration_month: '12',
|
17
|
+
expiration_year: '20'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'performs the request and returns the verification result' do
|
22
|
+
response = GetnetApi::CardVerification.verify card
|
23
|
+
expected_uri = 'https://api-sandbox.getnet.com.br/v1/cards/verification'
|
24
|
+
expect(WebMock).to have_requested(:post, expected_uri)
|
25
|
+
expect(response['status']).to eq 'VERIFIED'
|
26
|
+
expect(response).to have_key 'verification_id'
|
27
|
+
expect(response).to have_key 'authorization_code'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -11,6 +11,15 @@ describe GetnetApi::Configure do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
after do
|
15
|
+
GetnetApi.configure do |config|
|
16
|
+
config.ambiente = :sandbox
|
17
|
+
config.seller_id = '67be6e90-00c1-410d-83f5-6d75621effc8'
|
18
|
+
config.client_id = '74438877-f00b-4502-8454-de3d7166dc2a'
|
19
|
+
config.client_secret = '4eac6920-1b57-4cd1-8799-d877173bfa37'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
it 'sets attributes to GetnetApi' do
|
15
24
|
expect(GetnetApi.seller_id).to eq 'seller_id'
|
16
25
|
expect(GetnetApi.client_id).to eq 'client_id'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Credit do
|
4
|
+
let(:card) do
|
5
|
+
GetnetApi::Card.new(
|
6
|
+
number_token: 'dfe05208b105578c070f806c80abd3af09e246827d29b866cf4ce16c205849977c9496cbf0d0234f42339937f327747075f68763537b90b31389e01231d4d13c',
|
7
|
+
cardholder_name: 'JOAO DA SILVA',
|
8
|
+
security_code: '123',
|
9
|
+
brand: 'Mastercard',
|
10
|
+
expiration_month: '12',
|
11
|
+
expiration_year: '20'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:credit) do
|
16
|
+
GetnetApi::Credit.new(
|
17
|
+
delayed: false,
|
18
|
+
authenticated: false,
|
19
|
+
pre_authorization: false,
|
20
|
+
save_card_data: false,
|
21
|
+
transaction_type: 'FULL',
|
22
|
+
number_installments: 1,
|
23
|
+
soft_descriptor: 'Descrição para fatura',
|
24
|
+
dynamic_mcc: 1799,
|
25
|
+
card: card
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is valid with valid attributes' do
|
30
|
+
expect(credit).to be_valid
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is not valid with transaction type length > 22' do
|
34
|
+
credit.transaction_type = 'A' * 23
|
35
|
+
expect(credit).not_to be_valid
|
36
|
+
expect(credit.errors.messages[:transaction_type]).to be_present
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is not valid without number installments' do
|
40
|
+
credit.number_installments = nil
|
41
|
+
expect(credit).not_to be_valid
|
42
|
+
expect(credit.errors.messages[:number_installments]).to be_present
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'is not valid with soft descriptor length > 22' do
|
46
|
+
credit.soft_descriptor = 'A' * 23
|
47
|
+
expect(credit).not_to be_valid
|
48
|
+
expect(credit.errors.messages[:soft_descriptor]).to be_present
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is not valid with dynamic mcc length > 10' do
|
52
|
+
credit.dynamic_mcc = 'A' * 11
|
53
|
+
expect(credit).not_to be_valid
|
54
|
+
expect(credit.errors.messages[:dynamic_mcc]).to be_present
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#to_request' do
|
58
|
+
it 'returns credit object as a hash' do
|
59
|
+
credit_hash = credit.to_request
|
60
|
+
hash_keys = credit_hash.keys.reject { |k| k == :card }
|
61
|
+
hash_keys.each do |key|
|
62
|
+
expect(credit_hash[key]).to eq credit.send(key)
|
63
|
+
end
|
64
|
+
|
65
|
+
expect(credit_hash[:card]).to eq credit.card.to_request
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Customer do
|
4
|
+
let(:address) do
|
5
|
+
GetnetApi::Address.new(
|
6
|
+
street: 'Nome da Rua',
|
7
|
+
number: '123',
|
8
|
+
complement: 'Complemento',
|
9
|
+
district: 'Nome do Bairro',
|
10
|
+
city: 'São Paulo',
|
11
|
+
state: 'SP',
|
12
|
+
country: 'Brasil',
|
13
|
+
postal_code: '01010010'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:customer) do
|
18
|
+
GetnetApi::Customer.new(
|
19
|
+
customer_id: '123',
|
20
|
+
first_name: 'João',
|
21
|
+
last_name: 'da Silva',
|
22
|
+
name: 'João da Silva',
|
23
|
+
email: 'joao@email.com',
|
24
|
+
document_type: :pessoa_fisica,
|
25
|
+
document_number: '12332112340',
|
26
|
+
address: address,
|
27
|
+
phone_number: '5551999887766',
|
28
|
+
celphone_number: '5551999887766',
|
29
|
+
observation: 'O cliente tem interesse no plano x.'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is valid with valid attributes' do
|
34
|
+
expect(customer).to be_valid
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is not valid with customer id length > 100' do
|
38
|
+
customer.customer_id = '1' * 101
|
39
|
+
expect(customer).not_to be_valid
|
40
|
+
expect(customer.errors.messages[:customer_id]).to be_present
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is not valid with first name length > 40' do
|
44
|
+
customer.first_name = 'A' * 41
|
45
|
+
expect(customer).not_to be_valid
|
46
|
+
expect(customer.errors.messages[:first_name]).to be_present
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'is not valid with last name length > 80' do
|
50
|
+
customer.last_name = 'A' * 81
|
51
|
+
expect(customer).not_to be_valid
|
52
|
+
expect(customer.errors.messages[:last_name]).to be_present
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'is not valid with name length > 100' do
|
56
|
+
customer.name = 'A' * 101
|
57
|
+
expect(customer).not_to be_valid
|
58
|
+
expect(customer.errors.messages[:name]).to be_present
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'is not valid with email length > 100' do
|
62
|
+
customer.email = 'A' * 101
|
63
|
+
expect(customer).not_to be_valid
|
64
|
+
expect(customer.errors.messages[:email]).to be_present
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'is not valid with document number length > 15' do
|
68
|
+
customer.document_number = '1' * 16
|
69
|
+
expect(customer).not_to be_valid
|
70
|
+
expect(customer.errors.messages[:document_number]).to be_present
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'is not valid with document number length < 11' do
|
74
|
+
customer.document_number = '1' * 10
|
75
|
+
expect(customer).not_to be_valid
|
76
|
+
expect(customer.errors.messages[:document_number]).to be_present
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'is not valid with phone number length > 15' do
|
80
|
+
customer.phone_number = '1' * 16
|
81
|
+
expect(customer).not_to be_valid
|
82
|
+
expect(customer.errors.messages[:phone_number]).to be_present
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'is not valid with observation length > 140' do
|
86
|
+
customer.observation = '1' * 141
|
87
|
+
expect(customer).not_to be_valid
|
88
|
+
expect(customer.errors.messages[:observation]).to be_present
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'is not valid with address not being the correct object' do
|
92
|
+
customer.address = Object.new
|
93
|
+
expect(customer).not_to be_valid
|
94
|
+
expect(customer.errors.messages[:address]).to be_present
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'is not valid with invalid address' do
|
98
|
+
customer.address.street = 'A' * 61
|
99
|
+
expect(customer).not_to be_valid
|
100
|
+
expect(customer.errors.messages[:address]).to be_present
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'is not valid with document type with invalid key' do
|
104
|
+
customer.document_type = :invalid
|
105
|
+
expect(customer).not_to be_valid
|
106
|
+
expect(customer.errors.messages[:document_type]).to be_present
|
107
|
+
end
|
108
|
+
|
109
|
+
context '#to_request' do
|
110
|
+
it 'returns customer object as a hash' do
|
111
|
+
customer_hash = customer.to_request(:payment)
|
112
|
+
hash_keys = customer_hash.keys.reject do |key|
|
113
|
+
%i[billing_address document_type].include?(key)
|
114
|
+
end
|
115
|
+
hash_keys.each do |key|
|
116
|
+
expect(customer_hash[key]).to eq customer.send(key)
|
117
|
+
end
|
118
|
+
expect(customer_hash[:billing_address]).to eq customer.address.to_request
|
119
|
+
expect(customer_hash[:document_type]).to eq 'CPF'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.create', :vcr do
|
124
|
+
it 'performs the request' do
|
125
|
+
GetnetApi::Customer.create customer
|
126
|
+
expected_uri = 'https://api-sandbox.getnet.com.br/v1/customers'
|
127
|
+
expect(WebMock).to have_requested(:post, expected_uri)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Order do
|
4
|
+
let(:order) do
|
5
|
+
GetnetApi::Order.new(
|
6
|
+
order_id: '123',
|
7
|
+
sales_tax: 0,
|
8
|
+
product_type: 'service'
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is valid with valid attributes' do
|
13
|
+
expect(order).to be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'is not valid with order id length > 36' do
|
17
|
+
order.order_id = '1' * 37
|
18
|
+
expect(order).not_to be_valid
|
19
|
+
expect(order.errors.messages[:order_id]).to be_present
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#to_request' do
|
23
|
+
it 'returns order object as a hash' do
|
24
|
+
order_hash = order.to_request
|
25
|
+
order_hash.keys.each do |key|
|
26
|
+
expect(order_hash[key]).to eq order.send(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Payment do
|
4
|
+
|
5
|
+
let(:card_token) do
|
6
|
+
token = ''
|
7
|
+
VCR.use_cassette('getnet_api/cardtoken/get') do
|
8
|
+
card_number = '5155901222280001' # see https://developers.getnet.com.br/api#section/Cartoes-para-Teste
|
9
|
+
token = GetnetApi::CardToken.get(card_number)['number_token']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:card) do
|
14
|
+
GetnetApi::Card.new(
|
15
|
+
number_token: card_token,
|
16
|
+
cardholder_name: 'JOAO DA SILVA',
|
17
|
+
security_code: '123',
|
18
|
+
brand: 'Mastercard',
|
19
|
+
expiration_month: '12',
|
20
|
+
expiration_year: '23'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:credit) do
|
25
|
+
GetnetApi::Credit.new(
|
26
|
+
delayed: false,
|
27
|
+
authenticated: false,
|
28
|
+
pre_authorization: false,
|
29
|
+
save_card_data: false,
|
30
|
+
transaction_type: 'FULL',
|
31
|
+
number_installments: 1,
|
32
|
+
soft_descriptor: 'Descrição para fatura',
|
33
|
+
dynamic_mcc: 1799,
|
34
|
+
card: card
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:address) do
|
39
|
+
GetnetApi::Address.new(
|
40
|
+
street: 'Nome da Rua',
|
41
|
+
number: '123',
|
42
|
+
complement: 'Complemento',
|
43
|
+
district: 'Nome do Bairro',
|
44
|
+
city: 'São Paulo',
|
45
|
+
state: 'SP',
|
46
|
+
country: 'Brasil',
|
47
|
+
postal_code: '01010010'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:customer) do
|
52
|
+
GetnetApi::Customer.new(
|
53
|
+
customer_id: '123',
|
54
|
+
first_name: 'João',
|
55
|
+
last_name: 'da Silva',
|
56
|
+
name: 'João da Silva',
|
57
|
+
email: 'joao@email.com',
|
58
|
+
document_type: :pessoa_fisica,
|
59
|
+
document_number: '12332112340',
|
60
|
+
address: address,
|
61
|
+
phone_number: '5551999887766',
|
62
|
+
celphone_number: '5551999887766',
|
63
|
+
observation: 'O cliente tem interesse no plano x.'
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:order) do
|
68
|
+
GetnetApi::Order.new(
|
69
|
+
order_id: '123',
|
70
|
+
sales_tax: 0,
|
71
|
+
product_type: 'service'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:payment) do
|
76
|
+
GetnetApi::Payment.new(
|
77
|
+
amount: 100,
|
78
|
+
currency: 'BRL',
|
79
|
+
order: order,
|
80
|
+
customer: customer
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:payment_cancel) do
|
85
|
+
GetnetApi::PaymentCancel.new(
|
86
|
+
payment_id: "79447fe6-8672-4187-85de-11c4bab37aab",
|
87
|
+
cancel_amount: 100
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'is valid with valid attributes' do
|
92
|
+
expect(payment_cancel).to be_valid
|
93
|
+
end
|
94
|
+
|
95
|
+
context '#to_request' do
|
96
|
+
it 'returns card object as a hash' do
|
97
|
+
payment_cancel_hash = payment_cancel.to_request
|
98
|
+
payment_cancel_hash.keys.each do |key|
|
99
|
+
expect(payment_cancel_hash[key]).to eq payment_cancel.send(key)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context '.create' do
|
105
|
+
context 'when cancelling a payment', :vcr do
|
106
|
+
it 'correctly execute the request' do
|
107
|
+
response = GetnetApi::Payment.create payment, credit, :credit
|
108
|
+
payment_id = response['payment_id']
|
109
|
+
payment_cancel = GetnetApi::PaymentCancel.new(
|
110
|
+
payment_id: payment_id,
|
111
|
+
cancel_amount: 100
|
112
|
+
)
|
113
|
+
response_cancelamento = GetnetApi::PaymentCancel.create payment_cancel
|
114
|
+
|
115
|
+
expected_uri = "https://api-sandbox.getnet.com.br/v1/payments/credit/#{payment_id}/cancel"
|
116
|
+
expect(WebMock).to have_requested(:post, expected_uri)
|
117
|
+
expect(response_cancelamento["status"]).to eq("CANCELED")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe GetnetApi::Payment do
|
4
|
+
let(:boleto) do
|
5
|
+
GetnetApi::Boleto.new(
|
6
|
+
our_number: '123321123',
|
7
|
+
document_number: '12345678',
|
8
|
+
instructions: 'Não receber após o vencimento',
|
9
|
+
provider: 'santander'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:card_token) do
|
14
|
+
token = ''
|
15
|
+
VCR.use_cassette('getnet_api/cardtoken/get') do
|
16
|
+
card_number = '5155901222280001' # see https://developers.getnet.com.br/api#section/Cartoes-para-Teste
|
17
|
+
token = GetnetApi::CardToken.get(card_number)['number_token']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:card) do
|
22
|
+
GetnetApi::Card.new(
|
23
|
+
number_token: card_token,
|
24
|
+
cardholder_name: 'JOAO DA SILVA',
|
25
|
+
security_code: '123',
|
26
|
+
brand: 'Mastercard',
|
27
|
+
expiration_month: '12',
|
28
|
+
expiration_year: '23'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:credit) do
|
33
|
+
GetnetApi::Credit.new(
|
34
|
+
delayed: false,
|
35
|
+
authenticated: false,
|
36
|
+
pre_authorization: false,
|
37
|
+
save_card_data: false,
|
38
|
+
transaction_type: 'FULL',
|
39
|
+
number_installments: 1,
|
40
|
+
soft_descriptor: 'Descrição para fatura',
|
41
|
+
dynamic_mcc: 1799,
|
42
|
+
card: card
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:address) do
|
47
|
+
GetnetApi::Address.new(
|
48
|
+
street: 'Nome da Rua',
|
49
|
+
number: '123',
|
50
|
+
complement: 'Complemento',
|
51
|
+
district: 'Nome do Bairro',
|
52
|
+
city: 'São Paulo',
|
53
|
+
state: 'SP',
|
54
|
+
country: 'Brasil',
|
55
|
+
postal_code: '01010010'
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:customer) do
|
60
|
+
GetnetApi::Customer.new(
|
61
|
+
customer_id: '123',
|
62
|
+
first_name: 'João',
|
63
|
+
last_name: 'da Silva',
|
64
|
+
name: 'João da Silva',
|
65
|
+
email: 'joao@email.com',
|
66
|
+
document_type: :pessoa_fisica,
|
67
|
+
document_number: '12332112340',
|
68
|
+
address: address,
|
69
|
+
phone_number: '5551999887766',
|
70
|
+
celphone_number: '5551999887766',
|
71
|
+
observation: 'O cliente tem interesse no plano x.'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:order) do
|
76
|
+
GetnetApi::Order.new(
|
77
|
+
order_id: '123',
|
78
|
+
sales_tax: 0,
|
79
|
+
product_type: 'service'
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:payment) do
|
84
|
+
GetnetApi::Payment.new(
|
85
|
+
amount: 10_000,
|
86
|
+
currency: 'BRL',
|
87
|
+
order: order,
|
88
|
+
customer: customer
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'is valid with valid attributes' do
|
93
|
+
expect(payment).to be_valid
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'is not valid with currency length > 3' do
|
97
|
+
payment.currency = 'ABCD'
|
98
|
+
expect(payment).not_to be_valid
|
99
|
+
expect(payment.errors.messages[:currency]).to be_present
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'is not valid with order not being the correct object' do
|
103
|
+
payment.order = Object.new
|
104
|
+
expect(payment).not_to be_valid
|
105
|
+
expect(payment.errors.messages[:order]).to be_present
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'is not valid with invalid order' do
|
109
|
+
payment.order.order_id = '1' * 37
|
110
|
+
expect(payment).not_to be_valid
|
111
|
+
expect(payment.errors.messages[:order]).to be_present
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'is not valid with customer not being the correct object' do
|
115
|
+
payment.customer = Object.new
|
116
|
+
expect(payment).not_to be_valid
|
117
|
+
expect(payment.errors.messages[:customer]).to be_present
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'is not valid with invalid customer' do
|
121
|
+
payment.customer.customer_id = '1' * 101
|
122
|
+
expect(payment).not_to be_valid
|
123
|
+
expect(payment.errors.messages[:customer]).to be_present
|
124
|
+
end
|
125
|
+
|
126
|
+
context '#to_request' do
|
127
|
+
it 'returns payment object as a hash' do
|
128
|
+
payment_hash = payment.to_request(credit, :credit)
|
129
|
+
hash_keys = payment_hash.keys.reject do |key|
|
130
|
+
%i[order customer credit seller_id].include?(key)
|
131
|
+
end
|
132
|
+
|
133
|
+
hash_keys.each do |key|
|
134
|
+
expect(payment_hash[key]).to eq payment.send(key)
|
135
|
+
end
|
136
|
+
|
137
|
+
expect(payment_hash[:order]).to eq payment.order.to_request
|
138
|
+
expect(payment_hash[:customer]).to eq payment.customer.to_request(:payment)
|
139
|
+
expect(payment_hash[:credit]).to eq credit.to_request
|
140
|
+
expect(payment_hash[:seller_id]).to eq GetnetApi.seller_id.to_s
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context '.create' do
|
145
|
+
context 'when paying by boleto', :vcr do
|
146
|
+
it 'correctly requests for boleto payment' do
|
147
|
+
response = GetnetApi::Payment.create payment, boleto, :boleto
|
148
|
+
expected_uri = 'https://api-sandbox.getnet.com.br/v1/payments/boleto'
|
149
|
+
expect(WebMock).to have_requested(:post, expected_uri)
|
150
|
+
expect(response).to have_key('boleto')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when paying by credit', :vcr do
|
155
|
+
it 'correctly requests for credit payment' do
|
156
|
+
response = GetnetApi::Payment.create payment, credit, :credit
|
157
|
+
expected_uri = 'https://api-sandbox.getnet.com.br/v1/payments/credit'
|
158
|
+
expect(WebMock).to have_requested(:post, expected_uri)
|
159
|
+
expect(response).to have_key('credit')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -37,24 +37,24 @@ http_interactions:
|
|
37
37
|
Content-Type:
|
38
38
|
- application/json;charset=UTF-8
|
39
39
|
X-Edgeconnect-Midmile-Rtt:
|
40
|
-
- '
|
40
|
+
- '8'
|
41
41
|
X-Edgeconnect-Origin-Mex-Latency:
|
42
|
-
- '
|
42
|
+
- '43'
|
43
43
|
X-Powered-By:
|
44
|
-
- '
|
44
|
+
- '62207'
|
45
45
|
Vary:
|
46
46
|
- Accept-Encoding
|
47
47
|
Date:
|
48
|
-
-
|
48
|
+
- Wed, 14 Apr 2021 14:08:33 GMT
|
49
49
|
Content-Length:
|
50
50
|
- '127'
|
51
51
|
Connection:
|
52
52
|
- keep-alive
|
53
53
|
body:
|
54
54
|
encoding: UTF-8
|
55
|
-
string: "{\r\n \"access_token\":\"
|
55
|
+
string: "{\r\n \"access_token\":\"43bfa02b-8577-485e-83ca-b2f6383afb01\",\r\n
|
56
56
|
\ \"token_type\":\"Bearer\",\r\n \"expires_in\":3600,\r\n \"scope\":\"oob\"\r\n}"
|
57
|
-
recorded_at:
|
57
|
+
recorded_at: Wed, 14 Apr 2021 14:08:33 GMT
|
58
58
|
- request:
|
59
59
|
method: get
|
60
60
|
uri: https://api-sandbox.getnet.com.br/v1/some_endpoint
|
@@ -71,7 +71,7 @@ http_interactions:
|
|
71
71
|
Host:
|
72
72
|
- api-sandbox.getnet.com.br
|
73
73
|
Authorization:
|
74
|
-
- Bearer
|
74
|
+
- Bearer 43bfa02b-8577-485e-83ca-b2f6383afb01
|
75
75
|
Content-Type:
|
76
76
|
- application/json
|
77
77
|
Seller-Id:
|
@@ -92,15 +92,15 @@ http_interactions:
|
|
92
92
|
Content-Type:
|
93
93
|
- application/json;charset=utf-8
|
94
94
|
X-Edgeconnect-Midmile-Rtt:
|
95
|
-
- '
|
95
|
+
- '6'
|
96
96
|
X-Edgeconnect-Origin-Mex-Latency:
|
97
|
-
- '
|
97
|
+
- '50'
|
98
98
|
X-Powered-By:
|
99
|
-
- '
|
99
|
+
- '62208'
|
100
100
|
Vary:
|
101
101
|
- Accept-Encoding
|
102
102
|
Date:
|
103
|
-
-
|
103
|
+
- Wed, 14 Apr 2021 14:08:33 GMT
|
104
104
|
Content-Length:
|
105
105
|
- '196'
|
106
106
|
Connection:
|
@@ -109,5 +109,5 @@ http_interactions:
|
|
109
109
|
encoding: UTF-8
|
110
110
|
string: '{"message":"Not Found","name":"GatewayClientError","status_code":404,"details":[{"status":"DENIED","error_code":"GENERIC-404","description":"Not
|
111
111
|
Found","description_detail":"Resource not found"}]}'
|
112
|
-
recorded_at:
|
112
|
+
recorded_at: Wed, 14 Apr 2021 14:08:33 GMT
|
113
113
|
recorded_with: VCR 6.0.0
|