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
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Customer do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
context "updating customers" do
|
6
|
+
context "creating submodels" do
|
7
|
+
include_context "customer"
|
8
|
+
|
9
|
+
let(:customer) { Conekta::Customer.create(customer_data) }
|
10
|
+
|
11
|
+
let(:customer_oxxo) {
|
12
|
+
{
|
13
|
+
payment_sources: [{
|
14
|
+
type: 'oxxo_recurrent',
|
15
|
+
expires_at: 157_559_040_0
|
16
|
+
}],
|
17
|
+
email: 'test@gmail.com',
|
18
|
+
name: 'Mario'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
let(:oxxo_source_params) do
|
23
|
+
{
|
24
|
+
type: 'oxxo_recurrent',
|
25
|
+
expires_at: 157_559_040_0
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:source_params) do
|
30
|
+
{
|
31
|
+
type: "card",
|
32
|
+
token_id: "tok_test_visa_4242"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:shipping_contact_params) do
|
37
|
+
{
|
38
|
+
email: "rogue@xmen.org",
|
39
|
+
phone: "+5213353319758",
|
40
|
+
receiver: "Test Conekta",
|
41
|
+
address: {
|
42
|
+
street1: "250 Alexis St",
|
43
|
+
city: "Red Deer",
|
44
|
+
state: "Alberta",
|
45
|
+
country: "CA",
|
46
|
+
postal_code: "T4N 0B8",
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "successfully creates source for customer" do
|
52
|
+
customer = Conekta::Customer.create(customer_oxxo)
|
53
|
+
source = customer.payment_sources.first
|
54
|
+
|
55
|
+
expect(source.class.to_s).to eq('Conekta::PaymentSource')
|
56
|
+
expect(customer.payment_sources.class.to_s).to eq('Conekta::List')
|
57
|
+
expect(source.reference.size).to eq(14)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'successfully creates oxxo recurrent reference for customer' do
|
61
|
+
source = customer.create_offline_recurrent_reference(oxxo_source_params)
|
62
|
+
|
63
|
+
expect(source.class.to_s).to eq("Conekta::PaymentSource")
|
64
|
+
expect(customer.payment_sources.class.to_s).to eq("Conekta::List")
|
65
|
+
expect(source.reference.size).to eq(14)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "successfully creates shipping contact for customer" do
|
69
|
+
shipping_contact =
|
70
|
+
customer.create_shipping_contact(shipping_contact_params)
|
71
|
+
|
72
|
+
expect(shipping_contact.class.to_s).to eq("Conekta::ShippingContact")
|
73
|
+
expect(customer.shipping_contacts.class.to_s).to eq("Conekta::List")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::DiscountLine do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
include_context "order"
|
6
|
+
|
7
|
+
let(:discount_lines) do
|
8
|
+
[
|
9
|
+
{
|
10
|
+
code: "Cupon de descuento",
|
11
|
+
type: "loyalty",
|
12
|
+
amount: 10
|
13
|
+
},
|
14
|
+
{
|
15
|
+
code: "Cupon de descuento",
|
16
|
+
type: "loyalty",
|
17
|
+
amount: 5
|
18
|
+
}
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:order) do
|
23
|
+
Conekta::Order.create(order_data.merge(discount_lines: discount_lines))
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:discount_line) { order.discount_lines.first }
|
27
|
+
|
28
|
+
context "deleting discount lines" do
|
29
|
+
it "successful discount line delete" do
|
30
|
+
discount_line.delete
|
31
|
+
|
32
|
+
expect(discount_line.deleted).to eq(true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "updating discount lines" do
|
37
|
+
it "successful discount line update" do
|
38
|
+
discount_line.update(amount: 11)
|
39
|
+
|
40
|
+
expect(discount_line.amount).to eq(11)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "unsuccessful discount line update" do
|
44
|
+
expect {
|
45
|
+
discount_line.update(amount: -1)
|
46
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Error do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
|
6
|
+
let(:card) { { cards: ["tok_test_visa_4242"] } }
|
7
|
+
|
8
|
+
it "test no id error" do
|
9
|
+
expect{
|
10
|
+
Conekta::Customer.find(nil)
|
11
|
+
}.to raise_error(Conekta::Error)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "test no connection error" do
|
15
|
+
api_url = Conekta::api_base
|
16
|
+
Conekta::api_base = 'http://localhost:3001'
|
17
|
+
|
18
|
+
expect{
|
19
|
+
Conekta::Customer.create(card)
|
20
|
+
}.to raise_error(Conekta::NoConnectionError)
|
21
|
+
|
22
|
+
# cleanup
|
23
|
+
Conekta::api_base = api_url
|
24
|
+
end
|
25
|
+
|
26
|
+
it "test api error" do
|
27
|
+
expect{
|
28
|
+
Conekta::Customer.create({
|
29
|
+
cards: {
|
30
|
+
0 => "tok_test_visa_4242"
|
31
|
+
}
|
32
|
+
})
|
33
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "test parameter validation error" do
|
37
|
+
expect{
|
38
|
+
Conekta::Order.create({})
|
39
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "test resource not found error" do
|
43
|
+
expect{
|
44
|
+
Conekta::Order.find(1)
|
45
|
+
}.to raise_error(Conekta::ResourceNotFoundError)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "test authentication error" do
|
49
|
+
api_key = Conekta::api_key
|
50
|
+
Conekta::api_key = ""
|
51
|
+
|
52
|
+
expect{
|
53
|
+
Conekta::Customer.create({
|
54
|
+
cards: ["tok_test_visa_4242"]
|
55
|
+
})
|
56
|
+
}.to raise_error(Conekta::AuthenticationError)
|
57
|
+
|
58
|
+
# cleanup
|
59
|
+
Conekta::api_key = api_key
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::LineItem do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
|
6
|
+
let(:line_items) do
|
7
|
+
[{
|
8
|
+
name: "Box of Cohiba S1s",
|
9
|
+
description: "Imported From Mex.",
|
10
|
+
unit_price: 35000,
|
11
|
+
quantity: 1,
|
12
|
+
tags: ["food", "mexican food"]
|
13
|
+
},
|
14
|
+
{
|
15
|
+
name: "Other item",
|
16
|
+
description: "other description",
|
17
|
+
unit_price: 35000,
|
18
|
+
quantity: 1,
|
19
|
+
tags: ["food"]
|
20
|
+
}]
|
21
|
+
end
|
22
|
+
let(:order_data) do
|
23
|
+
{
|
24
|
+
currency: 'mxn',
|
25
|
+
line_items: line_items
|
26
|
+
}
|
27
|
+
end
|
28
|
+
let(:order) { Conekta::Order.create(order_data) }
|
29
|
+
let(:line_item) { order.line_items.first }
|
30
|
+
|
31
|
+
context "deleting line items" do
|
32
|
+
it "successful line item delete" do
|
33
|
+
line_item.delete
|
34
|
+
|
35
|
+
expect(line_item.deleted).to eq(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "updating line items" do
|
40
|
+
it "successful line item update" do
|
41
|
+
line_item.update(unit_price: 1000)
|
42
|
+
|
43
|
+
expect(line_item.unit_price).to eq(1000)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "unsuccessful line item update" do
|
47
|
+
expect {
|
48
|
+
line_item.update(description: nil)
|
49
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::List do
|
4
|
+
|
5
|
+
include_context "API 2.0.0"
|
6
|
+
|
7
|
+
let(:list) do
|
8
|
+
response = JSON.parse(File.read("spec/support/fixtures/orders.json"))
|
9
|
+
order_list = Conekta::List.new("Order",response)
|
10
|
+
order_list.load_from(response)
|
11
|
+
order_list
|
12
|
+
end
|
13
|
+
|
14
|
+
context "moving cursor" do
|
15
|
+
it "moves cursor forward" do
|
16
|
+
window = Conekta::Order.where({"limit" => 5, "next" => list[9].id})
|
17
|
+
expect(window.first.id).to eq(list[10].id)
|
18
|
+
window.next(limit: 1)
|
19
|
+
expect(window.first.id).to eq(list[15].id)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "moves cursor backwards" do
|
23
|
+
window = Conekta::Order.where({"limit" => 5, "next" => list[14].id})
|
24
|
+
expect(window.first.id).to eq(list[15].id)
|
25
|
+
window.previous(limit: 1)
|
26
|
+
expect(window.first.id).to eq(list[14].id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::Order do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
|
6
|
+
let(:customer_info) do
|
7
|
+
{
|
8
|
+
name: "John Constantine",
|
9
|
+
phone: "+5213353319758",
|
10
|
+
email: "hola@hola.com"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:customer_data) do
|
15
|
+
{
|
16
|
+
email: "hola@hola.com",
|
17
|
+
name: "John Constantine",
|
18
|
+
cards: ["tok_test_visa_4242"]
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:charges) do
|
23
|
+
[{
|
24
|
+
payment_method: {
|
25
|
+
type: "oxxo_cash",
|
26
|
+
expires_at: (Time.now + 3600).to_i
|
27
|
+
},
|
28
|
+
amount: 35000
|
29
|
+
}]
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:card_charges) do
|
33
|
+
[{
|
34
|
+
payment_method: {
|
35
|
+
type: "card",
|
36
|
+
token_id: "tok_test_visa_4242",
|
37
|
+
},
|
38
|
+
amount: 35000
|
39
|
+
}]
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:line_items) do
|
43
|
+
[{
|
44
|
+
name: "Box of Cohiba S1s",
|
45
|
+
description: "Imported From Mex.",
|
46
|
+
unit_price: 35000,
|
47
|
+
quantity: 1,
|
48
|
+
tags: ["food", "mexican food"]
|
49
|
+
}]
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:order_data) do
|
53
|
+
{
|
54
|
+
currency: 'mxn',
|
55
|
+
line_items: line_items,
|
56
|
+
metadata: {
|
57
|
+
test: true
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:order_data_with_charges) do
|
63
|
+
order_data.merge(charges: charges)
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:order_data_with_card_charges) do
|
67
|
+
order_data.merge(charges: card_charges)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "creating orders" do
|
71
|
+
it "successful order create" do
|
72
|
+
order = Conekta::Order.create(order_data)
|
73
|
+
|
74
|
+
expect(order).to be_a(Conekta::Order)
|
75
|
+
expect(order.metadata["test"]).to eq(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "unsuccessful order create" do
|
79
|
+
expect{
|
80
|
+
Conekta::Order.create({})
|
81
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with charges" do
|
85
|
+
it "successful order create" do
|
86
|
+
order = Conekta::Order.create(order_data_with_charges.
|
87
|
+
merge(customer_info: customer_info))
|
88
|
+
|
89
|
+
expect(order).to be_a(Conekta::Order)
|
90
|
+
end
|
91
|
+
|
92
|
+
context "unsuccessful order create" do
|
93
|
+
it "with missing customer_info and customer_id" do
|
94
|
+
expect{
|
95
|
+
Conekta::Order.create(order_data_with_charges)
|
96
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "updating orders" do
|
103
|
+
let(:order) { Conekta::Order.create(order_data) }
|
104
|
+
|
105
|
+
it "successful order update" do
|
106
|
+
order.update(charges: charges, customer_info: customer_info)
|
107
|
+
|
108
|
+
expect(order.charges).not_to be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
it "unsuccessful order update" do
|
112
|
+
expect{
|
113
|
+
order.update(charges: charges)
|
114
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "creating submodels" do
|
119
|
+
let(:line_item_params) do
|
120
|
+
{
|
121
|
+
name: "Box of Cohiba S1s",
|
122
|
+
description: "Imported From Mex.",
|
123
|
+
unit_price: 35000,
|
124
|
+
quantity: 1,
|
125
|
+
tags: ["food", "mexican food"]
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:tax_line_params) do
|
130
|
+
{
|
131
|
+
description: "IVA",
|
132
|
+
amount: 600
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
let(:shipping_line_params) do
|
137
|
+
{
|
138
|
+
description: "Otro Shipping",
|
139
|
+
amount: 40,
|
140
|
+
tracking_number: "TRACK124",
|
141
|
+
carrier: "USPS",
|
142
|
+
method: "Train",
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
let(:discount_line_params) do
|
147
|
+
{
|
148
|
+
code: "Cupon de descuento",
|
149
|
+
type: "loyalty",
|
150
|
+
amount: 10
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
let(:charge_params) do
|
155
|
+
{
|
156
|
+
payment_method: {
|
157
|
+
type: "oxxo_cash",
|
158
|
+
expires_at: (Time.now + 3600).to_i
|
159
|
+
},
|
160
|
+
amount: 35000
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
let(:shipping_contact_params) do
|
165
|
+
{
|
166
|
+
id: "1jap4jmcjnwh34",
|
167
|
+
email: "thomas.logan@xmen.org",
|
168
|
+
phone: "+5213353319758",
|
169
|
+
receiver: "Marvin Fuller",
|
170
|
+
between_streets: "Ackerman Crescent",
|
171
|
+
address: {
|
172
|
+
street1: "250 Alexis St",
|
173
|
+
city: "Red Deer",
|
174
|
+
state: "Alberta",
|
175
|
+
country: "MX",
|
176
|
+
postal_code: "78219",
|
177
|
+
residential: true
|
178
|
+
}
|
179
|
+
}
|
180
|
+
end
|
181
|
+
|
182
|
+
let(:order) { Conekta::Order.create(order_data) }
|
183
|
+
|
184
|
+
it "successfully creates charge for order" do
|
185
|
+
other_params = {
|
186
|
+
currency: 'mxn',
|
187
|
+
customer_info: {
|
188
|
+
name: 'John Constantine',
|
189
|
+
phone: '+5213353319758',
|
190
|
+
email: 'hola@hola.com'
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
order = Conekta::Order.create(order_data.merge(other_params))
|
195
|
+
charge = order.create_charge(charge_params)
|
196
|
+
|
197
|
+
expect(charge.class.to_s).to eq("Conekta::Charge")
|
198
|
+
expect(order.charges.class.to_s).to eq("Conekta::List")
|
199
|
+
end
|
200
|
+
|
201
|
+
it "successfully creates line item for order" do
|
202
|
+
line_item = order.create_line_item(line_item_params)
|
203
|
+
|
204
|
+
expect(line_item.class.to_s).to eq("Conekta::LineItem")
|
205
|
+
expect(order.line_items.class.to_s).to eq("Conekta::List")
|
206
|
+
end
|
207
|
+
|
208
|
+
it "successfully creates tax line for order" do
|
209
|
+
tax_line = order.create_tax_line(tax_line_params)
|
210
|
+
new_tax_line = order.create_tax_line(description: "ISR", amount: 2)
|
211
|
+
|
212
|
+
expect(tax_line.class.to_s).to eq("Conekta::TaxLine")
|
213
|
+
expect(order.tax_lines.class.to_s).to eq("Conekta::List")
|
214
|
+
expect(order.tax_lines.total).to eq(2)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "successfully creates shipping line for order" do
|
218
|
+
shipping_line = order.create_shipping_line(shipping_line_params)
|
219
|
+
|
220
|
+
expect(shipping_line.class.to_s).to eq("Conekta::ShippingLine")
|
221
|
+
expect(order.shipping_lines.class.to_s).to eq("Conekta::List")
|
222
|
+
end
|
223
|
+
|
224
|
+
it "successfully creates discount line for order" do
|
225
|
+
discount_line = order.create_discount_line(discount_line_params)
|
226
|
+
|
227
|
+
discount_line.update({amount: 1000})
|
228
|
+
|
229
|
+
expect(discount_line.class.to_s).to eq("Conekta::DiscountLine")
|
230
|
+
expect(order.discount_lines.class.to_s).to eq("Conekta::List")
|
231
|
+
end
|
232
|
+
|
233
|
+
it "successfully create shipping contact for order" do
|
234
|
+
shipping_contact = order.create_shipping_contact(shipping_contact_params)
|
235
|
+
|
236
|
+
expect(shipping_contact.class.to_s).to eq("Conekta::ShippingContact")
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "get" do
|
241
|
+
it "successfully gets order" do
|
242
|
+
id = Conekta::Order.create(order_data).id
|
243
|
+
|
244
|
+
order = Conekta::Order.find(id)
|
245
|
+
|
246
|
+
expect(order).to be_a(Conekta::Order)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "test successful where" do
|
250
|
+
orders = Conekta::Order.where
|
251
|
+
|
252
|
+
expect(orders).to be_a(Conekta::List)
|
253
|
+
expect(orders.elements_type).to eq("Order")
|
254
|
+
expect(orders.first).to be_a(Conekta::Order)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
it "successfully captures an order" do
|
259
|
+
order = Conekta::Order.create(order_data_with_card_charges.
|
260
|
+
merge(customer_info: customer_info, pre_authorize: true))
|
261
|
+
expect(order.payment_status).to eq("pre_authorized")
|
262
|
+
|
263
|
+
order.authorize_capture
|
264
|
+
|
265
|
+
expect(order.payment_status).to eq("paid")
|
266
|
+
end
|
267
|
+
|
268
|
+
context "refund" do
|
269
|
+
let(:order_refund) do
|
270
|
+
{
|
271
|
+
amount: 35000,
|
272
|
+
reason: "requested_by_client"
|
273
|
+
}
|
274
|
+
end
|
275
|
+
|
276
|
+
it "test successful refund" do
|
277
|
+
order = Conekta::Order.create(order_data_with_card_charges.
|
278
|
+
merge(customer_info: customer_info).
|
279
|
+
merge(line_items: line_items))
|
280
|
+
begin
|
281
|
+
order.refund(order_refund)
|
282
|
+
rescue Exception => e
|
283
|
+
puts e.details.map{|d| d.message}
|
284
|
+
end
|
285
|
+
|
286
|
+
refunded_order = Conekta::Order.find(order.id)
|
287
|
+
|
288
|
+
expect(refunded_order.payment_status).to eq("refunded")
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
# require 'conekta'
|
3
|
+
|
4
|
+
describe Conekta::Payee do
|
5
|
+
include_context "API 2.0.0"
|
6
|
+
|
7
|
+
describe 'an instance' do
|
8
|
+
let(:payee_attributes) do
|
9
|
+
{
|
10
|
+
name: "John Doe", email: "j_d@radcorp2.com", phone: "555555555",
|
11
|
+
billing_address:{
|
12
|
+
company_name: 'Rad Corp',
|
13
|
+
tax_id: 'tax121212abc',
|
14
|
+
street1: 'Guadalupe 73',
|
15
|
+
street2: 'Despacho 32',
|
16
|
+
street3: 'Condesa',
|
17
|
+
city: 'Cuauhtemoc',
|
18
|
+
state: 'DF',
|
19
|
+
country: 'MX',
|
20
|
+
postal_code: '06100'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates successfully' do
|
26
|
+
payee = Conekta::Payee.create(payee_attributes)
|
27
|
+
expect(payee).to be_a(Conekta::Payee)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ':payout_methods' do
|
31
|
+
let!(:payee) { Conekta::Payee.create(payee_attributes) }
|
32
|
+
let(:bank_attributes) do
|
33
|
+
{
|
34
|
+
type: "bank_account",
|
35
|
+
account_number: '072225008217746674',
|
36
|
+
account_holder_name: 'J D - Radcorp'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can create payout methods' do
|
41
|
+
payout_method = payee.create_destination(bank_attributes)
|
42
|
+
expect(payout_method).to be_a(Conekta::Destination)
|
43
|
+
# I'm sure this should be a Conekta::PayoutMethod,
|
44
|
+
# just not sure why it's reporting back as a Conekta::Method
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'assigns default_payout_method_id to first payout method created' do
|
48
|
+
payout_method = payee.create_destination(bank_attributes)
|
49
|
+
# refetch the payee object
|
50
|
+
payee = Conekta::Payee.find(payout_method.payee_id)
|
51
|
+
expect(payee.default_destination_id).to eq(payout_method.id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conekta::ShippingContact do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
include_context "customer"
|
6
|
+
|
7
|
+
let(:shipping_contacts) do
|
8
|
+
[{
|
9
|
+
receiver: "John Williams",
|
10
|
+
phone: "+5213353319758",
|
11
|
+
address: {
|
12
|
+
street1: "250 Alexis St",
|
13
|
+
city: "Red Deer",
|
14
|
+
state: "Alberta",
|
15
|
+
country: "CA",
|
16
|
+
postal_code: "T4N 0B8",
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{
|
20
|
+
receiver: "John Williams",
|
21
|
+
phone: "+5213353319758",
|
22
|
+
address: {
|
23
|
+
street1: "250 Alexis St",
|
24
|
+
city: "Red Deer",
|
25
|
+
state: "Alberta",
|
26
|
+
country: "CA",
|
27
|
+
postal_code: "T4N 0B8",
|
28
|
+
}
|
29
|
+
}]
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:customer) do
|
33
|
+
Conekta::Customer.create(customer_data.
|
34
|
+
merge(shipping_contacts: shipping_contacts))
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:shipping_contact) { customer.shipping_contacts.first }
|
38
|
+
|
39
|
+
context "deleting shipping contacts" do
|
40
|
+
it "successful shipping contact delete" do
|
41
|
+
shipping_contact.delete
|
42
|
+
|
43
|
+
expect(shipping_contact.deleted).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "updating shipping contacts" do
|
48
|
+
it "successful shipping contact update" do
|
49
|
+
shipping_contact.update(receiver: "Mario Moreno")
|
50
|
+
|
51
|
+
expect(shipping_contact.receiver).to eq("Mario Moreno")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "unsuccessful shipping contact update" do
|
55
|
+
expect {
|
56
|
+
shipping_contact.update(receiver: 123)
|
57
|
+
}.to raise_error(Conekta::Error)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|