conekta 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG +9 -1
- data/Gemfile +1 -0
- data/README.md +68 -46
- data/lib/conekta.rb +20 -1
- data/lib/conekta/address.rb +1 -0
- data/lib/conekta/card.rb +17 -3
- data/lib/conekta/charge.rb +7 -0
- data/lib/conekta/conekta_object.rb +25 -8
- data/lib/conekta/customer.rb +55 -4
- data/lib/conekta/destination.rb +29 -0
- data/lib/conekta/discount_line.rb +32 -0
- data/lib/conekta/error.rb +35 -37
- data/lib/conekta/error_list.rb +33 -0
- data/lib/conekta/event.rb +4 -1
- data/lib/conekta/fiscal_entity.rb +37 -0
- data/lib/conekta/line_item.rb +30 -0
- data/lib/conekta/list.rb +59 -0
- data/lib/conekta/log.rb +4 -0
- data/lib/conekta/operations/create_member.rb +20 -10
- data/lib/conekta/operations/custom_action.rb +1 -1
- data/lib/conekta/operations/delete.rb +3 -1
- data/lib/conekta/operations/where.rb +11 -2
- data/lib/conekta/order.rb +90 -0
- data/lib/conekta/payee.rb +4 -0
- data/lib/conekta/payment_source.rb +30 -0
- data/lib/conekta/payout_method.rb +12 -3
- data/lib/conekta/plan.rb +5 -0
- data/lib/conekta/refund.rb +2 -0
- data/lib/conekta/requestor.rb +14 -4
- data/lib/conekta/resource.rb +26 -4
- data/lib/conekta/return.rb +25 -0
- data/lib/conekta/shipping_contact.rb +32 -0
- data/lib/conekta/shipping_line.rb +33 -0
- data/lib/conekta/subscription.rb +17 -3
- data/lib/conekta/tax_line.rb +30 -0
- data/lib/conekta/token.rb +2 -0
- data/lib/conekta/util.rb +37 -3
- data/lib/conekta/version.rb +1 -1
- data/lib/conekta/webhook.rb +2 -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/{charge_spec.rb → 1.0.0/charge_spec.rb} +1 -0
- data/spec/conekta/{customer_spec.rb → 1.0.0/customer_spec.rb} +3 -2
- data/spec/conekta/{error_spec.rb → 1.0.0/error_spec.rb} +3 -1
- data/spec/conekta/{event_spec.rb → 1.0.0/event_spec.rb} +1 -0
- data/spec/conekta/{log_spec.rb → 1.0.0/log_spec.rb} +1 -0
- data/spec/conekta/{payout_spec.rb → 1.0.0/payout_spec.rb} +1 -0
- data/spec/conekta/{plan_spec.rb → 1.0.0/plan_spec.rb} +1 -0
- data/spec/conekta/{token_spec.rb → 1.0.0/token_spec.rb} +1 -0
- data/spec/conekta/{webhook_spec.rb → 1.0.0/webhook_spec.rb} +1 -0
- data/spec/conekta/2.0.0/customer_spec.rb +49 -0
- data/spec/conekta/2.0.0/discount_line_spec.rb +49 -0
- data/spec/conekta/2.0.0/error_list_spec.rb +45 -0
- data/spec/conekta/2.0.0/fiscal_entity_spec.rb +67 -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 +327 -0
- data/spec/conekta/{payee_spec.rb → 2.0.0/payee_spec.rb} +1 -1
- 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_spec.rb +6 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fixtures/orders.json +2394 -0
- data/spec/support/shared_context.rb +49 -0
- metadata +62 -21
data/lib/conekta/payee.rb
CHANGED
@@ -7,6 +7,10 @@ module Conekta
|
|
7
7
|
include Conekta::Operations::Update
|
8
8
|
include Conekta::Operations::CustomAction
|
9
9
|
include Conekta::Operations::CreateMember
|
10
|
+
|
11
|
+
attr_accessor :email, :name, :phone, :livemode, :default_destination_id,
|
12
|
+
:created_at
|
13
|
+
|
10
14
|
def load_from(response=nil)
|
11
15
|
if response
|
12
16
|
super
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Conekta
|
2
|
+
class PaymentSource < Resource
|
3
|
+
include Conekta::Operations::Delete
|
4
|
+
include Conekta::Operations::Update
|
5
|
+
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
def _url
|
8
|
+
if (id.nil? || id.to_s.empty?)
|
9
|
+
exception = Error.new({
|
10
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
11
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
12
|
+
})
|
13
|
+
|
14
|
+
if Conekta.api_version == "2.0.0"
|
15
|
+
error_list = Conekta::ErrorList.new
|
16
|
+
error_list.details << exception
|
17
|
+
exception = error_list
|
18
|
+
end
|
19
|
+
|
20
|
+
raise exception
|
21
|
+
end
|
22
|
+
|
23
|
+
self.customer._url + self.class._url + "/" + id
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
self.delete_member('customer','payment_sources')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -4,9 +4,18 @@ module Conekta
|
|
4
4
|
include Conekta::Operations::Update
|
5
5
|
include Conekta::Operations::CustomAction
|
6
6
|
def _url
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if (id.nil? || id.to_s.empty?)
|
8
|
+
exception = Error.new({
|
9
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
10
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
11
|
+
})
|
12
|
+
if Conekta.api_version == "2.0.0"
|
13
|
+
error_list = Conekta::ErrorList.new
|
14
|
+
error_list.details << exception
|
15
|
+
exception = error_list
|
16
|
+
end
|
17
|
+
raise exception
|
18
|
+
end
|
10
19
|
self.payee._url + self.class._url + "/" + id
|
11
20
|
end
|
12
21
|
def delete
|
data/lib/conekta/plan.rb
CHANGED
@@ -7,5 +7,10 @@ module Conekta
|
|
7
7
|
include Conekta::Operations::Update
|
8
8
|
include Conekta::Operations::CustomAction
|
9
9
|
include Conekta::Operations::CreateMember
|
10
|
+
|
11
|
+
attr_accessor :livemode, :created_at, :name, :amount, :currency,
|
12
|
+
:interval, :frequency, :expiry_count, :trial_period_days,
|
13
|
+
:created_at
|
14
|
+
|
10
15
|
end
|
11
16
|
end
|
data/lib/conekta/refund.rb
CHANGED
data/lib/conekta/requestor.rb
CHANGED
@@ -27,11 +27,17 @@ module Conekta
|
|
27
27
|
(if meth == :get then req.params = params else req.body = params.to_json end) if params
|
28
28
|
end
|
29
29
|
rescue Exception => e
|
30
|
-
|
30
|
+
if Conekta.api_version == "2.0.0"
|
31
|
+
json_response = {"details" => []}
|
32
|
+
else
|
33
|
+
json_response = {}
|
34
|
+
end
|
35
|
+
ErrorList.error_handler(json_response, nil)
|
31
36
|
end
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
json_response = JSON.parse(response.body)
|
39
|
+
return ErrorList.error_handler(json_response, response.status) if response.status != 200
|
40
|
+
json_response
|
35
41
|
end
|
36
42
|
|
37
43
|
private
|
@@ -59,13 +65,17 @@ module Conekta
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def conekta_headers
|
62
|
-
|
68
|
+
params = {
|
63
69
|
bindings_version: Conekta::VERSION,
|
64
70
|
lang: 'ruby',
|
65
71
|
lang_version: RUBY_VERSION,
|
66
72
|
publisher: 'conekta',
|
67
73
|
uname: Uname.uname
|
68
74
|
}
|
75
|
+
|
76
|
+
params.merge!(plugin: Conekta.plugin) if Conekta.plugin.to_s.length > 0
|
77
|
+
|
78
|
+
@conekta_headers ||= params
|
69
79
|
end
|
70
80
|
end
|
71
81
|
end
|
data/lib/conekta/resource.rb
CHANGED
@@ -1,14 +1,36 @@
|
|
1
1
|
module Conekta
|
2
2
|
class Resource < ConektaObject
|
3
|
+
|
4
|
+
attr_accessor :id
|
5
|
+
|
6
|
+
def initialize(id=nil)
|
7
|
+
@id = id
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
3
11
|
def self._url()
|
4
|
-
"/#{CGI.escape(
|
12
|
+
"/#{CGI.escape(underscored_class)}s"
|
5
13
|
end
|
14
|
+
|
6
15
|
def _url
|
7
|
-
|
8
|
-
|
9
|
-
|
16
|
+
if (id.nil? || id.to_s.empty?)
|
17
|
+
exception = Error.new({
|
18
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
19
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
20
|
+
})
|
21
|
+
if Conekta.api_version == "2.0.0"
|
22
|
+
error_list = Conekta::ErrorList.new
|
23
|
+
error_list.details << exception
|
24
|
+
exception = error_list
|
25
|
+
end
|
26
|
+
raise exception
|
27
|
+
end
|
10
28
|
|
11
29
|
return [self.class._url, id].join('/')
|
12
30
|
end
|
31
|
+
|
32
|
+
def self.underscored_class
|
33
|
+
Conekta::Util.underscore(self.to_s)
|
34
|
+
end
|
13
35
|
end
|
14
36
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Return < Resource
|
3
|
+
|
4
|
+
attr_accessor :livemode, :amount, :currency, :charge_id, :reason,
|
5
|
+
:created_at, :parent_id
|
6
|
+
def _url
|
7
|
+
if (id.nil? || id.to_s.empty?)
|
8
|
+
exception = Error.new({
|
9
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
10
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
11
|
+
})
|
12
|
+
|
13
|
+
if Conekta.api_version == "2.0.0"
|
14
|
+
error_list = Conekta::ErrorList.new
|
15
|
+
error_list.details << exception
|
16
|
+
exception = error_list
|
17
|
+
end
|
18
|
+
|
19
|
+
raise exception
|
20
|
+
end
|
21
|
+
|
22
|
+
"#{self.order._url}#{self.class._url}/#{id}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Conekta
|
2
|
+
class ShippingContact < Resource
|
3
|
+
include Conekta::Operations::Delete
|
4
|
+
include Conekta::Operations::Update
|
5
|
+
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
attr_accessor :receiver, :phone, :between_streets, :parent_id, :default
|
8
|
+
|
9
|
+
def _url
|
10
|
+
if (id.nil? || id.to_s.empty?)
|
11
|
+
exception = Error.new({
|
12
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
13
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
14
|
+
})
|
15
|
+
|
16
|
+
if Conekta.api_version == "2.0.0"
|
17
|
+
error_list = Conekta::ErrorList.new
|
18
|
+
error_list.details << exception
|
19
|
+
exception = error_list
|
20
|
+
end
|
21
|
+
|
22
|
+
raise exception
|
23
|
+
end
|
24
|
+
|
25
|
+
self.customer._url + self.class._url + "/" + id
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete
|
29
|
+
self.delete_member('customer', 'shipping_contacts')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Conekta
|
2
|
+
class ShippingLine < Resource
|
3
|
+
include Conekta::Operations::Delete
|
4
|
+
include Conekta::Operations::Update
|
5
|
+
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
attr_accessor :description, :amount, :carrier, :shipping_line_method, :tracking_number,
|
8
|
+
:parent_id, :metadata
|
9
|
+
|
10
|
+
def _url
|
11
|
+
if (id.nil? || id.to_s.empty?)
|
12
|
+
exception = Error.new({
|
13
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
14
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
15
|
+
})
|
16
|
+
|
17
|
+
if Conekta.api_version == "2.0.0"
|
18
|
+
error_list = Conekta::ErrorList.new
|
19
|
+
error_list.details << exception
|
20
|
+
exception = error_list
|
21
|
+
end
|
22
|
+
|
23
|
+
raise exception
|
24
|
+
end
|
25
|
+
|
26
|
+
"#{self.order._url}#{self.class._url}/#{id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete
|
30
|
+
self.delete_member('order', 'shipping_lines')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/conekta/subscription.rb
CHANGED
@@ -2,10 +2,24 @@ module Conekta
|
|
2
2
|
class Subscription < Resource
|
3
3
|
include Conekta::Operations::Update
|
4
4
|
include Conekta::Operations::CustomAction
|
5
|
+
|
6
|
+
attr_accessor :created_at, :subscription_start, :canceled_at, :paused_at,
|
7
|
+
:billing_cycle_start, :billing_cycle_end, :trial_start,
|
8
|
+
:trial_end, :plan_id, :customer_id, :card_id
|
9
|
+
|
5
10
|
def _url
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
if (id.nil? || id.to_s.empty?)
|
12
|
+
exception = Error.new({
|
13
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
14
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
15
|
+
})
|
16
|
+
if Conekta.api_version == "2.0.0"
|
17
|
+
error_list = Conekta::ErrorList.new
|
18
|
+
error_list.details << exception
|
19
|
+
exception = error_list
|
20
|
+
end
|
21
|
+
raise exception
|
22
|
+
end
|
9
23
|
self.customer._url + "/subscription"
|
10
24
|
end
|
11
25
|
def pause
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Conekta
|
2
|
+
class TaxLine < Resource
|
3
|
+
include Conekta::Operations::Delete
|
4
|
+
include Conekta::Operations::Update
|
5
|
+
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
attr_accessor :description, :amount, :parent_id, :metadata
|
8
|
+
|
9
|
+
def _url
|
10
|
+
if (id.nil? || id.to_s.empty?)
|
11
|
+
exception = Error.new({
|
12
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
13
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
14
|
+
})
|
15
|
+
if Conekta.api_version == "2.0.0"
|
16
|
+
error_list = Conekta::ErrorList.new
|
17
|
+
error_list.details << exception
|
18
|
+
exception = error_list
|
19
|
+
end
|
20
|
+
raise exception
|
21
|
+
end
|
22
|
+
|
23
|
+
"#{self.order._url}#{self.class._url}/#{id}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
self.delete_member('order', 'tax_lines')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/conekta/token.rb
CHANGED
data/lib/conekta/util.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Conekta
|
2
2
|
module Util
|
3
|
+
|
3
4
|
def self.types
|
4
5
|
@types ||= {
|
5
6
|
'bank_transfer_payment' => PaymentMethod,
|
@@ -14,6 +15,7 @@ module Conekta
|
|
14
15
|
'payee' => Payee,
|
15
16
|
'payout' => Payout,
|
16
17
|
'payout_method' => PayoutMethod,
|
18
|
+
'destination' => Destination,
|
17
19
|
'plan' => Plan,
|
18
20
|
'subscription' => Subscription,
|
19
21
|
'token' => Token,
|
@@ -21,16 +23,34 @@ module Conekta
|
|
21
23
|
'webhook_log' => WebhookLog,
|
22
24
|
'refund' => Refund,
|
23
25
|
'line_item' => LineItem,
|
24
|
-
'address' => Address
|
26
|
+
'address' => Address,
|
27
|
+
'order' => Order,
|
28
|
+
'payment_source' => PaymentSource,
|
29
|
+
'tax_line' => TaxLine,
|
30
|
+
'shipping_line' => ShippingLine,
|
31
|
+
'discount_line' => DiscountLine,
|
32
|
+
'fiscal_entity' => FiscalEntity,
|
33
|
+
'shipping_contact' => ShippingContact,
|
34
|
+
'list' => List,
|
35
|
+
'return' => Return
|
25
36
|
}
|
26
37
|
end
|
38
|
+
|
27
39
|
def self.convert_to_conekta_object(name,resp)
|
28
|
-
|
40
|
+
return resp if name == "data" # event data should not be parsed into objects
|
41
|
+
if resp.kind_of?(Hash)
|
29
42
|
if resp.has_key?('object') and types[resp['object']]
|
30
|
-
|
43
|
+
if resp['object'] == "list"
|
44
|
+
instance = types[resp['object']].new(name, resp)
|
45
|
+
else
|
46
|
+
instance = types[resp['object']].new()
|
47
|
+
end
|
48
|
+
|
31
49
|
instance.load_from(resp)
|
50
|
+
|
32
51
|
return instance
|
33
52
|
elsif name.instance_of? String
|
53
|
+
name = "shippin_line_method" if name == "method"
|
34
54
|
name = "event_data" if camelize(name) == "Data"
|
35
55
|
name = "obj" if camelize(name) == "Object"
|
36
56
|
if !Object.const_defined?(camelize(name))
|
@@ -38,10 +58,13 @@ module Conekta
|
|
38
58
|
else
|
39
59
|
instance = constantize(camelize(name)).new
|
40
60
|
end
|
61
|
+
|
41
62
|
instance.load_from(resp)
|
63
|
+
|
42
64
|
return instance
|
43
65
|
end
|
44
66
|
end
|
67
|
+
|
45
68
|
if resp.kind_of?(Array)
|
46
69
|
instance = ConektaObject.new
|
47
70
|
instance.load_from(resp)
|
@@ -56,10 +79,21 @@ module Conekta
|
|
56
79
|
end
|
57
80
|
return instance
|
58
81
|
end
|
82
|
+
|
83
|
+
def self.underscore(str)
|
84
|
+
str.split(/::/).last.
|
85
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
86
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
87
|
+
tr("-", "_").
|
88
|
+
downcase
|
89
|
+
end
|
90
|
+
|
59
91
|
protected
|
92
|
+
|
60
93
|
def self.camelize(str)
|
61
94
|
str.split('_').map{|e| e.capitalize}.join
|
62
95
|
end
|
96
|
+
|
63
97
|
def self.constantize(camel_cased_word)
|
64
98
|
names = camel_cased_word.split('::')
|
65
99
|
|
data/lib/conekta/version.rb
CHANGED
data/lib/conekta/webhook.rb
CHANGED
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
|