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,66 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Payee < Resource
|
3
|
+
include Conekta::Operations::Find
|
4
|
+
include Conekta::Operations::Where
|
5
|
+
include Conekta::Operations::Create
|
6
|
+
include Conekta::Operations::Delete
|
7
|
+
include Conekta::Operations::Update
|
8
|
+
include Conekta::Operations::CustomAction
|
9
|
+
include Conekta::Operations::CreateMember
|
10
|
+
|
11
|
+
attr_accessor :email, :name, :phone, :livemode, :default_destination_id,
|
12
|
+
:created_at
|
13
|
+
|
14
|
+
def load_from(response=nil)
|
15
|
+
if response
|
16
|
+
super
|
17
|
+
end
|
18
|
+
payee = self
|
19
|
+
if Conekta.api_version <= "1.0.0"
|
20
|
+
self.payout_methods.each do |k,v|
|
21
|
+
if !v.respond_to? :deleted || !v.deleted
|
22
|
+
v.create_attr('payee', payee)
|
23
|
+
self.payout_methods.set_val(k,v)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
self.destinations.each do |k,v|
|
28
|
+
if !v.respond_to? :deleted || !v.deleted
|
29
|
+
v.create_attr('payee', payee)
|
30
|
+
self.destinations.set_val(k,v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_payout_method(params)
|
37
|
+
raise_version_error("1.0.0") if Conekta.api_version > "1.0.0"
|
38
|
+
self.create_member('payout_methods', params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_destination(params)
|
42
|
+
raise_version_error("2.0.0") if Conekta.api_version <= "1.0.0"
|
43
|
+
self.create_member('destinations', params)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def raise_version_error(version)
|
48
|
+
exception = Error.error_handler({
|
49
|
+
"details" => [{
|
50
|
+
"debug_message" => I18n.t(
|
51
|
+
'error.conflict.version.unspecified',
|
52
|
+
{ resource: self.class.class_name, locale: :en }
|
53
|
+
),
|
54
|
+
"message" => I18n.t(
|
55
|
+
'error.conflict.version.unspecified_purchaser',
|
56
|
+
{ locale: Conekta.locale.to_sym }
|
57
|
+
),
|
58
|
+
"param" => nil,
|
59
|
+
"code" => "error.conflict.version.unspecified"
|
60
|
+
}]
|
61
|
+
}, 409)
|
62
|
+
|
63
|
+
raise exception
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
ensure_id
|
9
|
+
|
10
|
+
self.customer._url + self.class._url + "/" + id
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete
|
14
|
+
self.delete_member('customer', 'payment_sources')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Conekta
|
2
|
+
class PayoutMethod < Resource
|
3
|
+
include Conekta::Operations::Delete
|
4
|
+
include Conekta::Operations::Update
|
5
|
+
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
def _url
|
8
|
+
ensure_id
|
9
|
+
|
10
|
+
self.payee._url + self.class._url + "/" + id
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete
|
14
|
+
self.delete_member('payee','payout_methods')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/conekta/plan.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Plan < Resource
|
3
|
+
include Conekta::Operations::Find
|
4
|
+
include Conekta::Operations::Where
|
5
|
+
include Conekta::Operations::Create
|
6
|
+
include Conekta::Operations::Delete
|
7
|
+
include Conekta::Operations::Update
|
8
|
+
include Conekta::Operations::CustomAction
|
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
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Conekta
|
5
|
+
class Requestor
|
6
|
+
require 'sys/uname'
|
7
|
+
include Sys
|
8
|
+
|
9
|
+
attr_reader :api_key
|
10
|
+
|
11
|
+
def initialize(api_key=nil)
|
12
|
+
if (api_key.nil?)
|
13
|
+
@api_key = Conekta.api_key
|
14
|
+
else
|
15
|
+
@api_key = api_key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_url(_url='')
|
20
|
+
api_base = Conekta.api_base
|
21
|
+
api_base + _url
|
22
|
+
end
|
23
|
+
|
24
|
+
def request(meth, _url, params = nil)
|
25
|
+
_url = self.api_url(_url)
|
26
|
+
meth = meth.downcase
|
27
|
+
|
28
|
+
begin
|
29
|
+
connection = build_connection(_url, params)
|
30
|
+
response = connection.method(meth).call do |req|
|
31
|
+
(if meth == :get then req.params = params else req.body = params.to_json end) if params
|
32
|
+
end
|
33
|
+
rescue Exception => e
|
34
|
+
raise Error.error_handler({}, nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
json_response = JSON.parse(response.body)
|
38
|
+
raise Error.error_handler(json_response, response.status) if response.status != 200
|
39
|
+
json_response
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def build_connection(_url, params = nil)
|
45
|
+
connection = Faraday.new(
|
46
|
+
:url => _url,
|
47
|
+
:ssl => { :ca_file=> File.dirname(__FILE__) + '/../ssl_data/ca_bundle.crt'}
|
48
|
+
) do |faraday|
|
49
|
+
faraday.adapter Faraday.default_adapter
|
50
|
+
end
|
51
|
+
|
52
|
+
set_headers_for(connection)
|
53
|
+
return connection
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_headers_for(connection)
|
57
|
+
connection.headers['Content-Type'] = 'application/json'
|
58
|
+
connection.headers['X-Conekta-Client-User-Agent'] = conekta_headers.to_json
|
59
|
+
connection.headers['User-Agent'] = 'Conekta/v1 RubyBindings/' + Conekta::VERSION
|
60
|
+
connection.headers['Accept'] = "application/vnd.conekta-v#{Conekta.api_version}+json"
|
61
|
+
connection.headers['Accept-Language'] = Conekta.locale.to_s
|
62
|
+
connection.headers['Authorization'] = "Basic #{ Base64.strict_encode64("#{self.api_key}" + ':')}"
|
63
|
+
return connection
|
64
|
+
end
|
65
|
+
|
66
|
+
def conekta_headers
|
67
|
+
params = {
|
68
|
+
bindings_version: Conekta::VERSION,
|
69
|
+
lang: 'ruby',
|
70
|
+
lang_version: RUBY_VERSION,
|
71
|
+
publisher: 'conekta',
|
72
|
+
uname: Uname.uname
|
73
|
+
}
|
74
|
+
|
75
|
+
params.merge!(plugin: Conekta.plugin) if Conekta.plugin.to_s.length > 0
|
76
|
+
|
77
|
+
@conekta_headers ||= params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Resource < ConektaObject
|
3
|
+
|
4
|
+
attr_accessor :id
|
5
|
+
|
6
|
+
def initialize(id=nil)
|
7
|
+
@id = id
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
11
|
+
def self._url()
|
12
|
+
"/#{CGI.escape(underscored_class)}s"
|
13
|
+
end
|
14
|
+
|
15
|
+
def _url
|
16
|
+
ensure_id
|
17
|
+
|
18
|
+
return [self.class._url, id].join('/')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.underscored_class
|
22
|
+
Conekta::Util.underscore(self.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_member_with_relation(api_key, member, params, parent)
|
26
|
+
parent_klass = parent.class.underscored_class
|
27
|
+
child = self.create_member(api_key, member, params)
|
28
|
+
child.create_attr(parent_klass.to_s, parent)
|
29
|
+
return child
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def ensure_id
|
34
|
+
if (id.nil? || id.to_s.empty?)
|
35
|
+
exception = Error.error_handler({
|
36
|
+
"details" => [{
|
37
|
+
"debug_message" => I18n.t(
|
38
|
+
'error.resource.id',
|
39
|
+
{ resource: self.class.class_name, locale: :en }
|
40
|
+
),
|
41
|
+
"message" => I18n.t(
|
42
|
+
'error.resource.id_purchaser',
|
43
|
+
{ locale: Conekta.locale.to_sym }
|
44
|
+
),
|
45
|
+
"param" => "id",
|
46
|
+
"code" => "error.resource.id"
|
47
|
+
}]
|
48
|
+
}, -2)
|
49
|
+
|
50
|
+
raise exception
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
ensure_id
|
11
|
+
|
12
|
+
self.customer._url + self.class._url + "/" + id
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete
|
16
|
+
self.delete_member('customer', 'shipping_contacts')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
ensure_id
|
12
|
+
|
13
|
+
"#{self.order._url}#{self.class._url}/#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete
|
17
|
+
self.delete_member('order', 'shipping_lines')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Subscription < Resource
|
3
|
+
include Conekta::Operations::Update
|
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
|
+
|
10
|
+
def _url
|
11
|
+
ensure_id
|
12
|
+
|
13
|
+
self.customer._url + "/subscription"
|
14
|
+
end
|
15
|
+
def pause
|
16
|
+
custom_action(:post, 'pause')
|
17
|
+
end
|
18
|
+
def resume
|
19
|
+
custom_action(:post, 'resume')
|
20
|
+
end
|
21
|
+
def cancel
|
22
|
+
custom_action(:post, 'cancel')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
ensure_id
|
11
|
+
|
12
|
+
"#{self.order._url}#{self.class._url}/#{id}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete
|
16
|
+
self.delete_member('order', 'tax_lines')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/conekta/util.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
module Conekta
|
2
|
+
module Util
|
3
|
+
|
4
|
+
def self.types
|
5
|
+
@types ||= {
|
6
|
+
'customer_info' => ::Conekta::CustomerInfo,
|
7
|
+
'details' => ::Conekta::Details,
|
8
|
+
'bank_transfer_payment' => ::Conekta::PaymentMethod,
|
9
|
+
'bank_transfer_payout_method' => ::Conekta::Method,
|
10
|
+
'card' => ::Conekta::Card,
|
11
|
+
'card_payment' => ::Conekta::PaymentMethod,
|
12
|
+
'cash_payment' => ::Conekta::PaymentMethod,
|
13
|
+
'charge' => ::Conekta::Charge,
|
14
|
+
'customer' => ::Conekta::Customer,
|
15
|
+
'event' => ::Conekta::Event,
|
16
|
+
'log' => ::Conekta::Log,
|
17
|
+
'payee' => ::Conekta::Payee,
|
18
|
+
'payout' => ::Conekta::Payout,
|
19
|
+
'payout_method' => ::Conekta::PayoutMethod,
|
20
|
+
'destination' => ::Conekta::Destination,
|
21
|
+
'plan' => ::Conekta::Plan,
|
22
|
+
'subscription' => ::Conekta::Subscription,
|
23
|
+
'token' => ::Conekta::Token,
|
24
|
+
'webhook' => ::Conekta::Webhook,
|
25
|
+
'webhook_log' => ::Conekta::WebhookLog,
|
26
|
+
'refund' => ::Conekta::Refund,
|
27
|
+
'line_item' => ::Conekta::LineItem,
|
28
|
+
'address' => ::Conekta::Address,
|
29
|
+
'billing_address' => ::Conekta::Address,
|
30
|
+
'shipping_address' => ::Conekta::Address,
|
31
|
+
'order' => ::Conekta::Order,
|
32
|
+
'payment_source' => ::Conekta::PaymentSource,
|
33
|
+
'tax_line' => ::Conekta::TaxLine,
|
34
|
+
'shipping_line' => ::Conekta::ShippingLine,
|
35
|
+
'discount_line' => ::Conekta::DiscountLine,
|
36
|
+
'shipping_contact' => ::Conekta::ShippingContact,
|
37
|
+
'transfer' => ::Conekta::Transfer,
|
38
|
+
'list' => ::Conekta::List
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.convert_to_conekta_object(name,resp)
|
43
|
+
# these json strings should not be parsed into objects
|
44
|
+
return resp if ["data", "request_body", "request_headers", "response_headers", "response_body", "query_string", "metadata", "antifraud_info"].include?(name)
|
45
|
+
if resp.kind_of?(Hash)
|
46
|
+
if resp.has_key?('object') and types[resp['object']]
|
47
|
+
if resp['object'] == "list"
|
48
|
+
instance = types[resp['object']].new(name, resp)
|
49
|
+
else
|
50
|
+
instance = types[resp['object']].new()
|
51
|
+
end
|
52
|
+
|
53
|
+
instance.load_from(resp)
|
54
|
+
|
55
|
+
return instance
|
56
|
+
elsif name.instance_of? String
|
57
|
+
name = "shippin_line_method" if name == "method"
|
58
|
+
name = "event_data" if camelize(name) == "Data"
|
59
|
+
name = "obj" if camelize(name) == "Object"
|
60
|
+
if !Object.const_defined?(camelize(name))
|
61
|
+
instance = Object.const_set(camelize(name), Class.new(ConektaObject)).new
|
62
|
+
else
|
63
|
+
begin
|
64
|
+
instance = constantize("Conekta::"+camelize(name)).new
|
65
|
+
rescue # Class is not defined
|
66
|
+
instance = constantize(camelize(name)).new
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
instance.load_from(resp)
|
71
|
+
|
72
|
+
return instance
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
if resp.kind_of?(Array)
|
77
|
+
instance = ConektaObject.new
|
78
|
+
instance.load_from(resp)
|
79
|
+
if !resp.empty? and resp.first.instance_of? Hash and !resp.first["object"]
|
80
|
+
resp.each_with_index do |r, i|
|
81
|
+
obj = convert_to_conekta_object(name,r)
|
82
|
+
instance.set_val(i,obj)
|
83
|
+
instance[i] = obj
|
84
|
+
end
|
85
|
+
end
|
86
|
+
return instance
|
87
|
+
end
|
88
|
+
return instance
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.underscore(str)
|
92
|
+
str.split(/::/).last.
|
93
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
94
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
95
|
+
tr("-", "_").
|
96
|
+
downcase
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
def self.camelize(str)
|
102
|
+
str.split('_').map{|e| e.capitalize}.join
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.constantize(camel_cased_word)
|
106
|
+
names = camel_cased_word.split('::')
|
107
|
+
|
108
|
+
# Trigger a builtin NameError exception including the ill-formed constant in the message.
|
109
|
+
Object.const_get(camel_cased_word) if names.empty?
|
110
|
+
|
111
|
+
# Remove the first blank element in case of '::ClassName' notation.
|
112
|
+
names.shift if names.size > 1 && names.first.empty?
|
113
|
+
|
114
|
+
names.inject(Object) do |constant, name|
|
115
|
+
if constant == Object
|
116
|
+
constant.const_get(name)
|
117
|
+
else
|
118
|
+
candidate = constant.const_get(name)
|
119
|
+
next candidate if constant.const_defined?(name, false)
|
120
|
+
next candidate unless Object.const_defined?(name)
|
121
|
+
|
122
|
+
# Go down the ancestors to check it it's owned
|
123
|
+
# directly before we reach Object or the end of ancestors.
|
124
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
125
|
+
break const if ancestor == Object
|
126
|
+
break ancestor if ancestor.const_defined?(name, false)
|
127
|
+
const
|
128
|
+
end
|
129
|
+
|
130
|
+
# owner is in Object, so raise
|
131
|
+
constant.const_get(name, false)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Conekta
|
2
|
+
class Webhook < Resource
|
3
|
+
include Conekta::Operations::Find
|
4
|
+
include Conekta::Operations::Where
|
5
|
+
include Conekta::Operations::Create
|
6
|
+
include Conekta::Operations::Delete
|
7
|
+
include Conekta::Operations::Update
|
8
|
+
include Conekta::Operations::CustomAction
|
9
|
+
|
10
|
+
attr_accessor :url, :status, :production_enabled, :development_enabled, :subscribed_events
|
11
|
+
end
|
12
|
+
end
|
data/lib/conekta.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "json"
|
2
|
+
require "i18n"
|
3
|
+
|
4
|
+
require "conekta/version"
|
5
|
+
|
6
|
+
require "conekta/operations/find"
|
7
|
+
require "conekta/operations/where"
|
8
|
+
require "conekta/operations/create"
|
9
|
+
require "conekta/operations/delete"
|
10
|
+
require "conekta/operations/update"
|
11
|
+
require "conekta/operations/custom_action"
|
12
|
+
require "conekta/operations/create_member"
|
13
|
+
|
14
|
+
require "conekta/conekta_object"
|
15
|
+
require "conekta/list"
|
16
|
+
require "conekta/resource"
|
17
|
+
require "conekta/requestor"
|
18
|
+
require "conekta/util"
|
19
|
+
require "conekta/error"
|
20
|
+
require "conekta/error_details"
|
21
|
+
|
22
|
+
require "conekta/customer_info"
|
23
|
+
require "conekta/details"
|
24
|
+
require "conekta/event"
|
25
|
+
require "conekta/charge"
|
26
|
+
require "conekta/customer"
|
27
|
+
require "conekta/card"
|
28
|
+
require "conekta/discount_line"
|
29
|
+
require "conekta/log"
|
30
|
+
require "conekta/method"
|
31
|
+
require "conekta/order"
|
32
|
+
require "conekta/payment_method"
|
33
|
+
require "conekta/payee"
|
34
|
+
require "conekta/payout"
|
35
|
+
require "conekta/payout_method"
|
36
|
+
require "conekta/destination"
|
37
|
+
require "conekta/plan"
|
38
|
+
require "conekta/shipping_contact"
|
39
|
+
require "conekta/shipping_line"
|
40
|
+
require "conekta/payment_source"
|
41
|
+
require "conekta/subscription"
|
42
|
+
require "conekta/tax_line"
|
43
|
+
require "conekta/token"
|
44
|
+
require "conekta/transfer"
|
45
|
+
require "conekta/webhook"
|
46
|
+
require "conekta/webhook_log"
|
47
|
+
require "conekta/refund"
|
48
|
+
require "conekta/line_item"
|
49
|
+
require "conekta/address"
|
50
|
+
|
51
|
+
module Conekta
|
52
|
+
I18n.load_path += Dir[File.join(File.expand_path('../..', __FILE__), 'locales', '*.{rb,yml}').to_s]
|
53
|
+
|
54
|
+
@api_base = 'https://api.conekta.io'
|
55
|
+
@api_version = '2.0.0'
|
56
|
+
@locale = 'es'
|
57
|
+
|
58
|
+
def self.config
|
59
|
+
yield self
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.plugin
|
63
|
+
@plugin
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.plugin=(plugin)
|
67
|
+
@plugin = plugin
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.api_base
|
71
|
+
@api_base
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.api_base=(api_base)
|
75
|
+
@api_base = api_base
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.api_version
|
79
|
+
@api_version
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.api_version=(api_version)
|
83
|
+
@api_version = api_version
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.api_key
|
87
|
+
@api_key
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.api_key=(api_key)
|
91
|
+
@api_key = api_key
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.locale
|
95
|
+
@locale
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.locale=(locale)
|
99
|
+
@locale = locale
|
100
|
+
end
|
101
|
+
end
|