conekta 2.4.2 → 2.6.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/CHANGELOG.md +9 -0
- data/README.md +34 -61
- data/conekta.gemspec +2 -1
- data/lib/conekta/checkout.rb +35 -0
- data/lib/conekta/list.rb +0 -1
- data/lib/conekta/order.rb +18 -18
- data/lib/conekta/util.rb +1 -0
- data/lib/conekta/version.rb +1 -1
- data/lib/conekta.rb +1 -0
- data/spec/conekta/2.0.0/checkout_spec.rb +224 -0
- data/spec/conekta/2.0.0/order_spec.rb +126 -41
- data/spec/spec_helper.rb +0 -1
- metadata +51 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31713f94324383d6c460c26a4d948ab1684c86286a4181d94a1bcf448b906ce9
|
4
|
+
data.tar.gz: 8ffa91279cf24f52d6367903a469763bd77458cfaed1cb22728adc655ac296e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c90d1fa11514c232911156531a8794571ecc0800ef8276f8071df12a5e8b428458d7c8bfb8c808818d6ca56f2d73ca38f1224e9d8c1ac121d55b1f055c81e61d
|
7
|
+
data.tar.gz: 03ba2731ac8b69c7967baff8cd56df145ba62b34c021c12e68b8a91b5e5a79b5b3f9f15785d2a6728a7da6f87f61b9ac7f693a5c7a9381354e5cd79d214a1bfe
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [2.6.0](https://github.com/conekta/conekta-ruby/releases/tag/2.5.0) - 2020-06-08
|
2
|
+
### Deprecate List Total attribute
|
3
|
+
- Remove total attribute logic for lists as it is deprecated and will be removed.
|
4
|
+
Going forward use the has_more attribute of lists to determine whether you
|
5
|
+
should keep paginating.
|
6
|
+
## [2.5.0](https://github.com/conekta/conekta-ruby/releases/tag/2.5.0) - 2020-11-22
|
7
|
+
### Payment link
|
8
|
+
- Add models to support payment link (aka checkout).
|
9
|
+
|
1
10
|
## [2.4.2](https://github.com/conekta/conekta-ruby/releases/tag/2.4.2) - 2020-01-22
|
2
11
|
### Ruby 2.7 Cleanup
|
3
12
|
- Corrects warnings related to translate in Ruby 2.7
|
data/README.md
CHANGED
@@ -35,7 +35,6 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
# This changes the Accept-Language Header to the locale specified
|
37
37
|
Conekta.locale = :es
|
38
|
-
|
39
38
|
Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
40
39
|
|
41
40
|
# Or via an initializer in config/initializers/conekta.rb
|
@@ -45,71 +44,45 @@ Conekta.config do |c|
|
|
45
44
|
c.api_version = '2.0.0'
|
46
45
|
end
|
47
46
|
|
47
|
+
YOUR_DOMAIN = 'localhost:9292'.freeze
|
48
|
+
|
49
|
+
# Order creation example
|
48
50
|
begin
|
49
|
-
|
50
|
-
|
51
|
+
customer = Conekta::Customer.create(
|
52
|
+
{
|
53
|
+
name: 'Matz',
|
54
|
+
email: 'matz@rules.com'
|
55
|
+
}
|
56
|
+
)
|
57
|
+
|
58
|
+
order_params =
|
59
|
+
{
|
60
|
+
currency: 'MXN',
|
61
|
+
customer_info: {
|
62
|
+
customer_id: customer.id
|
63
|
+
},
|
64
|
+
line_items: [
|
65
|
+
{
|
66
|
+
name: 'T-Rex',
|
67
|
+
unit_price: 10000,
|
68
|
+
quantity: 1
|
69
|
+
}
|
70
|
+
],
|
71
|
+
checkout: {
|
72
|
+
type: 'HostedPayment',
|
73
|
+
name: 'Checkout Dummy',
|
74
|
+
allowed_payment_methods: %w[cash card bank_transfer],
|
75
|
+
success_url: YOUR_DOMAIN + '/success.html',
|
76
|
+
failure_url: YOUR_DOMAIN + '/cancel.html',
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
order = Conekta::Order.create(order_params)
|
51
81
|
rescue Conekta::Error => error
|
52
|
-
|
82
|
+
error.details.each do |error_details|
|
53
83
|
puts error_detail.message
|
54
84
|
end
|
55
85
|
end
|
56
|
-
|
57
|
-
{
|
58
|
-
"livemode": false,
|
59
|
-
"amount": 35000,
|
60
|
-
"payment_status": "pending_payment",
|
61
|
-
"currency": "MXN",
|
62
|
-
"customer_info": {
|
63
|
-
"email": "hola@hola.com",
|
64
|
-
"phone": "+5213353319758",
|
65
|
-
"name": "John Constantine",
|
66
|
-
"first_paid_at": 0
|
67
|
-
},
|
68
|
-
"object": "order",
|
69
|
-
"id": "ord_2ftyJuymR9FZczvPg",
|
70
|
-
"metadata": {
|
71
|
-
"test": true
|
72
|
-
},
|
73
|
-
"created_at": 1485272874,
|
74
|
-
"updated_at": 1485272874,
|
75
|
-
"line_items": {
|
76
|
-
"0": {
|
77
|
-
"name": "Box of Cohiba S1s",
|
78
|
-
"description": "Imported From Mex.",
|
79
|
-
"unit_price": 35000,
|
80
|
-
"quantity": 1,
|
81
|
-
"tags": ["food", "mexican food"],
|
82
|
-
"type": "physical",
|
83
|
-
"object": "line_item",
|
84
|
-
"id": "line_item_2ftyJuymR9FZczvPe",
|
85
|
-
"parent_id": "ord_2ftyJuymR9FZczvPg",
|
86
|
-
"metadata": {}
|
87
|
-
}
|
88
|
-
},
|
89
|
-
"charges": {
|
90
|
-
"0": {
|
91
|
-
"id": "5887772aedbb6ea3a30056c5",
|
92
|
-
"livemode": false,
|
93
|
-
"created_at": 1485272874,
|
94
|
-
"currency": "MXN",
|
95
|
-
"payment_method": {
|
96
|
-
"barcode_url": "https://s3.amazonaws.com/cash_payment_barcodes/sandbox_reference.png",
|
97
|
-
"service_name": "OxxoPay",
|
98
|
-
"object": "cash_payment",
|
99
|
-
"type": "oxxo",
|
100
|
-
"expires_at": 1485276473,
|
101
|
-
"store_name": "OXXO",
|
102
|
-
"reference": "93345678901234"
|
103
|
-
},
|
104
|
-
"object": "charge",
|
105
|
-
"status": "pending_payment",
|
106
|
-
"amount": 35000,
|
107
|
-
"fee": 1421,
|
108
|
-
"customer_id": "",
|
109
|
-
"order_id": "ord_2ftyJuymR9FZczvPg"
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
86
|
```
|
114
87
|
|
115
88
|
## Documentation
|
data/conekta.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "faraday"
|
24
24
|
spec.add_dependency "json"
|
25
25
|
spec.add_dependency "sys-uname"
|
26
|
+
spec.add_dependency "i18n"
|
26
27
|
|
27
28
|
spec.add_development_dependency "rspec", ">= 3.0"
|
28
|
-
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "pry"
|
29
30
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Checkout < Resource
|
3
|
+
include Conekta::Operations::Create
|
4
|
+
include Conekta::Operations::Where
|
5
|
+
include Conekta::Operations::Find
|
6
|
+
include Conekta::Operations::CustomAction
|
7
|
+
|
8
|
+
attr_accessor :_id, :livemode, :company_id, :entity_id, :emails_sent,
|
9
|
+
:sms_sent, :name, :slug, :status, :url,
|
10
|
+
:type, :recurrent, :is_redirect_on_failure,
|
11
|
+
:payments_limit_count, :paid_payments_count,
|
12
|
+
:expires_at, :allowed_payment_methods,
|
13
|
+
:needs_shipping_contact, :monthly_installments_options,
|
14
|
+
:monthly_installments_enabled,
|
15
|
+
:returns_control_on, :on_demand_enabled
|
16
|
+
|
17
|
+
def _url
|
18
|
+
ensure_id
|
19
|
+
|
20
|
+
"/checkouts/#{id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_sms(params = {})
|
24
|
+
custom_action(:post, "sms", params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def send_email(params = {})
|
28
|
+
custom_action(:post, "email", params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def cancel(params = {})
|
32
|
+
custom_action(:put, "cancel", params)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/conekta/list.rb
CHANGED
data/lib/conekta/order.rb
CHANGED
@@ -9,9 +9,10 @@ module Conekta
|
|
9
9
|
|
10
10
|
attr_accessor :livemode, :amount, :payment_status, :customer_id, :currency,
|
11
11
|
:metadata, :created_at, :updated_at, :tax_lines, :line_items,
|
12
|
-
:shipping_lines, :discount_lines, :shipping_contact, :charges
|
12
|
+
:shipping_lines, :discount_lines, :shipping_contact, :charges,
|
13
|
+
:checkout
|
13
14
|
|
14
|
-
def initialize(id=nil)
|
15
|
+
def initialize(id = nil)
|
15
16
|
@id = id
|
16
17
|
@line_items ||= List.new("LineItem", {})
|
17
18
|
@tax_lines ||= List.new("TaxLine", {})
|
@@ -26,7 +27,7 @@ module Conekta
|
|
26
27
|
super
|
27
28
|
end
|
28
29
|
|
29
|
-
order
|
30
|
+
order = self
|
30
31
|
submodels = [:line_items, :tax_lines, :shipping_lines, :discount_lines,
|
31
32
|
:charges]
|
32
33
|
create_submodels_lists(order, submodels)
|
@@ -34,40 +35,40 @@ module Conekta
|
|
34
35
|
|
35
36
|
#Attribute accessors
|
36
37
|
def create_line_item(params)
|
37
|
-
self.create_member_with_relation(
|
38
|
+
self.create_member_with_relation("line_items", params, self)
|
38
39
|
end
|
39
40
|
|
40
41
|
def create_tax_line(params)
|
41
|
-
self.create_member_with_relation(
|
42
|
+
self.create_member_with_relation("tax_lines", params, self)
|
42
43
|
end
|
43
44
|
|
44
45
|
def create_shipping_line(params)
|
45
|
-
self.create_member_with_relation(
|
46
|
+
self.create_member_with_relation("shipping_lines", params, self)
|
46
47
|
end
|
47
48
|
|
48
49
|
def create_discount_line(params)
|
49
|
-
self.create_member_with_relation(
|
50
|
+
self.create_member_with_relation("discount_lines", params, self)
|
50
51
|
end
|
51
52
|
|
52
53
|
def create_charge(params)
|
53
|
-
self.create_member(
|
54
|
+
self.create_member("charges", params)
|
54
55
|
end
|
55
56
|
|
56
57
|
def create_shipping_contact(params)
|
57
58
|
self.update(shipping_contact: params).shipping_contact
|
58
59
|
end
|
59
60
|
|
60
|
-
|
61
|
-
def authorize_capture(params={})
|
62
|
-
custom_action(:post,
|
61
|
+
#State transitions
|
62
|
+
def authorize_capture(params = {})
|
63
|
+
custom_action(:post, "capture", params)
|
63
64
|
end
|
64
65
|
|
65
|
-
def void(params={})
|
66
|
-
custom_action(:post,
|
66
|
+
def void(params = {})
|
67
|
+
custom_action(:post, "void", params)
|
67
68
|
end
|
68
69
|
|
69
|
-
def refund(params={})
|
70
|
-
custom_action(:post,
|
70
|
+
def refund(params = {})
|
71
|
+
custom_action(:post, "refund", params)
|
71
72
|
end
|
72
73
|
|
73
74
|
private
|
@@ -75,12 +76,11 @@ module Conekta
|
|
75
76
|
def create_submodels_lists(order, submodels)
|
76
77
|
submodels.each do |submodel|
|
77
78
|
self.send(submodel).each do |k, v|
|
78
|
-
v.create_attr(
|
79
|
+
v.create_attr("order", order)
|
79
80
|
|
80
|
-
self.send(submodel).set_val(k,v)
|
81
|
+
self.send(submodel).set_val(k, v)
|
81
82
|
end if self.respond_to?(submodel) && !self.send(submodel).nil?
|
82
83
|
end
|
83
84
|
end
|
84
|
-
|
85
85
|
end
|
86
86
|
end
|
data/lib/conekta/util.rb
CHANGED
@@ -11,6 +11,7 @@ module Conekta
|
|
11
11
|
'card_payment' => ::Conekta::PaymentMethod,
|
12
12
|
'cash_payment' => ::Conekta::PaymentMethod,
|
13
13
|
'charge' => ::Conekta::Charge,
|
14
|
+
'checkout' => ::Conekta::Checkout,
|
14
15
|
'customer' => ::Conekta::Customer,
|
15
16
|
'event' => ::Conekta::Event,
|
16
17
|
'log' => ::Conekta::Log,
|
data/lib/conekta/version.rb
CHANGED
data/lib/conekta.rb
CHANGED
@@ -0,0 +1,224 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Conekta::Checkout do
|
4
|
+
include_context "API 2.0.0"
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
if Conekta.api_base == "https://api.conekta.io"
|
8
|
+
skip("This test should be run in staging.")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:customer_info) do
|
13
|
+
{
|
14
|
+
name: "John Constantine",
|
15
|
+
phone: "4493424352",
|
16
|
+
email: "hola@hola.com",
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:line_items) do
|
21
|
+
[{
|
22
|
+
name: "Box of Cohiba S1s",
|
23
|
+
unit_price: 35000,
|
24
|
+
quantity: 1,
|
25
|
+
}]
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:msi_enabled) do
|
29
|
+
{
|
30
|
+
monthly_installments_enabled: true,
|
31
|
+
monthly_installments_options: [3, 6, 12],
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:recurrent) do
|
36
|
+
{
|
37
|
+
recurrent: true,
|
38
|
+
payments_limit_count: 10,
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:order_template) do
|
43
|
+
{
|
44
|
+
currency: "MXN",
|
45
|
+
line_items: line_items,
|
46
|
+
customer_info: customer_info,
|
47
|
+
metadata: {
|
48
|
+
"mycustomkey": "12345",
|
49
|
+
"othercustomkey": "abcde",
|
50
|
+
},
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:order_template_no_customer) do
|
55
|
+
{
|
56
|
+
currency: "MXN",
|
57
|
+
line_items: line_items,
|
58
|
+
metadata: {
|
59
|
+
"mycustomkey": "12345",
|
60
|
+
"othercustomkey": "abcde",
|
61
|
+
},
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:checkout_data) do
|
66
|
+
{
|
67
|
+
name: "Payment Link Name",
|
68
|
+
type: "PaymentLink",
|
69
|
+
recurrent: false,
|
70
|
+
expired_at: (Time.now + 259200).to_i,
|
71
|
+
allowed_payment_methods: ["cash", "card", "bank_transfer"],
|
72
|
+
needs_shipping_contact: false,
|
73
|
+
order_template: order_template,
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:checkout_data_no_customer) do
|
78
|
+
{
|
79
|
+
name: "Payment Link Name",
|
80
|
+
type: "PaymentLink",
|
81
|
+
recurrent: false,
|
82
|
+
expired_at: (Time.now + 259200).to_i,
|
83
|
+
allowed_payment_methods: ["cash", "card", "bank_transfer"],
|
84
|
+
needs_shipping_contact: false,
|
85
|
+
order_template: order_template_no_customer,
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:checkout_invalid_expired_at) do
|
90
|
+
{
|
91
|
+
name: "Payment Link Name",
|
92
|
+
type: "PaymentLink",
|
93
|
+
recurrent: false,
|
94
|
+
expired_at: (Time.now + 3600).to_i,
|
95
|
+
allowed_payment_methods: ["cash", "card", "bank_transfer"],
|
96
|
+
needs_shipping_contact: false,
|
97
|
+
order_template: order_template,
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:checkout_data_with_msi) do
|
102
|
+
checkout_data.merge(msi_enabled)
|
103
|
+
end
|
104
|
+
|
105
|
+
let(:checkout_data_recurrent) do
|
106
|
+
checkout_data_no_customer.merge(recurrent)
|
107
|
+
end
|
108
|
+
|
109
|
+
context "creating payment link" do
|
110
|
+
it "successful checkout create" do
|
111
|
+
checkout = Conekta::Checkout.create(checkout_data)
|
112
|
+
|
113
|
+
expect(checkout).to be_a(Conekta::Checkout)
|
114
|
+
expect(checkout.id).not_to eq("")
|
115
|
+
expect(checkout.id.length).to eq(36)
|
116
|
+
expect(checkout.type).to eq("PaymentLink")
|
117
|
+
expect(checkout.livemode).to eq(false)
|
118
|
+
expect(checkout.needs_shipping_contact).to eq(false)
|
119
|
+
expect(checkout.monthly_installments_enabled).to eq(false)
|
120
|
+
expect(checkout.slug).not_to eq("")
|
121
|
+
expect(checkout.url).not_to eq("")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "unsuccessful checkout create" do
|
125
|
+
expect {
|
126
|
+
Conekta::Checkout.create({})
|
127
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "unsuccessful checkout expired at create" do
|
131
|
+
expect {
|
132
|
+
Conekta::Checkout.create(checkout_invalid_expired_at)
|
133
|
+
}.to raise_error(Conekta::ParameterValidationError)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "successful with monthly installments enabled" do
|
137
|
+
checkout = Conekta::Checkout.create(checkout_data_with_msi)
|
138
|
+
|
139
|
+
expect(checkout).to be_a(Conekta::Checkout)
|
140
|
+
expect(checkout.id).not_to eq("")
|
141
|
+
expect(checkout.id.length).to eq(36)
|
142
|
+
expect(checkout.type).to eq("PaymentLink")
|
143
|
+
expect(checkout.livemode).to eq(false)
|
144
|
+
expect(checkout.needs_shipping_contact).to eq(false)
|
145
|
+
expect(checkout.monthly_installments_enabled).to eq(true)
|
146
|
+
expect(checkout.monthly_installments_options.length).to eq(3)
|
147
|
+
expect(checkout.slug).not_to eq("")
|
148
|
+
expect(checkout.url).not_to eq("")
|
149
|
+
end
|
150
|
+
|
151
|
+
it "successful with recurrent" do
|
152
|
+
checkout = Conekta::Checkout.create(checkout_data_recurrent)
|
153
|
+
|
154
|
+
expect(checkout).to be_a(Conekta::Checkout)
|
155
|
+
expect(checkout.id).not_to eq("")
|
156
|
+
expect(checkout.id.length).to eq(36)
|
157
|
+
expect(checkout.type).to eq("PaymentLink")
|
158
|
+
expect(checkout.livemode).to eq(false)
|
159
|
+
expect(checkout.needs_shipping_contact).to eq(false)
|
160
|
+
expect(checkout.recurrent).to eq(true)
|
161
|
+
expect(checkout.payments_limit_count).to eq(10)
|
162
|
+
expect(checkout.slug).not_to eq("")
|
163
|
+
expect(checkout.url).not_to eq("")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "get" do
|
168
|
+
it "successfully gets checkout" do
|
169
|
+
id = Conekta::Checkout.create(checkout_data).id
|
170
|
+
|
171
|
+
checkout = Conekta::Checkout.find(id)
|
172
|
+
|
173
|
+
expect(checkout).to be_a(Conekta::Checkout)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "test successful checkout where" do
|
177
|
+
checkouts = Conekta::Checkout.where
|
178
|
+
|
179
|
+
expect(checkouts).to be_a(Conekta::List)
|
180
|
+
expect(checkouts.elements_type).to eq("Checkout")
|
181
|
+
expect(checkouts.first).to be_a(Conekta::Checkout)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "notifications with payment link" do
|
186
|
+
it "unsuccessful send a checkout sms" do
|
187
|
+
expect {
|
188
|
+
checkout = Conekta::Checkout.create(checkout_data)
|
189
|
+
expect(checkout.sms_sent).to eq(0)
|
190
|
+
|
191
|
+
checkout.send_sms({
|
192
|
+
"phone": "5555555555",
|
193
|
+
})
|
194
|
+
}.to raise_error(Conekta::ProcessingError)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "successfully send a checkout email" do
|
198
|
+
checkout = Conekta::Checkout.create(checkout_data)
|
199
|
+
expect(checkout.emails_sent).to eq(0)
|
200
|
+
|
201
|
+
checkout.send_email({
|
202
|
+
"email": "test@mail.com",
|
203
|
+
})
|
204
|
+
|
205
|
+
checkoutFound = Conekta::Checkout.find(checkout.id)
|
206
|
+
expect(checkoutFound.emails_sent).to eq(1)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "cancel checkout request" do
|
211
|
+
it "successful cancel a checkout" do
|
212
|
+
checkout = Conekta::Checkout.create(checkout_data)
|
213
|
+
id = checkout.id
|
214
|
+
expect(checkout.status).to eq("Issued")
|
215
|
+
|
216
|
+
checkout.cancel({
|
217
|
+
"id": id,
|
218
|
+
})
|
219
|
+
|
220
|
+
checkoutFound = Conekta::Checkout.find(id)
|
221
|
+
expect(checkoutFound.status).to eq("Cancelled")
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Conekta::Order do
|
4
4
|
include_context "API 2.0.0"
|
@@ -6,8 +6,8 @@ describe Conekta::Order do
|
|
6
6
|
let(:customer_info) do
|
7
7
|
{
|
8
8
|
name: "John Constantine",
|
9
|
-
phone: "
|
10
|
-
email: "hola@hola.com"
|
9
|
+
phone: "3353319758",
|
10
|
+
email: "hola@hola.com",
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ describe Conekta::Order do
|
|
15
15
|
{
|
16
16
|
email: "hola@hola.com",
|
17
17
|
name: "John Constantine",
|
18
|
-
cards: ["tok_test_visa_4242"]
|
18
|
+
cards: ["tok_test_visa_4242"],
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -23,9 +23,9 @@ describe Conekta::Order do
|
|
23
23
|
[{
|
24
24
|
payment_method: {
|
25
25
|
type: "oxxo_cash",
|
26
|
-
expires_at: (Time.now + 3600).to_i
|
26
|
+
expires_at: (Time.now + 3600).to_i,
|
27
27
|
},
|
28
|
-
amount: 35000
|
28
|
+
amount: 35000,
|
29
29
|
}]
|
30
30
|
end
|
31
31
|
|
@@ -35,7 +35,7 @@ describe Conekta::Order do
|
|
35
35
|
type: "card",
|
36
36
|
token_id: "tok_test_visa_4242",
|
37
37
|
},
|
38
|
-
amount: 35000
|
38
|
+
amount: 35000,
|
39
39
|
}]
|
40
40
|
end
|
41
41
|
|
@@ -45,17 +45,45 @@ describe Conekta::Order do
|
|
45
45
|
description: "Imported From Mex.",
|
46
46
|
unit_price: 35000,
|
47
47
|
quantity: 1,
|
48
|
-
tags: ["food", "mexican food"]
|
48
|
+
tags: ["food", "mexican food"],
|
49
49
|
}]
|
50
50
|
end
|
51
51
|
|
52
|
+
let(:msi_enabled) do
|
53
|
+
{
|
54
|
+
monthly_installments_enabled: true,
|
55
|
+
monthly_installments_options: [3, 6, 12],
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:save_card_in_checkout) do
|
60
|
+
{
|
61
|
+
on_demand_enabled: true,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:checkout_data) do
|
66
|
+
{
|
67
|
+
expired_at: (Time.now + 259200).to_i,
|
68
|
+
allowed_payment_methods: ["cash", "card", "bank_transfer"],
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:checkout_msi) do
|
73
|
+
checkout_data.merge(msi_enabled)
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:checkout_save_card) do
|
77
|
+
checkout_data.merge(save_card_in_checkout)
|
78
|
+
end
|
79
|
+
|
52
80
|
let(:order_data) do
|
53
81
|
{
|
54
|
-
currency:
|
82
|
+
currency: "mxn",
|
55
83
|
line_items: line_items,
|
56
84
|
metadata: {
|
57
|
-
test: true
|
58
|
-
}
|
85
|
+
test: true,
|
86
|
+
},
|
59
87
|
}
|
60
88
|
end
|
61
89
|
|
@@ -67,6 +95,18 @@ describe Conekta::Order do
|
|
67
95
|
order_data.merge(charges: card_charges)
|
68
96
|
end
|
69
97
|
|
98
|
+
let(:order_data_with_checkout) do
|
99
|
+
order_data.merge(checkout: checkout_data)
|
100
|
+
end
|
101
|
+
|
102
|
+
let(:order_data_with_checkout_msi) do
|
103
|
+
order_data.merge(checkout: checkout_msi)
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:order_data_with_checkout_save_card) do
|
107
|
+
order_data.merge(checkout: checkout_save_card)
|
108
|
+
end
|
109
|
+
|
70
110
|
context "creating orders" do
|
71
111
|
it "successful order create" do
|
72
112
|
order = Conekta::Order.create(order_data)
|
@@ -76,7 +116,7 @@ describe Conekta::Order do
|
|
76
116
|
end
|
77
117
|
|
78
118
|
it "unsuccessful order create" do
|
79
|
-
expect{
|
119
|
+
expect {
|
80
120
|
Conekta::Order.create({})
|
81
121
|
}.to raise_error(Conekta::ParameterValidationError)
|
82
122
|
end
|
@@ -84,19 +124,64 @@ describe Conekta::Order do
|
|
84
124
|
context "with charges" do
|
85
125
|
it "successful order create" do
|
86
126
|
order = Conekta::Order.create(order_data_with_charges.
|
87
|
-
|
127
|
+
merge(customer_info: customer_info))
|
88
128
|
|
89
129
|
expect(order).to be_a(Conekta::Order)
|
90
130
|
end
|
91
131
|
|
92
132
|
context "unsuccessful order create" do
|
93
133
|
it "with missing customer_info and customer_id" do
|
94
|
-
expect{
|
134
|
+
expect {
|
95
135
|
Conekta::Order.create(order_data_with_charges)
|
96
136
|
}.to raise_error(Conekta::ParameterValidationError)
|
97
137
|
end
|
98
138
|
end
|
99
139
|
end
|
140
|
+
|
141
|
+
context "with checkout components" do
|
142
|
+
before(:each) do
|
143
|
+
if Conekta.api_base == "https://api.conekta.io"
|
144
|
+
skip("This test should be run in staging.")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "successful order create" do
|
149
|
+
order = Conekta::Order.create(order_data_with_checkout.
|
150
|
+
merge(customer_info: customer_info))
|
151
|
+
|
152
|
+
expect(order).to be_a(Conekta::Order)
|
153
|
+
expect(order.checkout.class.to_s).to eq("Conekta::Checkout")
|
154
|
+
expect(order.checkout.id).not_to eq("")
|
155
|
+
expect(order.checkout.type).to eq("Integration")
|
156
|
+
expect(order.checkout.monthly_installments_enabled).to eq(false)
|
157
|
+
end
|
158
|
+
|
159
|
+
context "with checkout components monthly installments create" do
|
160
|
+
it "with missing customer_info and customer_id" do
|
161
|
+
order = Conekta::Order.create(order_data_with_checkout_msi.
|
162
|
+
merge(customer_info: customer_info))
|
163
|
+
|
164
|
+
expect(order).to be_a(Conekta::Order)
|
165
|
+
expect(order.checkout.class.to_s).to eq("Conekta::Checkout")
|
166
|
+
expect(order.checkout.id).not_to eq("")
|
167
|
+
expect(order.checkout.type).to eq("Integration")
|
168
|
+
expect(order.checkout.monthly_installments_enabled).to eq(true)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "with checkout components save card create" do
|
173
|
+
it "with missing customer_info and customer_id" do
|
174
|
+
order = Conekta::Order.create(order_data_with_checkout_save_card.
|
175
|
+
merge(customer_info: customer_info))
|
176
|
+
|
177
|
+
expect(order).to be_a(Conekta::Order)
|
178
|
+
expect(order.checkout.class.to_s).to eq("Conekta::Checkout")
|
179
|
+
expect(order.checkout.id).not_to eq("")
|
180
|
+
expect(order.checkout.type).to eq("Integration")
|
181
|
+
expect(order.checkout.on_demand_enabled).to eq(true)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
100
185
|
end
|
101
186
|
|
102
187
|
context "updating orders" do
|
@@ -109,7 +194,7 @@ describe Conekta::Order do
|
|
109
194
|
end
|
110
195
|
|
111
196
|
it "unsuccessful order update" do
|
112
|
-
expect{
|
197
|
+
expect {
|
113
198
|
order.update(charges: charges)
|
114
199
|
}.to raise_error(Conekta::ParameterValidationError)
|
115
200
|
end
|
@@ -122,32 +207,32 @@ describe Conekta::Order do
|
|
122
207
|
description: "Imported From Mex.",
|
123
208
|
unit_price: 35000,
|
124
209
|
quantity: 1,
|
125
|
-
tags: ["food", "mexican food"]
|
210
|
+
tags: ["food", "mexican food"],
|
126
211
|
}
|
127
212
|
end
|
128
213
|
|
129
214
|
let(:tax_line_params) do
|
130
215
|
{
|
131
216
|
description: "IVA",
|
132
|
-
amount:
|
217
|
+
amount: 600,
|
133
218
|
}
|
134
219
|
end
|
135
220
|
|
136
221
|
let(:shipping_line_params) do
|
137
222
|
{
|
138
|
-
description:
|
139
|
-
amount:
|
223
|
+
description: "Otro Shipping",
|
224
|
+
amount: 40,
|
140
225
|
tracking_number: "TRACK124",
|
141
|
-
carrier:
|
142
|
-
method:
|
226
|
+
carrier: "USPS",
|
227
|
+
method: "Train",
|
143
228
|
}
|
144
229
|
end
|
145
230
|
|
146
231
|
let(:discount_line_params) do
|
147
232
|
{
|
148
233
|
code: "Cupon de descuento",
|
149
|
-
type:
|
150
|
-
amount:
|
234
|
+
type: "loyalty",
|
235
|
+
amount: 10,
|
151
236
|
}
|
152
237
|
end
|
153
238
|
|
@@ -155,9 +240,9 @@ describe Conekta::Order do
|
|
155
240
|
{
|
156
241
|
payment_method: {
|
157
242
|
type: "oxxo_cash",
|
158
|
-
expires_at: (Time.now + 3600).to_i
|
243
|
+
expires_at: (Time.now + 3600).to_i,
|
159
244
|
},
|
160
|
-
amount: 35000
|
245
|
+
amount: 35000,
|
161
246
|
}
|
162
247
|
end
|
163
248
|
|
@@ -174,8 +259,8 @@ describe Conekta::Order do
|
|
174
259
|
state: "Alberta",
|
175
260
|
country: "MX",
|
176
261
|
postal_code: "78219",
|
177
|
-
residential: true
|
178
|
-
}
|
262
|
+
residential: true,
|
263
|
+
},
|
179
264
|
}
|
180
265
|
end
|
181
266
|
|
@@ -183,15 +268,15 @@ describe Conekta::Order do
|
|
183
268
|
|
184
269
|
it "successfully creates charge for order" do
|
185
270
|
other_params = {
|
186
|
-
currency:
|
271
|
+
currency: "mxn",
|
187
272
|
customer_info: {
|
188
|
-
name:
|
189
|
-
phone:
|
190
|
-
email:
|
191
|
-
}
|
273
|
+
name: "John Constantine",
|
274
|
+
phone: "+5213353319758",
|
275
|
+
email: "hola@hola.com",
|
276
|
+
},
|
192
277
|
}
|
193
278
|
|
194
|
-
order
|
279
|
+
order = Conekta::Order.create(order_data.merge(other_params))
|
195
280
|
charge = order.create_charge(charge_params)
|
196
281
|
|
197
282
|
expect(charge.class.to_s).to eq("Conekta::Charge")
|
@@ -206,7 +291,7 @@ describe Conekta::Order do
|
|
206
291
|
end
|
207
292
|
|
208
293
|
it "successfully creates tax line for order" do
|
209
|
-
tax_line
|
294
|
+
tax_line = order.create_tax_line(tax_line_params)
|
210
295
|
new_tax_line = order.create_tax_line(description: "ISR", amount: 2)
|
211
296
|
|
212
297
|
expect(tax_line.class.to_s).to eq("Conekta::TaxLine")
|
@@ -224,7 +309,7 @@ describe Conekta::Order do
|
|
224
309
|
it "successfully creates discount line for order" do
|
225
310
|
discount_line = order.create_discount_line(discount_line_params)
|
226
311
|
|
227
|
-
discount_line.update({amount: 1000})
|
312
|
+
discount_line.update({ amount: 1000 })
|
228
313
|
|
229
314
|
expect(discount_line.class.to_s).to eq("Conekta::DiscountLine")
|
230
315
|
expect(order.discount_lines.class.to_s).to eq("Conekta::List")
|
@@ -257,7 +342,7 @@ describe Conekta::Order do
|
|
257
342
|
|
258
343
|
it "successfully captures an order" do
|
259
344
|
order = Conekta::Order.create(order_data_with_card_charges.
|
260
|
-
|
345
|
+
merge(customer_info: customer_info, pre_authorize: true))
|
261
346
|
expect(order.payment_status).to eq("pre_authorized")
|
262
347
|
|
263
348
|
order.authorize_capture
|
@@ -269,18 +354,18 @@ describe Conekta::Order do
|
|
269
354
|
let(:order_refund) do
|
270
355
|
{
|
271
356
|
amount: 35000,
|
272
|
-
reason: "requested_by_client"
|
357
|
+
reason: "requested_by_client",
|
273
358
|
}
|
274
359
|
end
|
275
360
|
|
276
361
|
it "test successful refund" do
|
277
362
|
order = Conekta::Order.create(order_data_with_card_charges.
|
278
|
-
|
279
|
-
|
363
|
+
merge(customer_info: customer_info).
|
364
|
+
merge(line_items: line_items))
|
280
365
|
begin
|
281
|
-
|
366
|
+
order.refund(order_refund)
|
282
367
|
rescue Exception => e
|
283
|
-
|
368
|
+
puts e.details.map { |d| d.message }
|
284
369
|
end
|
285
370
|
|
286
371
|
refunded_order = Conekta::Order.find(order.id)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conekta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conekta
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: i18n
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +142,7 @@ files:
|
|
128
142
|
- lib/conekta/address.rb
|
129
143
|
- lib/conekta/card.rb
|
130
144
|
- lib/conekta/charge.rb
|
145
|
+
- lib/conekta/checkout.rb
|
131
146
|
- lib/conekta/conekta_object.rb
|
132
147
|
- lib/conekta/customer.rb
|
133
148
|
- lib/conekta/customer_info.rb
|
@@ -186,6 +201,7 @@ files:
|
|
186
201
|
- spec/conekta/1.0.0/plan_spec.rb
|
187
202
|
- spec/conekta/1.0.0/token_spec.rb
|
188
203
|
- spec/conekta/1.0.0/webhook_spec.rb
|
204
|
+
- spec/conekta/2.0.0/checkout_spec.rb
|
189
205
|
- spec/conekta/2.0.0/customer_spec.rb
|
190
206
|
- spec/conekta/2.0.0/discount_line_spec.rb
|
191
207
|
- spec/conekta/2.0.0/error_spec.rb
|
@@ -206,7 +222,7 @@ homepage: https://www.conekta.com
|
|
206
222
|
licenses:
|
207
223
|
- MIT
|
208
224
|
metadata: {}
|
209
|
-
post_install_message:
|
225
|
+
post_install_message:
|
210
226
|
rdoc_options: []
|
211
227
|
require_paths:
|
212
228
|
- lib
|
@@ -221,8 +237,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
237
|
- !ruby/object:Gem::Version
|
222
238
|
version: '0'
|
223
239
|
requirements: []
|
224
|
-
rubygems_version: 3.
|
225
|
-
signing_key:
|
240
|
+
rubygems_version: 3.3.26
|
241
|
+
signing_key:
|
226
242
|
specification_version: 4
|
227
243
|
summary: This library provides https://api.conekta.io operations
|
228
|
-
test_files:
|
244
|
+
test_files:
|
245
|
+
- spec/conekta/1.0.0/.DS_Store
|
246
|
+
- spec/conekta/1.0.0/card_spec.rb
|
247
|
+
- spec/conekta/1.0.0/charge_spec.rb
|
248
|
+
- spec/conekta/1.0.0/customer_spec.rb
|
249
|
+
- spec/conekta/1.0.0/error_spec.rb
|
250
|
+
- spec/conekta/1.0.0/event_spec.rb
|
251
|
+
- spec/conekta/1.0.0/log_spec.rb
|
252
|
+
- spec/conekta/1.0.0/payout_spec.rb
|
253
|
+
- spec/conekta/1.0.0/plan_spec.rb
|
254
|
+
- spec/conekta/1.0.0/token_spec.rb
|
255
|
+
- spec/conekta/1.0.0/webhook_spec.rb
|
256
|
+
- spec/conekta/2.0.0/checkout_spec.rb
|
257
|
+
- spec/conekta/2.0.0/customer_spec.rb
|
258
|
+
- spec/conekta/2.0.0/discount_line_spec.rb
|
259
|
+
- spec/conekta/2.0.0/error_spec.rb
|
260
|
+
- spec/conekta/2.0.0/line_item_spec.rb
|
261
|
+
- spec/conekta/2.0.0/list_spec.rb
|
262
|
+
- spec/conekta/2.0.0/order_spec.rb
|
263
|
+
- spec/conekta/2.0.0/payee_spec.rb
|
264
|
+
- spec/conekta/2.0.0/shipping_contact_spec.rb
|
265
|
+
- spec/conekta/2.0.0/shipping_line_spec.rb
|
266
|
+
- spec/conekta/2.0.0/source_spec.rb
|
267
|
+
- spec/conekta/2.0.0/tax_line_spec.rb
|
268
|
+
- spec/conekta/2.0.0/transfer_spec.rb
|
269
|
+
- spec/conekta_spec.rb
|
270
|
+
- spec/spec_helper.rb
|
271
|
+
- spec/support/fixtures/orders.json
|
272
|
+
- spec/support/shared_context.rb
|