epayco 0.0.2

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +13 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +10 -0
  7. data/.yardopts +6 -0
  8. data/Gemfile +18 -0
  9. data/README.md +258 -0
  10. data/Rakefile +11 -0
  11. data/epayco.gemspec +27 -0
  12. data/lib/epayco.rb +29 -0
  13. data/lib/epayco/api.rb +29 -0
  14. data/lib/epayco/client.rb +15 -0
  15. data/lib/epayco/client/charge.rb +36 -0
  16. data/lib/epayco/client/customer.rb +58 -0
  17. data/lib/epayco/client/plans.rb +115 -0
  18. data/lib/epayco/client/subscription.rb +150 -0
  19. data/lib/epayco/configuration.rb +74 -0
  20. data/lib/epayco/connection.rb +30 -0
  21. data/lib/epayco/error.rb +31 -0
  22. data/lib/epayco/request.rb +44 -0
  23. data/lib/epayco/response.rb +17 -0
  24. data/lib/epayco/version.rb +3 -0
  25. data/lib/faraday/raise_http_exception.rb +59 -0
  26. data/spec/epay_spec.rb +65 -0
  27. data/spec/epayco/client/charge_spec.rb +40 -0
  28. data/spec/epayco/client/customer_spec.rb +43 -0
  29. data/spec/epayco/client/plans_spec.rb +71 -0
  30. data/spec/epayco/client/subscription_spec.rb +68 -0
  31. data/spec/epayco/client_spec.rb +10 -0
  32. data/spec/fixtures/charge_create.json +10 -0
  33. data/spec/fixtures/customer_all.json +22 -0
  34. data/spec/fixtures/customer_create.json +10 -0
  35. data/spec/fixtures/plan_all.json +18 -0
  36. data/spec/fixtures/plan_create.json +9 -0
  37. data/spec/fixtures/plan_details.json +18 -0
  38. data/spec/fixtures/plan_update.json +9 -0
  39. data/spec/fixtures/subscription_all.json +52 -0
  40. data/spec/fixtures/subscription_cancel.json +8 -0
  41. data/spec/fixtures/subscription_create.json +22 -0
  42. data/spec/spec_helper.rb +74 -0
  43. metadata +177 -0
  44. metadata.gz.sig +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59c1d40737d331f1db43c7b2ebdcc5ae8425dc4d
