conekta-tiempometa 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +124 -0
- data/Dockerfile +44 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +182 -0
- data/Rakefile +1 -0
- data/conekta.gemspec +29 -0
- data/lib/conekta/address.rb +5 -0
- data/lib/conekta/card.rb +21 -0
- data/lib/conekta/charge.rb +25 -0
- data/lib/conekta/conekta_object.rb +109 -0
- data/lib/conekta/customer.rb +82 -0
- data/lib/conekta/customer_info.rb +5 -0
- data/lib/conekta/destination.rb +17 -0
- data/lib/conekta/details.rb +5 -0
- data/lib/conekta/discount_line.rb +19 -0
- data/lib/conekta/error.rb +99 -0
- data/lib/conekta/error_details.rb +14 -0
- data/lib/conekta/event.rb +9 -0
- data/lib/conekta/line_item.rb +21 -0
- data/lib/conekta/list.rb +59 -0
- data/lib/conekta/log.rb +10 -0
- data/lib/conekta/method.rb +4 -0
- data/lib/conekta/operations/create.rb +19 -0
- data/lib/conekta/operations/create_member.rb +40 -0
- data/lib/conekta/operations/custom_action.rb +13 -0
- data/lib/conekta/operations/delete.rb +45 -0
- data/lib/conekta/operations/find.rb +21 -0
- data/lib/conekta/operations/update.rb +11 -0
- data/lib/conekta/operations/where.rb +30 -0
- data/lib/conekta/order.rb +87 -0
- data/lib/conekta/payee.rb +66 -0
- data/lib/conekta/payment_method.rb +4 -0
- data/lib/conekta/payment_source.rb +17 -0
- data/lib/conekta/payout.rb +7 -0
- data/lib/conekta/payout_method.rb +17 -0
- data/lib/conekta/plan.rb +16 -0
- data/lib/conekta/refund.rb +6 -0
- data/lib/conekta/requestor.rb +80 -0
- data/lib/conekta/resource.rb +54 -0
- data/lib/conekta/return.rb +12 -0
- data/lib/conekta/shipping_contact.rb +19 -0
- data/lib/conekta/shipping_line.rb +20 -0
- data/lib/conekta/subscription.rb +25 -0
- data/lib/conekta/tax_line.rb +19 -0
- data/lib/conekta/token.rb +8 -0
- data/lib/conekta/transfer.rb +7 -0
- data/lib/conekta/util.rb +136 -0
- data/lib/conekta/version.rb +3 -0
- data/lib/conekta/webhook.rb +12 -0
- data/lib/conekta/webhook_log.rb +4 -0
- data/lib/conekta.rb +101 -0
- data/lib/ssl_data/ca_bundle.crt +3955 -0
- data/locales/en.yml +9 -0
- data/locales/es.yml +10 -0
- data/readme_files/banner.png +0 -0
- data/readme_files/conekta-badge.png +0 -0
- data/readme_files/ruby-badge.png +0 -0
- data/spec/conekta/1.0.0/.DS_Store +0 -0
- data/spec/conekta/1.0.0/card_spec.rb +40 -0
- data/spec/conekta/1.0.0/charge_spec.rb +152 -0
- data/spec/conekta/1.0.0/customer_spec.rb +147 -0
- data/spec/conekta/1.0.0/error_spec.rb +69 -0
- data/spec/conekta/1.0.0/event_spec.rb +26 -0
- data/spec/conekta/1.0.0/log_spec.rb +20 -0
- data/spec/conekta/1.0.0/payout_spec.rb +60 -0
- data/spec/conekta/1.0.0/plan_spec.rb +53 -0
- data/spec/conekta/1.0.0/token_spec.rb +5 -0
- data/spec/conekta/1.0.0/webhook_spec.rb +36 -0
- data/spec/conekta/2.0.0/customer_spec.rb +77 -0
- data/spec/conekta/2.0.0/discount_line_spec.rb +49 -0
- data/spec/conekta/2.0.0/error_spec.rb +61 -0
- data/spec/conekta/2.0.0/line_item_spec.rb +53 -0
- data/spec/conekta/2.0.0/list_spec.rb +29 -0
- data/spec/conekta/2.0.0/order_spec.rb +291 -0
- data/spec/conekta/2.0.0/payee_spec.rb +55 -0
- data/spec/conekta/2.0.0/shipping_contact_spec.rb +60 -0
- data/spec/conekta/2.0.0/shipping_line_spec.rb +53 -0
- data/spec/conekta/2.0.0/source_spec.rb +31 -0
- data/spec/conekta/2.0.0/tax_line_spec.rb +44 -0
- data/spec/conekta/2.0.0/transfer_spec.rb +59 -0
- data/spec/conekta_spec.rb +29 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/fixtures/orders.json +1127 -0
- data/spec/support/shared_context.rb +49 -0
- metadata +229 -0
data/locales/en.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
en:
|
3
|
+
error:
|
4
|
+
resource:
|
5
|
+
id: 'Could not get the id of %{resource} instance.'
|
6
|
+
id_purchaser : 'There was an error. Please contact system administrator.'
|
7
|
+
requestor:
|
8
|
+
connection: 'Could not connect to %{base}.'
|
9
|
+
connection_purchaser: 'Could not connect to payment system.'
|
data/locales/es.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
es:
|
3
|
+
error:
|
4
|
+
resource:
|
5
|
+
id: 'No se pudo obtener el id de la instancia de %{resource}.'
|
6
|
+
id_purchaser: 'Hubo un error. Favor de contactar al administrador del sistema.'
|
7
|
+
requestor:
|
8
|
+
connection: 'No se pudo conectar a %{base}.'
|
9
|
+
connection_purchaser: 'No se pudo conectar al sistema de pagos.'
|
10
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Card do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
let(:customer_data) do
|
6
|
+
{
|
7
|
+
email: "hola@hola.com",
|
8
|
+
name: "John Constantine",
|
9
|
+
cards: ["tok_test_visa_4242"]
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:customer) do
|
14
|
+
Conekta::Customer.create(customer_data)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:card) { customer.cards.first }
|
18
|
+
|
19
|
+
context "deleting cards" do
|
20
|
+
it "successful card delete" do
|
21
|
+
card.delete
|
22
|
+
|
23
|
+
expect(card.deleted).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "updating cards" do
|
28
|
+
it "successful card update" do
|
29
|
+
card.update(active: false)
|
30
|
+
|
31
|
+
expect(card.active).to eq(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "unsuccessful card update" do
|
35
|
+
expect {
|
36
|
+
card.update(token: "tok_test_visa_4241")
|
37
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Charge do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
|
6
|
+
let(:payment_method) do
|
7
|
+
{
|
8
|
+
amount: 2000,
|
9
|
+
currency: 'mxn',
|
10
|
+
description: 'Some desc',
|
11
|
+
details: {
|
12
|
+
name: "Wolverine",
|
13
|
+
email: "logan.thomas@xmen.org",
|
14
|
+
phone: "403-342-0642",
|
15
|
+
line_items: [{
|
16
|
+
name: "Shades",
|
17
|
+
description: "Imported From Mex.",
|
18
|
+
unit_price: 20000,
|
19
|
+
quantity: 1,
|
20
|
+
sku: "cohb_s1",
|
21
|
+
category: "eyewear"
|
22
|
+
}]
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:invalid_payment_method) do
|
28
|
+
{
|
29
|
+
amount: 10,
|
30
|
+
currency: 'mxn',
|
31
|
+
description: 'Some desc',
|
32
|
+
details: {
|
33
|
+
name: "Wolverine",
|
34
|
+
email: "logan.thomas@xmen.org",
|
35
|
+
phone: "403-342-0642",
|
36
|
+
line_items: [{
|
37
|
+
name: "Shades",
|
38
|
+
description: "Imported From Mex.",
|
39
|
+
unit_price: 20000,
|
40
|
+
quantity: 1,
|
41
|
+
sku: "cohb_s1",
|
42
|
+
category: "eyewear"
|
43
|
+
}]
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:card) { { card: 'tok_test_visa_4242' } }
|
49
|
+
|
50
|
+
context "get" do
|
51
|
+
it "succesfully gets charge" do
|
52
|
+
transaction = Conekta::Charge.create(payment_method.merge(card))
|
53
|
+
expect(transaction.status).to eq("paid")
|
54
|
+
charge = Conekta::Charge.find(transaction.id)
|
55
|
+
expect(charge).to be_a(Conekta::Charge)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "test succesful where" do
|
59
|
+
charges = Conekta::Charge.where
|
60
|
+
charge = charges.first
|
61
|
+
expect(charge).to be_a(Conekta::Charge)
|
62
|
+
end
|
63
|
+
it "test succesful where status 'pending_payment'" do
|
64
|
+
charges = Conekta::Charge.where({status: 'pending_payment'})
|
65
|
+
charges.map{|index, charge|
|
66
|
+
expect(charge.status).to eq("pending_payment")
|
67
|
+
}
|
68
|
+
end
|
69
|
+
it "test succesful where status 'paid'" do
|
70
|
+
charges = Conekta::Charge.where({status: 'paid'})
|
71
|
+
charges.map{|index, charge|
|
72
|
+
expect(charge.status).to eq("paid")
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "creating charges" do
|
78
|
+
it "tests succesful bank payment" do
|
79
|
+
bank = { bank: { 'type' => 'banorte' } }
|
80
|
+
bank_payment = Conekta::Charge.create(payment_method.merge(bank))
|
81
|
+
expect(bank_payment.status).to eq("pending_payment")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "tests succesful card payment" do
|
85
|
+
card_payment = Conekta::Charge.create(payment_method.merge(card))
|
86
|
+
expect(card_payment.status).to eq("paid")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "tests succesful oxxo payment" do
|
90
|
+
oxxo = { cash: { 'type' => 'oxxo' } }
|
91
|
+
cash_payment = Conekta::Charge.create(payment_method.merge(oxxo))
|
92
|
+
expect(cash_payment.status).to eq("pending_payment")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "tests succesful card payment capture" do
|
96
|
+
# pm = @valid_payment_method
|
97
|
+
# card = @valid_visa_card
|
98
|
+
capture = { capture: false }
|
99
|
+
transaction = Conekta::Charge.create(
|
100
|
+
payment_method.merge(card).merge(capture)
|
101
|
+
)
|
102
|
+
expect(transaction.status).to eq("pre_authorized")
|
103
|
+
transaction.capture
|
104
|
+
expect(transaction.status).to eq("paid")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "test unsuccesful create" do
|
108
|
+
expect {
|
109
|
+
Conekta::Charge.create(invalid_payment_method.merge(card))
|
110
|
+
}.to raise_error(
|
111
|
+
Conekta::ParameterValidationError,
|
112
|
+
"The minimum for card payments is 3 pesos. Check that the amount " +
|
113
|
+
"is in cents as explained in the documentation."
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "refunding charges" do
|
119
|
+
it "test susccesful refund" do
|
120
|
+
transaction = Conekta::Charge.create(payment_method.merge(card))
|
121
|
+
expect(transaction.status).to eq("paid")
|
122
|
+
transaction.refund
|
123
|
+
expect(transaction.status).to eq("refunded")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "test unsusccesful refund" do
|
127
|
+
transaction = Conekta::Charge.create(payment_method.merge(card))
|
128
|
+
expect(transaction.status).to eq("paid")
|
129
|
+
|
130
|
+
expect { transaction.refund(3000) }.to raise_error(
|
131
|
+
Conekta::ProcessingError,
|
132
|
+
"The amount to refund exceeds the charge total."
|
133
|
+
)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'capturing charges' do
|
138
|
+
it 'captures an existing charge' do
|
139
|
+
amount_before_capture = 2000
|
140
|
+
amount_after_capture = 1000
|
141
|
+
capture = { capture: false }
|
142
|
+
transaction = Conekta::Charge.create(
|
143
|
+
payment_method.merge(card).merge(capture)
|
144
|
+
)
|
145
|
+
expect(transaction.status).to eq('pre_authorized')
|
146
|
+
expect(transaction.amount).to be == amount_before_capture
|
147
|
+
transaction.capture(1000)
|
148
|
+
expect(transaction.amount).to be == amount_after_capture
|
149
|
+
expect(transaction.status).to eq("paid")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Customer do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
let(:customer_data) { { :cards => ["tok_test_visa_4242"], email: "test@gmail.com", name: "Mario" } }
|
6
|
+
|
7
|
+
context "creating customers" do
|
8
|
+
it "successful customer create" do
|
9
|
+
customer = Conekta::Customer.create(customer_data)
|
10
|
+
expect(customer).to be_a(Conekta::Customer)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "unsuccessful customer create" do
|
14
|
+
expect { Conekta::Customer.create(
|
15
|
+
:cards => ["tok_test_visa_4241"],
|
16
|
+
:name => "Mario",
|
17
|
+
:email => "test@gmail.com"
|
18
|
+
) }.to raise_error(
|
19
|
+
Conekta::ParameterValidationError,
|
20
|
+
"The token does not exist."
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "getting customers" do
|
26
|
+
it "successful customer get" do
|
27
|
+
transaction = Conekta::Customer.create(customer_data)
|
28
|
+
customer = Conekta::Customer.find(transaction.id)
|
29
|
+
expect(customer).to be_a(Conekta::Customer)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "successful customer where" do
|
33
|
+
customers = Conekta::Customer.where
|
34
|
+
expect(customers.class.class_name).to eq("ConektaObject")
|
35
|
+
expect(customers.first).to be_a(Conekta::Customer)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "updating customers" do
|
40
|
+
it "successful customer update" do
|
41
|
+
customer = Conekta::Customer.create({
|
42
|
+
:cards => ["tok_test_visa_4242"],
|
43
|
+
:name => "Mario",
|
44
|
+
:email => "test@gmail.com"
|
45
|
+
})
|
46
|
+
customer.update({name: 'Logan', email: 'logan@x-men.org'})
|
47
|
+
expect(customer.name).to eq('Logan')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "deleting customers" do
|
52
|
+
it "successful customer delete" do
|
53
|
+
customer = Conekta::Customer.create(customer_data)
|
54
|
+
customer.delete
|
55
|
+
expect(customer.deleted).to eq(true)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "adding cards" do
|
60
|
+
let!(:customer) { Conekta::Customer.create(customer_data) }
|
61
|
+
|
62
|
+
it "add card to customer" do
|
63
|
+
card = customer.create_card(:token => 'tok_test_visa_1881')
|
64
|
+
expect(customer.cards.count).to eq(2)
|
65
|
+
expect(customer.cards.last.last4).to eq('1881')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "test delete card" do
|
69
|
+
card = customer.cards[0].delete
|
70
|
+
expect(card.deleted).to eq(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "test update card" do
|
74
|
+
customer.cards[0].update(token: 'tok_test_mastercard_4444', active: false)
|
75
|
+
expect(customer.cards[0].last4).to eq('4444')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "managing subscriptions" do
|
80
|
+
let!(:customer) { Conekta::Customer.create(customer_data) }
|
81
|
+
|
82
|
+
context "create" do
|
83
|
+
it "test succesful create subscription" do
|
84
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
85
|
+
expect(subscription.class.class_name).to eq('Subscription')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "test unsuccesful create subscription" do
|
89
|
+
expect { customer.create_subscription({plan: 'unexistent-plan'}) }.to \
|
90
|
+
raise_error(
|
91
|
+
Conekta::ResourceNotFoundError,
|
92
|
+
'The object Plan "unexistent-plan" could not be found.'
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "update" do
|
98
|
+
it "test succesful update subscription" do
|
99
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
100
|
+
plan = find_or_create_plan('gold-plan2')
|
101
|
+
|
102
|
+
subscription.update({plan: plan.id})
|
103
|
+
expect(subscription.plan_id).to eq('gold-plan2')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "pause/resume" do
|
108
|
+
let!(:subscription) { customer.create_subscription({plan: 'gold-plan'}) }
|
109
|
+
|
110
|
+
it "test succesful pause subscription" do
|
111
|
+
subscription.pause
|
112
|
+
expect(subscription.status).to eq('paused')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "test succesful resume subscription" do
|
116
|
+
subscription.pause
|
117
|
+
expect(subscription.status).to eq('paused')
|
118
|
+
subscription.resume
|
119
|
+
expect(subscription.status).to_not eq('paused')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "cancel" do
|
124
|
+
it "test succesful cancel subscription" do
|
125
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
126
|
+
subscription.cancel
|
127
|
+
expect(subscription.status).to eq('canceled')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def find_or_create_plan(plan_id)
|
134
|
+
plan = Conekta::Plan.find(plan_id)
|
135
|
+
rescue Conekta::Error => e
|
136
|
+
plan = Conekta::Plan.create({
|
137
|
+
id: plan_id,
|
138
|
+
name: "Gold Plan",
|
139
|
+
amount: 10000,
|
140
|
+
currency: "MXN",
|
141
|
+
interval: "month",
|
142
|
+
frequency: 1,
|
143
|
+
trial_period_days: 15,
|
144
|
+
expiry_count: 12
|
145
|
+
})
|
146
|
+
return plan
|
147
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Error do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
let(:card) { { cards: ["tok_test_visa_4242"] } }
|
6
|
+
|
7
|
+
it "test no id error" do
|
8
|
+
expect { Conekta::Charge.find(nil) }.to raise_error(
|
9
|
+
Conekta::Error, "Could not get the id of Charge instance."
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "test no connection error" do
|
14
|
+
api_url = Conekta::api_base
|
15
|
+
Conekta::api_base = 'http://localhost:3001'
|
16
|
+
|
17
|
+
expect { Conekta::Customer.create(card) }.to raise_error(
|
18
|
+
Conekta::NoConnectionError, "Could not connect to http://localhost:3001."
|
19
|
+
)
|
20
|
+
|
21
|
+
# cleanup
|
22
|
+
Conekta::api_base = api_url
|
23
|
+
end
|
24
|
+
|
25
|
+
it "test api error" do
|
26
|
+
expect { Conekta::Customer.create({ cards: {0=>"tok_test_visa_4242"} }) }.to \
|
27
|
+
raise_error(Conekta::ParameterValidationError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "test authentication error" do
|
31
|
+
api_key = Conekta::api_key
|
32
|
+
Conekta::api_key = ""
|
33
|
+
expect { Conekta::Customer.create({ cards: ["tok_test_visa_4242"] }) }.to \
|
34
|
+
raise_error(Conekta::AuthenticationError)
|
35
|
+
|
36
|
+
# cleanup
|
37
|
+
Conekta.api_key = api_key
|
38
|
+
end
|
39
|
+
|
40
|
+
it "test parameter validation error" do
|
41
|
+
expect { Conekta::Plan.create({id: 'gold-plan'}) }.to raise_error(
|
42
|
+
Conekta::ParameterValidationError
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "test processing error" do
|
47
|
+
charge = nil
|
48
|
+
charges = Conekta::Charge.where()
|
49
|
+
charges.each do |(k,v)|
|
50
|
+
if v.status == "pre_authorized"
|
51
|
+
charge = v
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
begin
|
56
|
+
if charge
|
57
|
+
charge.capture
|
58
|
+
end
|
59
|
+
rescue Conekta::Error => e
|
60
|
+
expect(e.class_name).to eq("ProcessingError")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "test resource not found error" do
|
65
|
+
expect { Conekta::Charge.find(1) }.to raise_error(
|
66
|
+
Conekta::ResourceNotFoundError
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Event do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
it "test successful where" do
|
6
|
+
events = Conekta::Event.where
|
7
|
+
expect(events.class_name).to eq("ConektaObject")
|
8
|
+
expect(events[0].class_name).to eq("Event")
|
9
|
+
if !events[0].webhook_logs.empty?
|
10
|
+
expect(events[0].webhook_logs.first.class_name).to eq("WebhookLog")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "test successful find" do
|
15
|
+
events = Conekta::Event.where
|
16
|
+
e = events.first
|
17
|
+
|
18
|
+
event = Conekta::Event.find(e.id)
|
19
|
+
|
20
|
+
expect(event).to be_a(Conekta::Event)
|
21
|
+
expect(event.class_name).to eq("Event")
|
22
|
+
if !events[0].webhook_logs.empty?
|
23
|
+
expect(events[0].webhook_logs.first.class_name).to eq("WebhookLog")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Log do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
it "test successful where" do
|
6
|
+
events = Conekta::Log.where
|
7
|
+
expect(events.class_name).to eq("ConektaObject")
|
8
|
+
expect(events[0].class_name).to eq("Log")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "test successful find" do
|
12
|
+
events = Conekta::Log.where
|
13
|
+
e = events.first
|
14
|
+
|
15
|
+
event = Conekta::Log.find(e.id)
|
16
|
+
|
17
|
+
expect(event).to be_a(Conekta::Log)
|
18
|
+
expect(event.class_name).to eq("Log")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Payout do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
let(:payee_attributes) do
|
6
|
+
{
|
7
|
+
name: "John Doe", email: "j_d@radcorp.com", phone: "555555555",
|
8
|
+
billing_address:{
|
9
|
+
company_name: 'Rad Corp',
|
10
|
+
tax_id: 'tax121212abc',
|
11
|
+
street1: 'Guadalupe 73',
|
12
|
+
street2: 'Despacho 32',
|
13
|
+
street3: 'Condesa',
|
14
|
+
city: 'Cuauhtemoc',
|
15
|
+
state: 'DF',
|
16
|
+
country: 'MX',
|
17
|
+
zip: '06100'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:bank_attributes) do
|
23
|
+
{
|
24
|
+
account_number: '032180000118359719',
|
25
|
+
account_holder: 'J D - Radcorp',
|
26
|
+
description: 'Conekta To JD',
|
27
|
+
statement_description: 'Conekta To JD 111111111',
|
28
|
+
statement_reference: '111111111'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'an instance' do
|
33
|
+
before do
|
34
|
+
payee = Conekta::Payee.create(payee_attributes)
|
35
|
+
payout_method = payee.create_payout_method(bank_attributes)
|
36
|
+
|
37
|
+
@payee = Conekta::Payee.find(payee.id)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'is created successfully' do
|
41
|
+
payout = Conekta::Payout.create(
|
42
|
+
amount: 5000, currency: "MXN", payee: @payee.id
|
43
|
+
)
|
44
|
+
expect(payout).to be_a(Conekta::Payout)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can be retrieved by :id' do
|
48
|
+
transaction = Conekta::Payout.create(
|
49
|
+
amount: 5000, currency: "MXN", payee: @payee.id
|
50
|
+
)
|
51
|
+
# refetch payout
|
52
|
+
payout = Conekta::Payout.find(transaction.id)
|
53
|
+
expect(payout).to be_a(Conekta::Payout)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'has a :method attribute' do
|
57
|
+
expect(@payee.payout_methods.first).to be_a(Conekta::Method)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Plan do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
context "get/where" do
|
6
|
+
it "test succesful get plan" do
|
7
|
+
plans = Conekta::Plan.where
|
8
|
+
p = plans.first;
|
9
|
+
plan = Conekta::Plan.find(p.id)
|
10
|
+
expect(plan).to be_a(Conekta::Plan)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "test succesful where" do
|
14
|
+
plans = Conekta::Plan.where
|
15
|
+
expect(plans.class_name).to eq("ConektaObject")
|
16
|
+
expect(plans.first).to be_a(Conekta::Plan)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "creating plans" do
|
21
|
+
it "test succesful create plan" do
|
22
|
+
plan = Conekta::Plan.create(
|
23
|
+
id: ((0...8).map { (65 + rand(26)).chr }.join),
|
24
|
+
name: "Gold Plan",
|
25
|
+
amount: 10000,
|
26
|
+
currency: "MXN",
|
27
|
+
interval: "month",
|
28
|
+
frequency: 10,
|
29
|
+
trial_period_days: 15,
|
30
|
+
expiry_count: 12
|
31
|
+
)
|
32
|
+
expect(plan).to be_a(Conekta::Plan)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "updating plans" do
|
37
|
+
it "test update plan" do
|
38
|
+
plans = Conekta::Plan.where
|
39
|
+
plan = plans.first
|
40
|
+
plan.update({name: "Silver Plan"})
|
41
|
+
expect(plan.name).to eq("Silver Plan")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "deleting plans" do
|
46
|
+
it "test delete plan" do
|
47
|
+
plans = Conekta::Plan.where
|
48
|
+
plan = plans.first
|
49
|
+
plan.delete
|
50
|
+
expect(plan.deleted).to eq(true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Webhook do
|
4
|
+
include_context "API 1.0.0"
|
5
|
+
let!(:events) do
|
6
|
+
{
|
7
|
+
events: [
|
8
|
+
"charge.created", "charge.paid", "charge.under_fraud_review",
|
9
|
+
"charge.fraudulent", "charge.refunded", "charge.created", "customer.created",
|
10
|
+
"customer.updated", "customer.deleted", "webhook.created", "webhook.updated",
|
11
|
+
"webhook.deleted", "charge.chargeback.created", "charge.chargeback.updated",
|
12
|
+
"charge.chargeback.under_review", "charge.chargeback.lost", "charge.chargeback.won",
|
13
|
+
"payout.created", "payout.retrying", "payout.paid_out", "payout.failed",
|
14
|
+
"plan.created", "plan.updated", "plan.deleted", "subscription.created",
|
15
|
+
"subscription.paused", "subscription.resumed", "subscription.canceled",
|
16
|
+
"subscription.expired", "subscription.updated", "subscription.paid",
|
17
|
+
"subscription.payment_failed", "payee.created", "payee.updated",
|
18
|
+
"payee.deleted", "payee.payout_method.created",
|
19
|
+
"payee.payout_method.updated", "payee.payout_method.deleted"
|
20
|
+
]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
let(:url) { { url: "http://localhost:3000/my_listener" } }
|
24
|
+
|
25
|
+
# This spec was commented to avoid webhook creation saturation.
|
26
|
+
#
|
27
|
+
# it "succesfully gets charge" do
|
28
|
+
# webhook = Conekta::Webhook.create(url.merge(events))
|
29
|
+
# expect(webhook.url).to eq(url[:url])
|
30
|
+
# webhook = Conekta::Webhook.find(webhook.id)
|
31
|
+
# expect(webhook.url).to eq(url[:url])
|
32
|
+
# webhook.update({url: "http://localhost:2000/my_listener"})
|
33
|
+
# expect(webhook.url).to eq("http://localhost:2000/my_listener")
|
34
|
+
# webhook.delete
|
35
|
+
# end
|
36
|
+
end
|