conekta 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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG +9 -1
  4. data/Gemfile +1 -0
  5. data/README.md +68 -46
  6. data/lib/conekta.rb +20 -1
  7. data/lib/conekta/address.rb +1 -0
  8. data/lib/conekta/card.rb +17 -3
  9. data/lib/conekta/charge.rb +7 -0
  10. data/lib/conekta/conekta_object.rb +25 -8
  11. data/lib/conekta/customer.rb +55 -4
  12. data/lib/conekta/destination.rb +29 -0
  13. data/lib/conekta/discount_line.rb +32 -0
  14. data/lib/conekta/error.rb +35 -37
  15. data/lib/conekta/error_list.rb +33 -0
  16. data/lib/conekta/event.rb +4 -1
  17. data/lib/conekta/fiscal_entity.rb +37 -0
  18. data/lib/conekta/line_item.rb +30 -0
  19. data/lib/conekta/list.rb +59 -0
  20. data/lib/conekta/log.rb +4 -0
  21. data/lib/conekta/operations/create_member.rb +20 -10
  22. data/lib/conekta/operations/custom_action.rb +1 -1
  23. data/lib/conekta/operations/delete.rb +3 -1
  24. data/lib/conekta/operations/where.rb +11 -2
  25. data/lib/conekta/order.rb +90 -0
  26. data/lib/conekta/payee.rb +4 -0
  27. data/lib/conekta/payment_source.rb +30 -0
  28. data/lib/conekta/payout_method.rb +12 -3
  29. data/lib/conekta/plan.rb +5 -0
  30. data/lib/conekta/refund.rb +2 -0
  31. data/lib/conekta/requestor.rb +14 -4
  32. data/lib/conekta/resource.rb +26 -4
  33. data/lib/conekta/return.rb +25 -0
  34. data/lib/conekta/shipping_contact.rb +32 -0
  35. data/lib/conekta/shipping_line.rb +33 -0
  36. data/lib/conekta/subscription.rb +17 -3
  37. data/lib/conekta/tax_line.rb +30 -0
  38. data/lib/conekta/token.rb +2 -0
  39. data/lib/conekta/util.rb +37 -3
  40. data/lib/conekta/version.rb +1 -1
  41. data/lib/conekta/webhook.rb +2 -0
  42. data/spec/conekta/1.0.0/.DS_Store +0 -0
  43. data/spec/conekta/1.0.0/card_spec.rb +40 -0
  44. data/spec/conekta/{charge_spec.rb → 1.0.0/charge_spec.rb} +1 -0
  45. data/spec/conekta/{customer_spec.rb → 1.0.0/customer_spec.rb} +3 -2
  46. data/spec/conekta/{error_spec.rb → 1.0.0/error_spec.rb} +3 -1
  47. data/spec/conekta/{event_spec.rb → 1.0.0/event_spec.rb} +1 -0
  48. data/spec/conekta/{log_spec.rb → 1.0.0/log_spec.rb} +1 -0
  49. data/spec/conekta/{payout_spec.rb → 1.0.0/payout_spec.rb} +1 -0
  50. data/spec/conekta/{plan_spec.rb → 1.0.0/plan_spec.rb} +1 -0
  51. data/spec/conekta/{token_spec.rb → 1.0.0/token_spec.rb} +1 -0
  52. data/spec/conekta/{webhook_spec.rb → 1.0.0/webhook_spec.rb} +1 -0
  53. data/spec/conekta/2.0.0/customer_spec.rb +49 -0
  54. data/spec/conekta/2.0.0/discount_line_spec.rb +49 -0
  55. data/spec/conekta/2.0.0/error_list_spec.rb +45 -0
  56. data/spec/conekta/2.0.0/fiscal_entity_spec.rb +67 -0
  57. data/spec/conekta/2.0.0/line_item_spec.rb +53 -0
  58. data/spec/conekta/2.0.0/list_spec.rb +29 -0
  59. data/spec/conekta/2.0.0/order_spec.rb +327 -0
  60. data/spec/conekta/{payee_spec.rb → 2.0.0/payee_spec.rb} +1 -1
  61. data/spec/conekta/2.0.0/shipping_contact_spec.rb +60 -0
  62. data/spec/conekta/2.0.0/shipping_line_spec.rb +53 -0
  63. data/spec/conekta/2.0.0/source_spec.rb +31 -0
  64. data/spec/conekta/2.0.0/tax_line_spec.rb +44 -0
  65. data/spec/conekta_spec.rb +6 -0
  66. data/spec/spec_helper.rb +11 -0
  67. data/spec/support/fixtures/orders.json +2394 -0
  68. data/spec/support/shared_context.rb +49 -0
  69. metadata +62 -21
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Charge do
4
+ include_context "API 1.0.0"
4
5
  let(:payment_method) do
