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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10843b196a15bc8eed5bb035b6eeadc130c5e700
|
4
|
+
data.tar.gz: fb7a22fc70af5e7ed2ea715feb27b06d87d21df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b5319eafe9ed1073033fc58d435de0545feb09f492dc5208e90b60feb9455043c561bf9bf2d4b0159260ffc78e318a3dbd0f67587cb6f7d8dac8910705e74ff
|
7
|
+
data.tar.gz: be9b23b5ae1a3ff0d767e3e0dca26099073238c7e1b9c0921cfc7ecec32f8cff6d6cf391f9a642dc994bf144f7d641e1bd89afd22dd7b62cd7d7df25e27584fb
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
![alt tag](https://raw.github.com/conekta/conekta-ruby/master/readme_files/cover.png)
|
2
2
|
|
3
|
-
# Conekta Ruby v.
|
3
|
+
# Conekta Ruby v.1.1.0
|
4
4
|
|
5
5
|
This is a ruby library that allows interaction with https://api.conekta.io API.
|
6
6
|
|
@@ -31,58 +31,80 @@ Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
|
31
31
|
Conekta.config do |c|
|
32
32
|
c.locale = :es
|
33
33
|
c.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
34
|
-
c.api_version = '
|
34
|
+
c.api_version = '2.0.0'
|
35
35
|
end
|
36
36
|
|
37
37
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
card: params[:conektaTokenId]
|
44
|
-
#"tok_a4Ff0dD2xYZZq82d9"
|
45
|
-
})
|
46
|
-
rescue Conekta::ParameterValidationError => e
|
47
|
-
puts e.message
|
48
|
-
#alguno de los parámetros fueron inválidos
|
49
|
-
rescue Conekta::ProcessingError => e
|
50
|
-
puts e.message
|
51
|
-
#la tarjeta no pudo ser procesada
|
52
|
-
rescue Conekta::Error => e
|
53
|
-
puts e.message
|
54
|
-
#un error ocurrió que no sucede en el flujo normal de cobros como por ejemplo un auth_key incorrecto
|
38
|
+
order = Conekta::Order.create(order_data_with_charges.
|
39
|
+
merge(customer_info: customer_info))
|
40
|
+
rescue Conekta::ErrorList => error_list
|
41
|
+
for error_detail in error_list.details do
|
42
|
+
puts error_detail.message
|
55
43
|
end
|
44
|
+
end
|
56
45
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
67
|
-
|
68
|
-
|
69
|
-
"
|
70
|
-
"
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
"
|
46
|
+
{
|
47
|
+
"livemode": false,
|
48
|
+
"amount": 35000,
|
49
|
+
"status": "created",
|
50
|
+
"currency": "MXN",
|
51
|
+
"capture": true,
|
52
|
+
"last_payment_info": {
|
53
|
+
"charge_id": "5887772aedbb6ea3a30056c5",
|
54
|
+
"payment_method": "OxxoPayment",
|
55
|
+
"status": "pending_payment"
|
56
|
+
},
|
57
|
+
"customer_info": {
|
58
|
+
"email": "hola@hola.com",
|
59
|
+
"phone": "+5213353319758",
|
60
|
+
"name": "John Constantine",
|
61
|
+
"first_paid_at": 0
|
62
|
+
},
|
63
|
+
"object": "order",
|
64
|
+
"id": "ord_2ftyJuymR9FZczvPg",
|
65
|
+
"metadata": {
|
66
|
+
"test": true
|
67
|
+
},
|
68
|
+
"created_at": 1485272874,
|
69
|
+
"updated_at": 1485272874,
|
70
|
+
"line_items": {
|
71
|
+
"0": {
|
72
|
+
"name": "Box of Cohiba S1s",
|
73
|
+
"description": "Imported From Mex.",
|
74
|
+
"unit_price": 35000,
|
75
|
+
"quantity": 1,
|
76
|
+
"tags": ["food", "mexican food"],
|
77
|
+
"type": "physical",
|
78
|
+
"object": "line_item",
|
79
|
+
"id": "line_item_2ftyJuymR9FZczvPe",
|
80
|
+
"parent_id": "ord_2ftyJuymR9FZczvPg",
|
81
|
+
"metadata": {}
|
82
|
+
}
|
83
|
+
},
|
84
|
+
"charges": {
|
85
|
+
"0": {
|
86
|
+
"id": "5887772aedbb6ea3a30056c5",
|
87
|
+
"livemode": false,
|
88
|
+
"created_at": 1485272874,
|
89
|
+
"currency": "MXN",
|
90
|
+
"payment_method": {
|
91
|
+
"barcode_url": "https://s3.amazonaws.com/cash_payment_barcodes/sandbox_reference.png",
|
92
|
+
"service_name": "OxxoPay",
|
93
|
+
"object": "cash_payment",
|
94
|
+
"type": "oxxo",
|
95
|
+
"expires_at": 1485276473,
|
96
|
+
"store_name": "OXXO",
|
97
|
+
"reference": "93345678901234"
|
98
|
+
},
|
99
|
+
"object": "charge",
|
100
|
+
"status": "pending_payment",
|
101
|
+
"amount": 35000,
|
102
|
+
"fee": 1421,
|
103
|
+
"customer_id": "",
|
104
|
+
"order_id": "ord_2ftyJuymR9FZczvPg"
|
84
105
|
}
|
85
106
|
}
|
107
|
+
}
|
86
108
|
```
|
87
109
|
|
88
110
|
License
|
data/lib/conekta.rb
CHANGED
@@ -12,41 +12,60 @@ require "conekta/operations/custom_action"
|
|
12
12
|
require "conekta/operations/create_member"
|
13
13
|
|
14
14
|
require "conekta/conekta_object"
|
15
|
+
require "conekta/list"
|
15
16
|
require "conekta/resource"
|
16
17
|
require "conekta/requestor"
|
17
18
|
require "conekta/util"
|
18
19
|
require "conekta/error"
|
20
|
+
require "conekta/error_list"
|
19
21
|
|
20
22
|
require "conekta/event"
|
21
23
|
require "conekta/charge"
|
22
24
|
require "conekta/customer"
|
23
25
|
require "conekta/card"
|
26
|
+
require "conekta/discount_line"
|
27
|
+
require "conekta/fiscal_entity"
|
24
28
|
require "conekta/log"
|
25
29
|
require "conekta/method"
|
30
|
+
require "conekta/order"
|
26
31
|
require "conekta/payment_method"
|
27
32
|
require "conekta/payee"
|
28
33
|
require "conekta/payout"
|
29
34
|
require "conekta/payout_method"
|
35
|
+
require "conekta/destination"
|
30
36
|
require "conekta/plan"
|
37
|
+
require "conekta/shipping_contact"
|
38
|
+
require "conekta/shipping_line"
|
39
|
+
require "conekta/payment_source"
|
31
40
|
require "conekta/subscription"
|
41
|
+
require "conekta/tax_line"
|
32
42
|
require "conekta/token"
|
33
43
|
require "conekta/webhook"
|
34
44
|
require "conekta/webhook_log"
|
35
45
|
require "conekta/refund"
|
36
46
|
require "conekta/line_item"
|
47
|
+
require "conekta/return"
|
37
48
|
require "conekta/address"
|
38
49
|
|
39
50
|
module Conekta
|
40
51
|
I18n.load_path += Dir[File.join(File.expand_path('../..', __FILE__), 'locales', '*.{rb,yml}').to_s]
|
41
52
|
|
42
53
|
@api_base = 'https://api.conekta.io'
|
43
|
-
@api_version = '
|
54
|
+
@api_version = '2.0.0'
|
44
55
|
@locale = 'es'
|
45
56
|
|
46
57
|
def self.config
|
47
58
|
yield self
|
48
59
|
end
|
49
60
|
|
61
|
+
def self.plugin
|
62
|
+
@plugin
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.plugin=(plugin)
|
66
|
+
@plugin = plugin
|
67
|
+
end
|
68
|
+
|
50
69
|
def self.api_base
|
51
70
|
@api_base
|
52
71
|
end
|
data/lib/conekta/address.rb
CHANGED
data/lib/conekta/card.rb
CHANGED
@@ -3,10 +3,24 @@ module Conekta
|
|
3
3
|
include Conekta::Operations::Delete
|
4
4
|
include Conekta::Operations::Update
|
5
5
|
include Conekta::Operations::CustomAction
|
6
|
+
|
7
|
+
attr_accessor :created_at, :last4, :bin, :name,
|
8
|
+
:exp_month, :exp_year, :brand,
|
9
|
+
:parent_id, :default
|
10
|
+
|
6
11
|
def _url
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
if (id.nil? || id.to_s.empty?)
|
13
|
+
exception = Error.new({
|
14
|
+
"message" => I18n.t('error.resource.id', { resource: self.class.class_name, locale: :en }),
|
15
|
+
"message_to_purchaser" => I18n.t('error.resource.id_purchaser', { locale: Conekta.locale.to_sym })
|
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
|
+
raise exception
|
23
|
+
end
|
10
24
|
self.customer._url + self.class._url + "/" + id
|
11
25
|
end
|
12
26
|
def delete
|
data/lib/conekta/charge.rb
CHANGED
@@ -4,6 +4,13 @@ module Conekta
|
|
4
4
|
include Conekta::Operations::Where
|
5
5
|
include Conekta::Operations::Create
|
6
6
|
include Conekta::Operations::CustomAction
|
7
|
+
|
8
|
+
attr_accessor :livemode, :amount, :created_at, :currency, :description,
|
9
|
+
:reference_id, :failure_code, :failure_message, :fee,
|
10
|
+
:monthly_installments, :device_fingerprint, :status,
|
11
|
+
:exchange_rate, :foreign_currency, :amount_in_foreign_currency,
|
12
|
+
:checkout_id, :checkout_order_count
|
13
|
+
|
7
14
|
def capture
|
8
15
|
custom_action(:post, 'capture')
|
9
16
|
end
|
@@ -1,25 +1,29 @@
|
|
1
1
|
module Conekta
|
2
2
|
class ConektaObject < Hash
|
3
|
-
attr_reader :id
|
4
3
|
attr_reader :values
|
5
|
-
|
4
|
+
|
5
|
+
def initialize
|
6
6
|
@values = Hash.new
|
7
|
-
@id = id.to_s
|
8
7
|
end
|
8
|
+
|
9
9
|
def set_val(k,v)
|
10
10
|
@values[k] = v
|
11
11
|
self[k] = v
|
12
12
|
end
|
13
|
+
|
13
14
|
def unset_key(k)
|
14
15
|
@values.delete(k)
|
15
16
|
self.delete(k)
|
16
17
|
end
|
18
|
+
|
17
19
|
def first
|
18
20
|
self[0]
|
19
21
|
end
|
22
|
+
|
20
23
|
def last
|
21
24
|
self[self.count - 1]
|
22
25
|
end
|
26
|
+
|
23
27
|
def load_from(response)
|
24
28
|
if response.instance_of?(Array)
|
25
29
|
response.each_with_index do |v, i|
|
@@ -32,9 +36,11 @@ module Conekta
|
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
39
|
+
|
35
40
|
def to_s
|
36
41
|
@values.inspect
|
37
42
|
end
|
43
|
+
|
38
44
|
def inspect
|
39
45
|
if self.respond_to? :each
|
40
46
|
if self.class.class_name != "ConektaObject"
|
@@ -46,26 +52,33 @@ module Conekta
|
|
46
52
|
super
|
47
53
|
end
|
48
54
|
end
|
55
|
+
|
49
56
|
def self.class_name
|
50
57
|
self.name.split('::')[-1]
|
51
58
|
end
|
59
|
+
|
52
60
|
def class_name
|
53
61
|
self.class.name.split('::')[-1]
|
54
62
|
end
|
63
|
+
|
55
64
|
def create_attr(k,v)
|
56
65
|
# Conflict with Resource Class Url
|
66
|
+
k = "_#{k}" if k.to_s == "method"
|
67
|
+
|
57
68
|
if ! k.to_s.match(/-/) and ! k.to_s.match(/^[0-9]+/)
|
58
|
-
create_method( "#{k}=".to_sym ) { |val|
|
69
|
+
create_method( "#{k}=".to_sym ) { |val|
|
59
70
|
instance_variable_set( "@" + k, val)
|
60
71
|
}
|
61
72
|
self.send("#{k}=".to_sym, v)
|
62
73
|
self.class.send(:remove_method, "#{k}=".to_sym)
|
63
|
-
create_method( k.to_sym ) {
|
64
|
-
instance_variable_get( "@" + k )
|
74
|
+
create_method( k.to_sym ) {
|
75
|
+
instance_variable_get( "@" + k )
|
65
76
|
}
|
66
77
|
end
|
67
78
|
end
|
79
|
+
|
68
80
|
protected
|
81
|
+
|
69
82
|
def to_hash
|
70
83
|
hash = Hash.new
|
71
84
|
self.values.each do |k,v|
|
@@ -73,13 +86,16 @@ module Conekta
|
|
73
86
|
end
|
74
87
|
hash
|
75
88
|
end
|
76
|
-
|
77
|
-
|
89
|
+
|
90
|
+
def create_method(name, &block)
|
91
|
+
self.class.send(:define_method, name, &block)
|
78
92
|
end
|
93
|
+
|
79
94
|
def load_from_enumerable(k,v)
|
80
95
|
if v.respond_to? :each and !v.instance_of?(ConektaObject)
|
81
96
|
v = Conekta::Util.convert_to_conekta_object(k,v)
|
82
97
|
end
|
98
|
+
|
83
99
|
if self.instance_of?(ConektaObject)
|
84
100
|
self[k] = v
|
85
101
|
else
|
@@ -87,5 +103,6 @@ module Conekta
|
|
87
103
|
end
|
88
104
|
self.set_val(k,v)
|
89
105
|
end
|
106
|
+
|
90
107
|
end
|
91
108
|
end
|
data/lib/conekta/customer.rb
CHANGED
@@ -7,26 +7,77 @@ 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, :name, :email, :phone, :default_shipping_contact_id,
|
12
|
+
:default_fiscal_entity_id, :referrer, :account_age,
|
13
|
+
:paid_transactions, :first_paid_at, :corporate, :default_payment_source_id,
|
14
|
+
:fiscal_entities, :shipping_contacts, :subscription, :payment_sources, :cards
|
15
|
+
|
16
|
+
def initialize(id=nil)
|
17
|
+
@id = id
|
18
|
+
@payment_sources ||= List.new("PaymentSource", {})
|
19
|
+
@fiscal_entities ||= List.new("FiscalEntity", {})
|
20
|
+
@shipping_contacts ||= List.new("ShippingContacts", {})
|
21
|
+
super(id)
|
22
|
+
end
|
23
|
+
|
10
24
|
def load_from(response=nil)
|
11
25
|
if response
|
12
26
|
super
|
13
27
|
end
|
28
|
+
|
14
29
|
customer = self
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
30
|
+
|
31
|
+
if Conekta.api_version == "2.0.0"
|
32
|
+
submodels = [:fiscal_entities, :payment_sources, :shipping_contacts]
|
33
|
+
create_submodels_lists(customer, submodels)
|
34
|
+
else
|
35
|
+
submodels = [:cards]
|
36
|
+
|
37
|
+
submodels.each do |submodel|
|
38
|
+
self.send(submodel).each do |k,v|
|
39
|
+
if !v.respond_to? :deleted or !v.deleted
|
40
|
+
v.create_attr('customer', customer)
|
41
|
+
|
42
|
+
self.send(submodel).set_val(k,v)
|
43
|
+
end
|
44
|
+
end
|
19
45
|
end
|
20
46
|
end
|
47
|
+
|
21
48
|
if self.respond_to? :subscription and self.subscription
|
22
49
|
self.subscription.create_attr('customer', customer)
|
23
50
|
end
|
24
51
|
end
|
52
|
+
|
25
53
|
def create_card(params)
|
26
54
|
self.create_member('cards', params)
|
27
55
|
end
|
56
|
+
|
57
|
+
def create_payment_source(params)
|
58
|
+
self.create_member('payment_sources', params)
|
59
|
+
end
|
60
|
+
|
28
61
|
def create_subscription(params)
|
29
62
|
self.create_member('subscription', params)
|
30
63
|
end
|
64
|
+
|
65
|
+
def create_fiscal_entity(params)
|
66
|
+
self.create_member('fiscal_entities', params)
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_shipping_contact(params)
|
70
|
+
self.create_member('shipping_contacts', params)
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_submodels_lists(customer, submodels)
|
74
|
+
submodels.each do |submodel|
|
75
|
+
self.send(submodel).each do |k, v|
|
76
|
+
v.create_attr('customer', customer)
|
77
|
+
|
78
|
+
self.send(submodel).set_val(k,v)
|
79
|
+
end if self.respond_to?(submodel) && !self.send(submodel).nil?
|
80
|
+
end
|
81
|
+
end
|
31
82
|
end
|
32
83
|
end
|