conekta-tiempometa 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +124 -0
  5. data/Dockerfile +44 -0
  6. data/Gemfile +13 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +182 -0
  9. data/Rakefile +1 -0
  10. data/conekta.gemspec +29 -0
  11. data/lib/conekta/address.rb +5 -0
  12. data/lib/conekta/card.rb +21 -0
  13. data/lib/conekta/charge.rb +25 -0
  14. data/lib/conekta/conekta_object.rb +109 -0
  15. data/lib/conekta/customer.rb +82 -0
  16. data/lib/conekta/customer_info.rb +5 -0
  17. data/lib/conekta/destination.rb +17 -0
  18. data/lib/conekta/details.rb +5 -0
  19. data/lib/conekta/discount_line.rb +19 -0
  20. data/lib/conekta/error.rb +99 -0
  21. data/lib/conekta/error_details.rb +14 -0
  22. data/lib/conekta/event.rb +9 -0
  23. data/lib/conekta/line_item.rb +21 -0
  24. data/lib/conekta/list.rb +59 -0
  25. data/lib/conekta/log.rb +10 -0
  26. data/lib/conekta/method.rb +4 -0
  27. data/lib/conekta/operations/create.rb +19 -0
  28. data/lib/conekta/operations/create_member.rb +40 -0
  29. data/lib/conekta/operations/custom_action.rb +13 -0
  30. data/lib/conekta/operations/delete.rb +45 -0
  31. data/lib/conekta/operations/find.rb +21 -0
  32. data/lib/conekta/operations/update.rb +11 -0
  33. data/lib/conekta/operations/where.rb +30 -0
  34. data/lib/conekta/order.rb +87 -0
  35. data/lib/conekta/payee.rb +66 -0
  36. data/lib/conekta/payment_method.rb +4 -0
  37. data/lib/conekta/payment_source.rb +17 -0
  38. data/lib/conekta/payout.rb +7 -0
  39. data/lib/conekta/payout_method.rb +17 -0
  40. data/lib/conekta/plan.rb +16 -0
  41. data/lib/conekta/refund.rb +6 -0
  42. data/lib/conekta/requestor.rb +80 -0
  43. data/lib/conekta/resource.rb +54 -0
  44. data/lib/conekta/return.rb +12 -0
  45. data/lib/conekta/shipping_contact.rb +19 -0
  46. data/lib/conekta/shipping_line.rb +20 -0
  47. data/lib/conekta/subscription.rb +25 -0
  48. data/lib/conekta/tax_line.rb +19 -0
  49. data/lib/conekta/token.rb +8 -0
  50. data/lib/conekta/transfer.rb +7 -0
  51. data/lib/conekta/util.rb +136 -0
  52. data/lib/conekta/version.rb +3 -0
  53. data/lib/conekta/webhook.rb +12 -0
  54. data/lib/conekta/webhook_log.rb +4 -0
  55. data/lib/conekta.rb +101 -0
  56. data/lib/ssl_data/ca_bundle.crt +3955 -0
  57. data/locales/en.yml +9 -0
  58. data/locales/es.yml +10 -0
  59. data/readme_files/banner.png +0 -0
  60. data/readme_files/conekta-badge.png +0 -0
  61. data/readme_files/ruby-badge.png +0 -0
  62. data/spec/conekta/1.0.0/.DS_Store +0 -0
  63. data/spec/conekta/1.0.0/card_spec.rb +40 -0
  64. data/spec/conekta/1.0.0/charge_spec.rb +152 -0
  65. data/spec/conekta/1.0.0/customer_spec.rb +147 -0
  66. data/spec/conekta/1.0.0/error_spec.rb +69 -0
  67. data/spec/conekta/1.0.0/event_spec.rb +26 -0
  68. data/spec/conekta/1.0.0/log_spec.rb +20 -0
  69. data/spec/conekta/1.0.0/payout_spec.rb +60 -0
  70. data/spec/conekta/1.0.0/plan_spec.rb +53 -0
  71. data/spec/conekta/1.0.0/token_spec.rb +5 -0
  72. data/spec/conekta/1.0.0/webhook_spec.rb +36 -0
  73. data/spec/conekta/2.0.0/customer_spec.rb +77 -0
  74. data/spec/conekta/2.0.0/discount_line_spec.rb +49 -0
  75. data/spec/conekta/2.0.0/error_spec.rb +61 -0
  76. data/spec/conekta/2.0.0/line_item_spec.rb +53 -0
  77. data/spec/conekta/2.0.0/list_spec.rb +29 -0
  78. data/spec/conekta/2.0.0/order_spec.rb +291 -0
  79. data/spec/conekta/2.0.0/payee_spec.rb +55 -0
  80. data/spec/conekta/2.0.0/shipping_contact_spec.rb +60 -0
  81. data/spec/conekta/2.0.0/shipping_line_spec.rb +53 -0
  82. data/spec/conekta/2.0.0/source_spec.rb +31 -0
  83. data/spec/conekta/2.0.0/tax_line_spec.rb +44 -0
  84. data/spec/conekta/2.0.0/transfer_spec.rb +59 -0
  85. data/spec/conekta_spec.rb +29 -0
  86. data/spec/spec_helper.rb +14 -0
  87. data/spec/support/fixtures/orders.json +1127 -0
  88. data/spec/support/shared_context.rb +49 -0
  89. metadata +229 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35634e2f8b3436bac1efbb536d41b4d769b81ce7