5
6
  {
6
7
  amount: 2000,
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Customer do
4
+ include_context "API 1.0.0"
4
5
  let(:customer_data) { { :cards => ["tok_test_visa_4242"], email: "test@gmail.com", name: "Mario" } }
5
6
 
6
7
  context "creating customers" do
@@ -9,7 +10,7 @@ describe Conekta::Customer do
9
10
  expect(customer).to be_a(Conekta::Customer)
10
11
  end
11
12
 
12
- it "successful customer create" do
13
+ it "unsuccessful customer create" do
13
14
  expect { Conekta::Customer.create(
14
15
  :cards => ["tok_test_visa_4241"],
15
16
  :name => "Mario",
@@ -88,7 +89,7 @@ describe Conekta::Customer do
88
89
  expect { customer.create_subscription({plan: 'unexistent-plan'}) }.to \
89
90
  raise_error(
90
91
  Conekta::ResourceNotFoundError,
91
- "Object Plan unexistent-plan could not be found."
92
+ "The object Plan unexistent-plan could not be found."
92
93
  )
93
94
  end
94
95
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Error do
4
+ include_context "API 1.0.0"
4
5
  let(:card) { { cards: ["tok_test_visa_4242"] } }
5
6
 
6
7
  it "test no id error" do
@@ -27,12 +28,13 @@ describe Conekta::Error do
27
28
  end
28
29
 
29
30
  it "test authentication error" do
31
+ api_key = Conekta::api_key
30
32
  Conekta::api_key = ""
31
33
  expect { Conekta::Customer.create({ cards: ["tok_test_visa_4242"] }) }.to \
32
34
  raise_error(Conekta::AuthenticationError)
33
35
 
34
36
  # cleanup
35
- Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
37
+ Conekta.api_key = api_key
36
38
  end
37
39
 
38
40
  it "test parameter validation error" do
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Event do
4
+ include_context "API 1.0.0"
4
5
  it "test successful where" do
5
6
  events = Conekta::Event.where
6
7
  expect(events.class_name).to eq("ConektaObject")
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Log do
4
+ include_context "API 1.0.0"
4
5
  it "test successful where" do
5
6
  events = Conekta::Log.where
6
7
  expect(events.class_name).to eq("ConektaObject")
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Payout do
4
+ include_context "API 1.0.0"
4
5
  let(:payee_attributes) do
5
6
  {
6
7
  name: "John Doe", email: "j_d@radcorp.com", phone: "555555555",
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Plan do
4
+ include_context "API 1.0.0"
4
5
  context "get/where" do
5
6
  it "test succesful get plan" do
6
7
  plans = Conekta::Plan.where
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Token do
4
+ include_context "API 1.0.0"
4
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Conekta::Webhook do
4
+ include_context "API 1.0.0"
4
5
  let!(:events) do
5
6
  {
6
7
  events: [
@@ -0,0 +1,49 @@
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(:source_params) do
12
+ {
13
+ type: "card",
14
+ token_id: "tok_test_visa_4242"
15
+ }
16
+ end
17
+
18
+ let(:shipping_contact_params) do
19
+ {
20
+ email: "rogue@xmen.org",
21
+ phone: "+5213353319758",
22
+ receiver: "Test Conekta",
23
+ address: {
24
+ street1: "250 Alexis St",
25
+ city: "Red Deer",
26
+ state: "Alberta",
27
+ country: "CA",
28
+ postal_code: "T4N 0B8",
29
+ }
30
+ }
31
+ end
32
+
33
+ it "successfully creates source for customer" do
34
+ source = customer.create_payment_source(source_params)
35
+
36
+ expect(source.class.to_s).to eq("Conekta::PaymentSource")
37
+ expect(customer.payment_sources.class.to_s).to eq("Conekta::List")
38
+ end
39
+
40
+ it "successfully creates shipping contact for customer" do
41
+ shipping_contact =
42
+ customer.create_shipping_contact(shipping_contact_params)
43
+
44
+ expect(shipping_contact.class.to_s).to eq("Conekta::ShippingContact")
45
+ expect(customer.shipping_contacts.class.to_s).to eq("Conekta::List")
46
+ end
47
+ end
48
+ end
49
+ 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::ErrorList)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conekta::ErrorList 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_to_raise_error_list(Conekta::ErrorList, nil, Conekta::Error) \
10
+ { Conekta::Customer.find(nil) }
11
+ end
12
+
13
+ it "test no connection error" do
14
+ api_url = Conekta::api_base
15
+ Conekta::api_base = 'http://localhost:3001'
16
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::NoConnectionError) \
17
+ { Conekta::Customer.create(card) }
18
+ # cleanup
19
+ Conekta::api_base = api_url
20
+ end
21
+
22
+ it "test api error" do
23
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ParameterValidationError) \
24
+ { Conekta::Customer.create({ cards: {0=>"tok_test_visa_4242"} }) }
25
+ end
26
+
27
+ it "test parameter validation error" do
28
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ParameterValidationError) \
29
+ { Conekta::Order.create({}) }
30
+ end
31
+
32
+ it "test resource not found error" do
33
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ResourceNotFoundError) \
34
+ { Conekta::Order.find(1) }
35
+ end
36
+
37
+ it "test authentication error" do
38
+ api_key = Conekta::api_key
39
+ Conekta::api_key = ""
40
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::AuthenticationError) \
41
+ { Conekta::Customer.create({ cards: ["tok_test_visa_4242"] }) }
42
+ # cleanup
43
+ Conekta::api_key = api_key
44
+ end
45
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conekta::FiscalEntity do
4
+ include_context "API 2.0.0"
5
+ include_context "customer"
6
+
7
+ let(:fiscal_entities) do
8
+ [{
9
+ tax_id: "AMGH851205MN1",
10
+ name: "Nike SA de CV",
11
+ address: {
12
+ street1: "250 Alexis St",
13
+ internal_number: "19",
14
+ external_number: "91",
15
+ city: "Red Deer",
16
+ state: "Alberta",
17
+ country: "CA",
18
+ postal_code: "T4N 0B8"
19
+ }
20
+ },
21
+ {
22
+ tax_id: "AMGH851205MN2",
23
+ name: "Nike SA de CV",
24
+ address: {
25
+ street1: "250 Alexis St",
26
+ internal_number: "20",
27
+ external_number: "02",
28
+ city: "Red Deer",
29
+ state: "Alberta",
30
+ country: "CA",
31
+ postal_code: "T4N 0B8"
32
+ }
33
+ }]
34
+ end
35
+
36
+ let(:customer) do
37
+ Conekta::Customer.create(customer_data.
38
+ merge(fiscal_entities: fiscal_entities))
39
+ end
40
+ let(:fiscal_entity) { customer.fiscal_entities.first }
41
+
42
+ context "deleting fiscal entities" do
43
+ it "successful fiscal entity delete" do
44
+ begin
45
+ fiscal_entity.delete
46
+ rescue Conekta::ErrorList => list
47
+ puts list.details.map{|d|d.message}.inspect
48
+ end
49
+
50
+ expect(fiscal_entity.deleted).to eq(true)
51
+ end
52
+ end
53
+
54
+ context "updating fiscal entities" do
55
+ it "successful fiscal entity update" do
56
+ fiscal_entity.update(name: "Adidas")
57
+
58
+ expect(fiscal_entity.name).to eq("Adidas")
59
+ end
60
+
61
+ it "unsuccessful fiscal entity update" do
62
+ expect {
63
+ fiscal_entity.update(tax_id: nil)
64
+ }.to raise_error(Conekta::ErrorList)
65
+ end
66
+ end
67
+ 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::ErrorList)
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,327 @@
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_source: {
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_source: {
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(:fiscal_entity) do
53
+ {
54
+ tax_id: "AMGH851205MN1",
55
+ company_name: "Nike SA de CV",
56
+ address: {
57
+ street1: "250 Alexis St",
58
+ internal_number: "19",
59
+ external_number: "91",
60
+ city: "Red Deer",
61
+ state: "Alberta",
62
+ country: "CA",
63
+ postal_code: "T4N 0B8"
64
+ }
65
+ }
66
+ end
67
+
68
+ let(:order_data) do
69
+ {
70
+ currency: 'mxn',
71
+ line_items: line_items,
72
+ metadata: {
73
+ test: true
74
+ }
75
+ }
76
+ end
77
+
78
+ let(:order_data_with_charges) do
79
+ order_data.merge(charges: charges)
80
+ end
81
+
82
+ let(:order_data_with_card_charges) do
83
+ order_data.merge(charges: card_charges)
84
+ end
85
+
86
+ context "creating orders" do
87
+ it "successful order create" do
88
+ order = Conekta::Order.create(order_data)
89
+
90
+ expect(order).to be_a(Conekta::Order)
91
+ expect(order.metadata.test).to eq(true)
92
+ end
93
+
94
+ it "successful order with fiscal_entity create" do
95
+ order = Conekta::Order.create(order_data.merge(fiscal_entity: fiscal_entity))
96
+ expect(order.fiscal_entity).to be_a(Conekta::FiscalEntity)
97
+ expect(order.fiscal_entity.order).to eq(order)
98
+ end
99
+
100
+ it "unsuccessful order create" do
101
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ParameterValidationError) \
102
+ { Conekta::Order.create({}) }
103
+ end
104
+
105
+ context "with charges" do
106
+ it "successful order create" do
107
+ order = Conekta::Order.create(order_data_with_charges.
108
+ merge(customer_info: customer_info))
109
+
110
+ expect(order).to be_a(Conekta::Order)
111
+ end
112
+
113
+ context "unsuccessful order create" do
114
+ it "with missing customer_info and customer_id" do
115
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ParameterValidationError) \
116
+ { Conekta::Order.create(order_data_with_charges) }
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ context "updating orders" do
123
+ let(:order) { Conekta::Order.create(order_data) }
124
+
125
+ it "successful order update" do
126
+ order.update(charges: charges, customer_info: customer_info)
127
+
128
+ expect(order.charges).not_to be_empty
129
+ end
130
+
131
+ it "unsuccessful order update" do
132
+ expect_to_raise_error_list(Conekta::ErrorList, nil, Conekta::ParameterValidationError) \
133
+ { order.update(charges: charges) }
134
+ end
135
+ end
136
+
137
+ context "creating submodels" do
138
+ let(:line_item_params) do
139
+ {
140
+ name: "Box of Cohiba S1s",
141
+ description: "Imported From Mex.",
142
+ unit_price: 35000,
143
+ quantity: 1,
144
+ tags: ["food", "mexican food"]
145
+ }
146
+ end
147
+
148
+ let(:tax_line_params) do
149
+ {
150
+ description: "IVA",
151
+ amount: 600
152
+ }
153
+ end
154
+
155
+ let(:shipping_line_params) do
156
+ {
157
+ description: "Otro Shipping",
158
+ amount: 40,
159
+ tracking_number: "TRACK124",
160
+ carrier: "USPS",
161
+ method: "Train",
162
+ }
163
+ end
164
+
165
+ let(:fiscal_entity_params) do
166
+ {
167
+ tax_id: "AMGH851205MN2",
168
+ company_name: "Nike SA de CV",
169
+ address: {
170
+ street1: "250 Alexis St",
171
+ internal_number: "20",
172
+ external_number: "02",
173
+ city: "Red Deer",
174
+ state: "Alberta",
175
+ country: "CA",
176
+ postal_code: "T4N 0B8"
177
+ }
178
+ }
179
+ end
180
+
181
+ let(:discount_line_params) do
182
+ {
183
+ code: "Cupon de descuento",
184
+ type: "loyalty",
185
+ amount: 10
186
+ }
187
+ end
188
+
189
+ let(:charge_params) do
190
+ {
191
+ payment_source: {
192
+ type: "oxxo_cash",
193
+ expires_at: (Time.now + 3600).to_i
194
+ },
195
+ amount: 35000
196
+ }
197
+ end
198
+
199
+ let(:shipping_contact_params) do
200
+ {
201
+ id: "1jap4jmcjnwh34",
202
+ email: "thomas.logan@xmen.org",
203
+ phone: "+5213353319758",
204
+ receiver: "Marvin Fuller",
205
+ between_streets: "Ackerman Crescent",
206
+ address: {
207
+ street1: "250 Alexis St",
208
+ city: "Red Deer",
209
+ state: "Alberta",
210
+ country: "MX",
211
+ postal_code: "78219",
212
+ residential: true
213
+ }
214
+ }
215
+ end
216
+
217
+ let(:order) { Conekta::Order.create(order_data) }
218
+
219
+ it "successfully creates charge for order" do
220
+ other_params = {
221
+ currency: 'mxn',
222
+ customer_info: {
223
+ name: 'John Constantine',
224
+ phone: '+5213353319758',
225
+ email: 'hola@hola.com'
226
+ }
227
+ }
228
+
229
+ order = Conekta::Order.create(order_data.merge(other_params))
230
+ charge = order.create_charge(charge_params)
231
+
232
+ expect(charge.class.to_s).to eq("Conekta::Charge")
233
+ expect(order.charges.class.to_s).to eq("Conekta::List")
234
+ end
235
+
236
+ it "successfully creates line item for order" do
237
+ line_item = order.create_line_item(line_item_params)
238
+
239
+ expect(line_item.class.to_s).to eq("Conekta::LineItem")
240
+ expect(order.line_items.class.to_s).to eq("Conekta::List")
241
+ end
242
+
243
+ it "successfully creates tax line for order" do
244
+ tax_line = order.create_tax_line(tax_line_params)
245
+ new_tax_line = order.create_tax_line(description: "ISR", amount: 2)
246
+
247
+ expect(tax_line.class.to_s).to eq("Conekta::TaxLine")
248
+ expect(order.tax_lines.class.to_s).to eq("Conekta::List")
249
+ expect(order.tax_lines.total).to eq(2)
250
+ end
251
+
252
+ it "successfully creates shipping line for order" do
253
+ shipping_line = order.create_shipping_line(shipping_line_params)
254
+
255
+ expect(shipping_line.class.to_s).to eq("Conekta::ShippingLine")
256
+ expect(order.shipping_lines.class.to_s).to eq("Conekta::List")
257
+ end
258
+
259
+ it "successfully creates discount line for order" do
260
+ discount_line = order.create_discount_line(discount_line_params)
261
+
262
+ expect(discount_line.class.to_s).to eq("Conekta::DiscountLine")
263
+ expect(order.discount_lines.class.to_s).to eq("Conekta::List")
264
+ end
265
+
266
+ it "successfully creates fiscal entity for order" do
267
+ fiscal_entity = order.create_fiscal_entity(fiscal_entity_params)
268
+
269
+ expect(fiscal_entity.class.to_s).to eq("Conekta::FiscalEntity")
270
+ end
271
+
272
+ it "successfully create shipping contact for order" do
273
+ shipping_contact = order.create_shipping_contact(shipping_contact_params)
274
+
275
+ expect(shipping_contact.class.to_s).to eq("Conekta::ShippingContact")
276
+ end
277
+ end
278
+
279
+ context "get" do
280
+ it "successfully gets order" do
281
+ id = Conekta::Order.create(order_data).id
282
+
283
+ order = Conekta::Order.find(id)
284
+
285
+ expect(order).to be_a(Conekta::Order)
286
+ end
287
+
288
+ it "test successful where" do
289
+ orders = Conekta::Order.where
290
+
291
+ expect(orders).to be_a(Conekta::List)
292
+ expect(orders.elements_type).to eq("Order")
293
+ expect(orders.first).to be_a(Conekta::Order)
294
+ end
295
+ end
296
+
297
+ it "successfully captures an order" do
298
+ order = Conekta::Order.create(order_data_with_charges.
299
+ merge(customer_info: customer_info, preauthorize: true))
300
+ expect(order.preauthorize).to eq(true)
301
+
302
+ order.capture_order
303
+
304
+ expect(order.preauthorize).to eq(false)
305
+ end
306
+
307
+ context "returns" do
308
+ let(:order_return) do
309
+ {
310
+ amount: 35000,
311
+ reason: "Reason return",
312
+ currency: "MXN"
313
+ }
314
+ end
315
+
316
+ it "test successful return" do
317
+ order = Conekta::Order.create(order_data_with_card_charges.
318
+ merge(customer_info: customer_info).
319
+ merge(line_items: line_items))
320
+ order.create_return(order_return.merge(order_id: order.id))
321
+ returned_order = Conekta::Order.find(order.id)
322
+
323
+ expect(returned_order.status).to eq("returned")
324
+ expect(returned_order.returns.first).to be_a(Conekta::Return)
325
+ end
326
+ end
327
+ end