-
Notifications
You must be signed in to change notification settings - Fork 52
/
test_card.rb
78 lines (66 loc) · 2 KB
/
test_card.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# typed: true
# frozen_string_literal: true
require_relative '../lib/mercadopago'
require 'minitest/autorun'
class TestCard < Minitest::Test
def test_all
sdk = Mercadopago::SDK.new('TEST-783169576377080-082620-395ee7f82e0d55b1db606c118686c1db-464842924')
customer_object = {
email: '[email protected]',
first_name: 'Rafa',
last_name: 'Williner',
phone: {
area_code: '03492',
number: '432334'
},
identification: {
type: 'DNI',
number: '29804555'
},
address: {
street_name: 'some street'
},
description: 'customer description'
}
customer_saved = sdk.customer.create(customer_object)
assert_equal 201, customer_saved[:status]
customer_id = customer_saved[:response]['id']
sleep(1)
card_token_object = {
card_number: '5031433215406351',
expiration_year: 2025,
expiration_month: 11,
security_code: '123',
cardholder: {
name: 'APRO'
}
}
begin
card_token = sdk.card_token.create(card_token_object)
card_object = {
token: card_token[:response]['id']
}
card_saved = sdk.card.create(customer_id, card_object)
assert !card_saved.nil?
assert !card_saved[:response].nil?
assert !card_saved[:response]['id'].nil?
sleep(1)
cards = sdk.card.list(customer_id)
assert !cards.nil?
assert !cards[:response].nil?
assert !cards[:response].empty?
sleep(1)
card_get = sdk.card.get(customer_id, card_saved[:response]['id'])
assert_equal 200, card_get[:status]
sleep(1)
card_deleted = sdk.card.delete(customer_id, card_saved[:response]['id'])
assert_equal 200, card_deleted[:status]
sleep(1)
ensure
if customer_saved.key?(:response) && customer_saved[:response].key?('id')
customer_deleted = sdk.customer.delete(customer_saved[:response]['id'])
assert_equal 200, customer_deleted[:status]
end
end
end
end