4
+ data.tar.gz: 153cdaa2480fd09d3f028ca43dacede5cdfd3901
5
+ SHA512:
6
+ metadata.gz: 3b12a8aefed9daea1b825edd741659d4dc895bde84af71f80b0ca3eb00ffa4003c35158281bc846ffe4f01046ab1bf92947ccd7d7ed1425445d9774ccea222bd
7
+ data.tar.gz: c072e9d8d2854ec01f9f7260a627629e97a3914c1b2e6c2731b65c7517fa0f44fdbecf9615d96cd6f14f4c7f10defb5ab32f604e3730d29c17dcadc0c4ce10f4
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ .byebug_history
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ bin/
21
+ tags
22
+ *.swp
23
+ *.un~
24
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG.md ADDED
@@ -0,0 +1,124 @@
1
+ ## [2.4.0](https://github.com/conekta/conekta-ruby/releases/tag/2.4.0) - 2017-10-05
2
+ ### Added oxxo recurrent support
3
+ - Added new method create_offline_recurrent_reference.
4
+
5
+ ## [2.3.0](https://github.com/conekta/conekta-ruby/releases/tag/2.3.0) - 2017-10-05
6
+ ### Fix
7
+ - Capture allow pass amount in api v1
8
+
9
+ ## [2.2.0](https://github.com/conekta/conekta-ruby/releases/tag/2.2.0) - 2017-10-05
10
+ ### Fix
11
+ - Payee module implementation for api 2
12
+
13
+ ## [2.1.0](https://github.com/conekta/conekta-ruby/releases/tag/2.1.0) - 2017-10-05
14
+ ### Change
15
+ - Error list refactor and byebug implementation
16
+
17
+ ## [2.0.1](https://github.com/conekta/conekta-ruby/releases/tag/2.0.1) - 2017-02-15
18
+ ### Feature
19
+ - Order model, submodels and methods as well as enhanced Errors and lists
20
+
21
+ ## [2.0.0](https://github.com/conekta/conekta-ruby/releases/tag/2.0.0) - 2017-02-13
22
+ ### Update
23
+ - Update vertical info to antifraud info
24
+
25
+ ## [1.1.3]() - 2017-02-08
26
+ ### Change
27
+ - Change vertical_info to antifraud_info
28
+
29
+ ## [1.1.2]() - 2017-02-08
30
+ ### Change
31
+ - Avoid class name conflicts
32
+
33
+ ## [1.1.1](https://github.com/conekta/conekta-ruby/releases/tag/1.1.1) - 2017-02-01
34
+ ### Fix
35
+ - Fix submodels updates
36
+
37
+ ## [1.1.0]() - 2017-01-24
38
+ ### Update
39
+ - Version bump
40
+
41
+ ## [1.0.0]() - 2017-01-24
42
+ ###
43
+ - Add support for API 2.0.0
44
+
45
+ ## [0.5.8]() - 2016-07-19
46
+ ### Feature
47
+ - Add new models for parsing
48
+
49
+ ## [0.5.7]() - 2016-07-19
50
+ ### Fix
51
+ - Fix parameter handling for get requests
52
+
53
+ ## [0.5.6]() - 2015-12-29
54
+ ### Change
55
+ - Change parameter serialization using request body instead of connection params
56
+
57
+ ## [0.5.5]() - 2015-12-01
58
+ ### Feature
59
+ - Add find method to Event class
60
+
61
+ ## [0.5.4]() - 2015-09-08
62
+ ### Feature
63
+ - Update ConektaObject with the attribute 'values'
64
+
65
+ ## [0.5.3]() - 2015-08-13
66
+ ### Change
67
+ - Refactorization
68
+
69
+ ## [0.5.2](https://github.com/conekta/conekta-ruby/releases/tag/v0.5.2) - 2015-02-13
70
+ ### Change
71
+ - Change rspec dependency to development
72
+
73
+ ## [0.5.0]() - 2015-01-20
74
+ ### Feature
75
+ - Add Webhook module
76
+
77
+ ## [0.4.9]() - 2014-07-08
78
+ ### Change
79
+ - Update API version to 1.0.0
80
+
81
+ ## [0.4.6](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.6) - 2014-07-08
82
+ ### Feature
83
+ - Add message_to_purchaser internal errors
84
+
85
+ ## [0.4.5](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.5) - 2014-07-08
86
+ ### Feature
87
+ - Sprinkling small Ruby style conventions here and there (antillas21)
88
+
89
+ ## [0.4.4](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.4) - 2014-06-04
90
+ ### Fix
91
+ - Fix requestor and where method
92
+
93
+ ## [0.4.3](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.3) - 2014-05-25
94
+ ### Feature
95
+ - Add locale and message_to_purchaser
96
+
97
+ ## [0.4.2]() - 2014-04-28
98
+ ### Fix
99
+ - Fix Payout specs
100
+
101
+ ## [0.4.1](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.1) - 2014-04-16
102
+ ### Remove
103
+ - Remove active support and add custom methods in util file
104
+
105
+ ## [0.4.0](https://github.com/conekta/conekta-ruby/releases/tag/v0.4.0) - 2014-04-16
106
+ ### Feature
107
+ - Add payout and payee models with specs
108
+ - Add webhook logs for events
109
+ - Ameliorate convert_to_conekta_object logic
110
+
111
+ ## [0.3.7](https://github.com/conekta/conekta-ruby/releases/tag/v0.3.7) - 2013-01-27
112
+ ### Feature
113
+ - Added api_version setter
114
+
115
+ ## [0.3.6](https://github.com/conekta/conekta-ruby/releases/tag/v0.3.6) - 2013-01-17
116
+ ### Fix
117
+ - Fix cert path
118
+
119
+ ## [0.3.5]() - 2013-01-13
120
+ ### Deprecate
121
+ - Deprecate retrieve and all methods and replaced them with find and where respectively
122
+ ### Feature
123
+ - Add payment method model
124
+ - Objects' properties are now accessible via methods of the same of name
data/Dockerfile ADDED
@@ -0,0 +1,44 @@
1
+ FROM ubuntu:14.04
2
+
3
+ MAINTAINER Leo Fischer
4
+
5
+ RUN apt-get update
6
+ RUN apt-get install -y vim git wget curl
7
+
8
+ #setup test_user user
9
+ RUN useradd -ms /bin/bash test_user
10
+ RUN echo "test_user:sudo" | chpasswd
11
+ RUN usermod -aG sudo test_user
12
+ RUN mkdir -p /data/db/
13
+ RUN chown test_user /data/db
14
+ RUN sudo echo "test_user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
15
+
16
+ USER test_user
17
+ ENV HOME /home/test_user
18
+
19
+ RUN echo "set tabstop=2" >> ~/.vimrc
20
+ RUN echo "set shiftwidth=2" >> ~/.vimrc
21
+ RUN echo "set softtabstop=2" >> ~/.vimrc
22
+
23
+ #install RVM and Ruby
24
+ RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
25
+ RUN \curl -sSL https://get.rvm.io | sudo bash -s stable
26
+ RUN sudo usermod -a -G rvm test_user
27
+ RUN /bin/bash -l -c "rvm requirements"
28
+ RUN /bin/bash -l -c "rvm install 1.9.3"
29
+ RUN /bin/bash -l -c "rvm install 2.1.9"
30
+ RUN /bin/bash -l -c "rvm install 2.2.4"
31
+ RUN /bin/bash -l -c "rvm install 2.3.0"
32
+
33
+ #configure external fs links
34
+ WORKDIR $HOME
35
+
36
+ #One Time Staging Steps
37
+ RUN git clone https://github.com/conekta/conekta-ruby
38
+
39
+ WORKDIR $HOME/conekta-ruby
40
+
41
+ RUN /bin/bash -l -c "rvm use 1.9.3 && gem install bundle && bundle install"
42
+ RUN /bin/bash -l -c "rvm use 2.1.9 && gem install bundle && bundle install"
43
+ RUN /bin/bash -l -c "rvm use 2.2.4 && gem install bundle && bundle install"
44
+ RUN /bin/bash -l -c "rvm use 2.3.0 && gem install bundle && bundle install"
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+ gem 'sys-uname'
3
+ gem 'rspec'
4
+ gem 'faraday'
5
+ gem 'json'
6
+ gem 'i18n'
7
+
8
+ group :development, :test do
9
+ gem 'byebug'
10
+ end
11
+
12
+ # Specify your gem's dependencies in conekta.gemspec
13
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014 - Conekta, Inc. (https://www.conekta.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,182 @@
1
+ <div align="center">
2
+
3
+ ![banner](readme_files/banner.png)
4
+
5
+ # Conekta Ruby v.2.4.0
6
+
7
+ ![ruby badge](readme_files/ruby-badge.png)
8
+ ![conekta badge](readme_files/conekta-badge.png)
9
+
10
+ </div>
11
+
12
+ This is a [Ruby](https://www.ruby-lang.org/) library that allows interaction with [Conekta's API](https://api.conekta.io).
13
+
14
+ ## Requeriments
15
+
16
+ Add them!
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'conekta'
23
+
24
+ And then execute:
25
+
26
+ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ gem install conekta
31
+
32
+ ## Usage
33
+ ```ruby
34
+ # Set your configuration variables
35
+
36
+ # This changes the Accept-Language Header to the locale specified
37
+ Conekta.locale = :es
38
+
39
+ Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
40
+
41
+ # Or via an initializer in config/initializers/conekta.rb
42
+ Conekta.config do |c|
43
+ c.locale = :es
44
+ c.api_key = '1tv5yJp3xnVZ7eK67m4h'
45
+ c.api_version = '2.0.0'
46
+ end
47
+
48
+ begin
49
+ order = Conekta::Order.create(order_data_with_charges.
50
+ merge(customer_info: customer_info))
51
+ rescue Conekta::Error => error
52
+ for error_detail in error.details do
53
+ puts error_detail.message
54
+ end
55
+ 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
+ ```
114
+
115
+ ## Documentation
116
+
117
+ Please visit the [official API reference](https://developers.conekta.com/api) for an up-to-date documentation.
118
+
119
+ Development and Testing
120
+ -----------------------
121
+ Feel free to play with our library and make pull requests if you find any bugs.
122
+ You can run the test suite with [rspec](https://github.com/rspec/rspec-rails) from the library's root directory:
123
+
124
+ ```shell
125
+ bundle exec rspec
126
+ ```
127
+
128
+ To facilitate the development and testing process you can use one of our Docker containers that come with [RVM](https://github.com/rvm/rvm) and [Ruby](https://www.ruby-lang.org/) versions 1.9.3, 2.1.9, 2.2.4 and 2.3.0:
129
+
130
+ ```shell
131
+ docker pull conekta/conekta-ruby
132
+
133
+ docker run -ti conekta/conekta-ruby /bin/bash --login
134
+ ```
135
+
136
+ ***
137
+
138
+ ## How to contribute to the project
139
+
140
+ 1. Fork the repository
141
+
142
+ 2. Clone the repository
143
+ ```
144
+ git clone git@github.com:yourUserName/conekta-ruby.git
145
+ ```
146
+ 3. Create a branch
147
+ ```
148
+ git checkout develop
149
+ git pull origin develop
150
+ # You should choose the name of your branch
151
+ git checkout -b <feature/my_branch>
152
+ ```
153
+ 4. Make necessary changes and commit those changes
154
+ ```
155
+ git add .
156
+ git commit -m "my changes"
157
+ ```
158
+ 5. Push changes to GitHub
159
+ ```
160
+ git push origin <feature/my_branch>
161
+ ```
162
+ 6. Submit your changes for review, create a pull request
163
+
164
+ To create a pull request, you need to have made your code changes on a separate branch. This branch should be named like this: **feature/my_feature** or **fix/my_fix**.
165
+
166
+ Make sure that, if you add new features to our library, be sure that corresponding **unit tests** are added.
167
+
168
+ If you go to your repository on GitHub, you’ll see a Compare & pull request button. Click on that button.
169
+
170
+ ***
171
+
172
+ ## We are always hiring!
173
+
174
+ If you are a comfortable working with a range of backend languages (Java, Python, Ruby, PHP, etc) and frameworks, you have solid foundation in data structures, algorithms and software design with strong analytical and debugging skills, check our open positions: https://www.conekta.com/careers
175
+
176
+ ### License
177
+
178
+ <div align="center">
179
+
180
+ Developed in :mexico: Mexico by [Conekta](https://www.conekta.com). Available with [MIT License](LICENSE).
181
+
182
+ </div>
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/conekta.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'conekta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "conekta-tiempometa"
8
+ spec.version = Conekta::VERSION
9
+ spec.authors = ["Conekta"]
10
+ spec.email = ["soporte@conekta.com"]
11
+ spec.description = %q{Ruby library for https://api.conekta.io}
12
+ spec.summary = %q{This library provides https://api.conekta.io operations}
13
+ spec.homepage = "https://www.conekta.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "bundler", ">= 1.3"
22
+ spec.add_dependency "rake"
23
+ spec.add_dependency "faraday"
24
+ spec.add_dependency "json"
25
+ spec.add_dependency "sys-uname"
26
+
27
+ spec.add_development_dependency "rspec", ">= 3.0"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,5 @@
1
+ module Conekta
2
+ class Address < Resource
3
+ attr_accessor :street1, :street2, :street3, :city, :state, :zip, :country
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Conekta
2
+ class Card < Resource
3
+ include Conekta::Operations::Delete
4
+ include Conekta::Operations::Update
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
+
11
+ def _url
12
+ ensure_id
13
+
14
+ self.customer._url + self.class._url + "/" + id
15
+ end
16
+
17
+ def delete
18
+ self.delete_member('customer','cards')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Conekta
2
+ class Charge < Resource
3
+ include Conekta::Operations::Find
4
+ include Conekta::Operations::Where
5
+ include Conekta::Operations::Create
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
+
14
+ # Usage: charge_reference.capture(2000)
15
+ def capture(capture_amount=nil)
16
+ params = { 'amount' => (capture_amount || self.amount) }
17
+ custom_action(:post, 'capture', params)
18
+ end
19
+
20
+ def refund(params=nil)
21
+ params = { 'amount' => (params || self.amount) }
22
+ custom_action(:post, 'refund', params)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,109 @@
1
+ module Conekta
2
+ class ConektaObject < Hash
3
+ attr_reader :values
4
+
5
+ def initialize
6
+ @values = Hash.new
7
+ end
8
+
9
+ def set_val(k,v)
10
+ @values ||= {}
11
+ @values[k] = v
12
+ self[k] = v
13
+ end
14
+
15
+ def unset_key(k)
16
+ @values.delete(k)
17
+ self.delete(k)
18
+ end
19
+
20
+ def first
21
+ self[0]
22
+ end
23
+
24
+ def last
25
+ self[self.keys.last]
26
+ end
27
+
28
+ def load_from(response)
29
+ if response.instance_of?(Array)
30
+ response.each_with_index do |v, i|
31
+ load_from_enumerable(i,v)
32
+ end
33
+ elsif response.kind_of?(Hash)
34
+ response = response.to_hash if response.class != Hash
35
+ response.each do |k,v|
36
+ load_from_enumerable(k,v)
37
+ end
38
+ end
39
+ end
40
+
41
+ def to_s
42
+ @values.inspect
43
+ end
44
+
45
+ def inspect
46
+ if self.respond_to? :each
47
+ if self.class.class_name != "ConektaObject"
48
+ self.to_s
49
+ else
50
+ self.to_a.map{|x| x[1] }
51
+ end
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ def self.class_name
58
+ self.name.split('::')[-1]
59
+ end
60
+
61
+ def class_name
62
+ self.class.name.split('::')[-1]
63
+ end
64
+
65
+ def create_attr(k,v)
66
+ # Conflict with Resource Class Url
67
+ k = "_#{k}" if k.to_s == "method"
68
+
69
+ if ! k.to_s.match(/-/) and ! k.to_s.match(/^[0-9]+/)
70
+ create_method( "#{k}=".to_sym ) { |val|
71
+ instance_variable_set( "@" + k, val)
72
+ }
73
+ self.send("#{k}=".to_sym, v)
74
+ self.class.send(:remove_method, "#{k}=".to_sym)
75
+ create_method( k.to_sym ) {
76
+ instance_variable_get( "@" + k )
77
+ }
78
+ end
79
+ end
80
+
81
+ protected
82
+
83
+ def to_hash
84
+ hash = Hash.new
85
+ self.values.each do |k,v|
86
+ hash[k] = v
87
+ end
88
+ hash
89
+ end
90
+
91
+ def create_method(name, &block)
92
+ self.class.send(:define_method, name, &block)
93
+ end
94
+
95
+ def load_from_enumerable(k,v)
96
+ if v.respond_to? :each and !v.instance_of?(ConektaObject)
97
+ v = Conekta::Util.convert_to_conekta_object(k,v)
98
+ end
99
+
100
+ if self.instance_of?(ConektaObject)
101
+ self[k] = v
102
+ else
103
+ self.create_attr(k,v)
104
+ end
105
+ self.set_val(k,v)
106
+ end
107
+
108
+ end
109
+ end