4
+ data.tar.gz: 973e398e92b645039f094fc09d06102fe8e9108d
5
+ SHA512:
6
+ metadata.gz: 97fe3572f5af14e5ba2e85f29e3c442fe56a74f87d5829e44844b323dbedfd88b2c6c48be71ca8426e9363f1ae0c6678877f7c2f30e898f7dc61fbe7400274c4
7
+ data.tar.gz: cceabb52c2cf7cceadfff83e0ea61af12efed71bcaabc6587d23378167678dca72689e4c927d9bccfa6effe00bd89046c9b5a4f9361f7842775206b7c186e269
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ .bundle
3
+ vendor/bundle
4
+ .ruby-version
5
+ .rbenv-vars
6
+ spec/reports
7
+ Gemfile.lock
8
+ log/*
9
+ .yardoc
10
+ doc/*
11
+ certs/
12
+ coverage/
13
+ .todo
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,10 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+
4
+ before_install:
5
+ - rvm get head
6
+
7
+ rvm:
8
+ - 2.4.0
9
+ - 2.3.3
10
+ - 2.2.3
@@ -0,0 +1,6 @@
1
+ --no-private
2
+ --protected
3
+ --tag format:"Supported formats"
4
+ --markup markdown
5
+ -
6
+ README.md
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bundler', '~> 1.3'
4
+ gem 'rake'
5
+ gem 'yard'
6
+
7
+ group :development do
8
+ gem 'pry'
9
+ gem 'byebug'
10
+ end
11
+
12
+ group :test do
13
+ gem 'coveralls', require: false
14
+ gem 'rspec', '~> 3.0'
15
+ gem 'webmock'
16
+ end
17
+
18
+ gemspec
@@ -0,0 +1,258 @@
1
+ # EPayCo
2
+ A Gem to interact with [epayco.co](https://epayco.co/) API
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/epayco.png)](http://badge.fury.io/rb/epayco)
5
+ [![Code Climate](https://codeclimate.com/github/moisesnarvaez/epayco.png)](https://codeclimate.com/github/moisesnarvaez/epayco)
6
+ [![Dependency Status](https://gemnasium.com/moisesnarvaez/epayco.png)](https://gemnasium.com/moisesnarvaez/epayco)
7
+ [![Build Status](https://travis-ci.org/moisesnarvaez/epayco.png)](https://travis-ci.org/moisesnarvaez/epayco)
8
+
9
+ ## Installation
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'epayco'
13
+
14
+ And then execute:
15
+
16
+ bundle install
17
+
18
+ ## Configuration
19
+
20
+ Set the Api Keys:
21
+
22
+ Make sure to set `EPAYCO_PUBLIC_KEY` and `EPAYCO_PRIVATE_KEY` in your environement variables. You can get your API keys in your [configuration page](https://dashboard.epayco.co/clientes/configuracion).
23
+
24
+ ```ruby
25
+ EPayCo.public_key = ENV['EPAYCO_PUBLIC_KEY']
26
+ EPayCo.private_key = ENV['EPAYCO_PRIVATE_KEY']
27
+ ```
28
+
29
+ Multiple tokens or multithreaded usage:
30
+
31
+ ```ruby
32
+ settings = { public_key: ENV['EPAYCO_PUBLIC_KEY'], private_key: ENV['EPAYCO_PRIVATE_KEY'] }
33
+ epayco_client = EPayCo::Client.new(settings)
34
+ epayco_client.plan_all
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Plans
40
+
41
+ ```ruby
42
+ # Creating a Plan
43
+ plan_params = {
44
+ id_plan: "test",
45
+ name: "Test",
46
+ description: "Plan de prueba",
47
+ amount: 30,
48
+ currency: "USD",
49
+ interval: "year",
50
+ interval_count: 1,
51
+ trial_days: 0
52
+ }
53
+ response = EPayCo.plan_create(plan_params)
54
+ => {"status"=>"Creado", "user"=>"e54cd3e4f2a9d6be230cc50500cc69dc4672350", "id"=>"test"}
55
+
56
+ # Listing all Plans
57
+ plans = EPayCo.plan_all
58
+ => [{"id_plan"=>"test",
59
+ "object"=>"plan",
60
+ "name"=>"Test",
61
+ "description"=>"Plan de prueba",
62
+ "amount"=>30,
63
+ "currency"=>"usd",
64
+ "interval"=>"year",
65
+ "status"=>"active",
66
+ "trialDays"=>0,
67
+ "created"=>"19-02-2017"}]
68
+
69
+ # Udating a Plan
70
+ response = EPayCo.plan_update(plan_params)
71
+ => {"status"=>"Actualizado", "userId"=>"5c4773856f296c674685209bbfd11f92", "planId"=>"test"}
72
+ ```
73
+
74
+ ### Customers
75
+
76
+ ```ruby
77
+ # Creating a Customer
78
+ customer_params = {
79
+ token_card: "ZdTo2WFZEH9r3HC7N",
80
+ name: "Joe Doe",
81
+ email: "joe@payco.co",
82
+ phone: "3005234321",
83
+ default: true
84
+ }
85
+ response = EPayCo.customer_create(customer_params)
86
+ => {"status"=>"Creado",
87
+ "description"=>"El cliente ha sido creado con exito para realizar operaciones y enlazarlo use el id: q2u73ZB6eba49Po7h",
88
+ "customerId"=>"q2u73ZB6eba49Po7h",
89
+ "token"=>"F3HZdToH9r7N2WCZE"}
90
+
91
+ # Listing all Customers
92
+ customers = EPayCo.customer_all
93
+ => [{"id_customer"=>"PKEMb9wfxQjttGeP",
94
+ "object"=>"customer",
95
+ "name"=>"Juan Fernando",
96
+ "email"=>"cliente1@epayco.com",
97
+ "phone"=>"3333333",
98
+ "created"=>"21-10-2016"},
99
+ {"id_customer"=>"qRTGGssNKXZo2Q6pL",
100
+ "object"=>"customer",
101
+ "name"=>"Pedro Jaramillo",
102
+ "email"=>"cliente2@epayco.com",
103
+ "phone"=>"3333333",
104
+ "created"=>"21-10-2016"}]
105
+ ```
106
+
107
+ ### Subscription
108
+ ```ruby
109
+ # Creating a Subscription
110
+ subscription_params = {
111
+ id_plan: "cursocarpinteria",
112
+ customer: "6eba2u73ZBh49Po7q",
113
+ token_card: "ZdTo2WFZEH9r3HC7N"
114
+ }
115
+ response = EPayCo.subscription_create(subscription_params)
116
+ => {"success"=>true,
117
+ "object"=>"subscription",
118
+ "id"=>"wAzyX9Sutm3BaLxM2",
119
+ "created"=>"Sep 27, 2016 10:59 AM",
120
+ "current_period_start"=>"Sep 27, 2016 10:59 AM",
121
+ "current_period_end"=>"Nov 26, 2016 10:59 AM",
122
+ "customer"=>"6eba2u73ZBh49Po7q",
123
+ "message"=>"Suscripción creada",
124
+ "data"=>
125
+ {"id_plan"=>"cursocarpinteria2",
126
+ "name"=>"Curso de carpintería2",
127
+ "description"=>"En este curso aprenderás carpintería2",
128
+ "amount"=>30000,
129
+ "currency"=>"cop",
130
+ "interval"=>"month",
131
+ "status"=>"active",
132
+ "trialDays"=>30,
133
+ "createdAt"=>"Sep 27, 2016 10:59 AM"},
134
+ "status"=>"active"}
135
+
136
+ # Listing all Subscriptions
137
+ subscriptions = EPayCo.subscription_all
138
+ => [{"_id"=>"wAzyX9Sutm3BaLxM2",
139
+ "idPlan"=>"cursocarpinteria2",
140
+ "data"=>
141
+ {"_id"=>"LS5L9cRaJSWA4ykeM",
142
+ "idClient"=>"cursocarpinteria2",
143
+ "name"=>"Curso de carpintería2",
144
+ "description"=>"En este curso aprenderás carpintería2",
145
+ "amount"=>30000,
146
+ "currency"=>"cop",
147
+ "interval"=>"month",
148
+ "clientId"=>"5c4773856f296c674685209bbfd11f92",
149
+ "status"=>"active",
150
+ "trialDays"=>30,
151
+ "createdAt"=>"2016-09-27T15:29:38.772Z"},
152
+ "periodStart"=>"2016-09-27T15:59:46.339Z",
153
+ "periodEnd"=>"2016-11-26T15:59:46.339Z",
154
+ "status"=>"active",
155
+ "idUser"=>"5c4773856f296c674685209bbfd11f92",
156
+ "idCustomer"=>"6eba2u73ZBh49Po7q",
157
+ "createdAt"=>"2016-09-27T15:59:46.352Z"}]
158
+
159
+ # Getting a Subscription Details
160
+ subscription = EPayCo.subscription_details
161
+ => {"success"=>true,
162
+ "object"=>"subscription",
163
+ "id"=>"wAzyX9Sutm3BaLxM2",
164
+ "created"=>"Sep 27, 2016 10:59 AM",
165
+ "current_period_start"=>"Sep 27, 2016 10:59 AM",
166
+ "current_period_end"=>"Nov 26, 2016 10:59 AM",
167
+ "customer"=>"6eba2u73ZBh49Po7q",
168
+ "message"=>"Suscripción creada",
169
+ "data"=>
170
+ {"id_plan"=>"cursocarpinteria2",
171
+ "name"=>"Curso de carpintería2",
172
+ "description"=>"En este curso aprenderás carpintería2",
173
+ "amount"=>30000,
174
+ "currency"=>"cop",
175
+ "interval"=>"month",
176
+ "status"=>"active",
177
+ "trialDays"=>30,
178
+ "createdAt"=>"Sep 27, 2016 10:59 AM"},
179
+ "status"=>"active"}
180
+
181
+ # Canceling a Subscription Details
182
+ subscription_id = "wAzyX9Sutm3BaLxM2"
183
+ response = EPayCo.subscription_cancel(subscription_id)
184
+ => {"status"=>"Actualizado", "description"=>"La suscripción ha sido inhabilidata para el usuario wAzyX9Sutm3BaLxM2"}
185
+ ```
186
+
187
+ ### Charge
188
+
189
+ ```ruby
190
+ # Creating a Charge
191
+ charge_params = {
192
+ token_card: "hMsDAjwD7KLsgZQ54",
193
+ customer_id: "6eba2u73ZBh49Po7q",
194
+ plan_id: "cursocarpinteria",
195
+ doc_type: "CC",
196
+ doc_number: "1035851980",
197
+ name: "John",
198
+ last_name: "Doe",
199
+ email: "example@email.com",
200
+ ip: "192.198.2.114",
201
+ bill: "OR-1234",
202
+ description: "Test Payment",
203
+ value: "116000",
204
+ tax: "16000",
205
+ tax_base: "100000",
206
+ currency: "COP",
207
+ dues: "12"
208
+ }
209
+ response = EPayCo.charge_create(charge_params)
210
+ => {"status"=>"Creado", "description"=>"El charge ha sido creado con exito", "customerId"=>"6eba2u73ZBh49Po7q", "token"=>"ZdTo2WFZEH9r3HC7N"}
211
+ ```
212
+
213
+ ## Contributing
214
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
215
+
216
+ Here are some ways *you* can contribute:
217
+
218
+ * by using alpha, beta, and prerelease versions
219
+ * by reporting bugs
220
+ * by suggesting new features
221
+ * by writing or editing documentation
222
+ * by writing specifications
223
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
224
+ * by refactoring code
225
+ * by closing [issues](http://github.com/Instagram/instagram-ruby-gem/issues)
226
+ * by reviewing patches
227
+
228
+
229
+ ## Submitting a Pull Request
230
+
231
+ 1. Fork it
232
+ 2. [Create a topic branch](http://learn.github.com/p/branching.html)
233
+ 3. Implement your feature or bug fix.
234
+ 4. Add documentation for your feature or bug fix.
235
+ 5. Run rake `doc:yard`. If your changes are not 100% documented, go back to step 4.
236
+ 6. Add specs for your feature or bug fix.
237
+ 7. Run `bundle exec rspec`. If your changes are not 100% covered, go back to step 6.
238
+ 8. Commit your changes and push
239
+ 9. [Submit a pull request](http://help.github.com/send-pull-requests/). Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
240
+
241
+ ## Inspiration
242
+ * [Mercury Parser Gem](https://github.com/moisesnarvaez/mercury_parser)
243
+ * [The Instagram Ruby Gem](https://github.com/facebookarchive/instagram-ruby-gem)
244
+
245
+ ## Author
246
+ [Moises Narvaez](http://www.moisesnarvaez.com)
247
+
248
+ ## Copyright
249
+ Copyright (c) 2017 Moises Narvaez
250
+
251
+ ## License
252
+ MIT License
253
+
254
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
255
+
256
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
257
+
258
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :spec
7
+
8
+ desc 'Run all specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |task|
10
+ task.pattern = 'spec/**/*_spec.rb'
11
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/epayco/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'epayco'
6
+ s.version = EPayCo::VERSION
7
+ s.date = '2017-02-17'
8
+ s.summary = "%q{A Gem to interact with epayco.co API}"
9
+ s.description = "%q{The EPayCo Gem provides methods to create, process and manage payment.}"
10
+ s.authors = ["Moises Narvaez"]
11
+ s.email = 'MoisesNarvaez@gmail.com'
12
+ s.homepage = 'https://github.com/moisesnarvaez/epayco'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.cert_chain = ['certs/gem-public_cert.pem']
21
+ s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
22
+
23
+ s.add_runtime_dependency('faraday', '~> 0.11.0')
24
+ s.add_runtime_dependency('faraday_middleware', '~> 0.11.0.1')
25
+ s.add_runtime_dependency('multi_json', '~> 1.12')
26
+ s.add_runtime_dependency('hashie', '~> 3.5')
27
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../epayco/error', __FILE__)
2
+ require File.expand_path('../epayco/configuration', __FILE__)
3
+ require File.expand_path('../epayco/api', __FILE__)
4
+ require File.expand_path('../epayco/client', __FILE__)
5
+ require File.expand_path('../epayco/response', __FILE__)
6
+
7
+ module EPayCo
8
+ extend Configuration
9
+
10
+ class << self
11
+ # Alias for EPayCo::Client.new
12
+ #
13
+ # @return [EPayCo::Client]
14
+ def client(options={})
15
+ EPayCo::Client.new(options)
16
+ end
17
+
18
+ # Delegate to EPayCo::Client
19
+ def method_missing(method, *args, &block)
20
+ return super unless client.respond_to?(method)
21
+ client.send(method, *args, &block)
22
+ end
23
+
24
+ # Delegate to EPayCo::Client
25
+ def respond_to?(method, include_all=false)
26
+ return client.respond_to?(method, include_all) || super
27
+ end
28
+ end
29
+ end # EPayCo
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+
4
+ module EPayCo
5
+ # @private
6
+ class API
7
+ # @private
8
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
9
+
10
+ # Creates a new API
11
+ def initialize(options={})
12
+ options = EPayCo.options.merge(options)
13
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
15
+ end
16
+ end
17
+
18
+ def config
19
+ conf = {}
20
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
21
+ conf[key] = send key
22
+ end
23
+ conf
24
+ end
25
+
26
+ include Connection
27
+ include Request
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../api', __FILE__)
2
+
3
+ module EPayCo
4
+ # Wrapper for the EPayCo REST API
5
+ #
6
+ # @note All methods have been separated into modules
7
+ class Client < API
8
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
9
+
10
+ include EPayCo::Client::Plans
11
+ include EPayCo::Client::Subscription
12
+ include EPayCo::Client::Customer
13
+ include EPayCo::Client::Charge
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module EPayCo
2
+ class Client
3
+ # Defines methods related to Charges
4
+ module Charge
5
+
6
+ # Creates a new charge
7
+ #
8
+ # @format :json
9
+ # @param options The Charge Attributes
10
+ # @option options [String] :token_card Token de la tarjeta tokenizada
11
+ # @option options [String] :customer_id Id del usuario al que se asocio la tarjeta
12
+ # @option options [String] :plan_id Id del plan si se quiere agregar agregar una suscripción
13
+ # @option options [String] :doc_type Tipo de documento del cliente
14
+ # @option options [String] :doc_number Número de cocumento del cliente
15
+ # @option options [String] :name Nombre del cliente que realiza el pago
16
+ # @option options [String] :last_name Apellidos del usuario que realiza el pago
17
+ # @option options [String] :email Email del usuario que realiza el pago
18
+ # @option options [String] :ip Ip del cliente al momento de la transacción
19
+ # @option options [String] :bill Número de factura de la compra
20
+ # @option options [String] :description Descripción de la compra que hace el usuario
21
+ # @option options [String] :value Valor total a pagar del producto o servicio
22
+ # @option options [String] :tax Impuesto que se cobra sobre el valor total
23
+ # @option options [String] :tax_base Base del valor total con el impuesto discriminado
24
+ # @option options [String] :currency Moneda en la que se ejecuta la transacción
25
+ # @option options [String] :dues Cantidad de cuotas que se difiere el pago
26
+ # @return [Hashie::Mash]
27
+ # @example Success
28
+ #
29
+ def charge_create(options={})
30
+ path = "/recurring/v1/charge/create"
31
+ response_options = { return_object: 'data' }
32
+ post(path, options.merge(public_key: public_key), response_options)
33
+ end
34
+ end
35
+ end
36
+ end