conekticut 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +112 -0
- data/Rakefile +1 -0
- data/conekticut.gemspec +29 -0
- data/lib/conekticut/client/configuration.rb +53 -0
- data/lib/conekticut/client/payment.rb +45 -0
- data/lib/conekticut/client/request_handler.rb +28 -0
- data/lib/conekticut/client.rb +12 -0
- data/lib/conekticut/sslcert.rb +14 -0
- data/lib/conekticut/version.rb +3 -0
- data/lib/conekticut.rb +21 -0
- data/spec/client/configuration_spec.rb +52 -0
- data/spec/client/payment_spec.rb +96 -0
- data/spec/client/request_handler_spec.rb +76 -0
- data/spec/client/request_spec.rb +4 -0
- data/spec/client/sslcert_spec.rb +25 -0
- data/spec/factories/ssl_cert.crt +27 -0
- data/spec/spec_helper.rb +21 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 696b1f1c94c9cbe238d7905b8086d2ca34f4a225
|
4
|
+
data.tar.gz: 3741322ac6c34522bfb2499efc30072644734f7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5166ccbbdcad3e427b9ecb2d5d8b9176dea9982e5bed5d623e00b9cb5779f3388e2f392873954ac785066bb6a7b175e04e99b78f7e53f0a6d60779eca7b75c2
|
7
|
+
data.tar.gz: 273b93b8b914a7254034b491e3948c9c5dc2a46eb370b2c80d7fad8c00d796076501c5dd0547c77405a39b940d4712c5288dfb76567d6fae18522006efa55dd1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ian Rodriguez
|
2
|
+
|
3
|
+
MIT License
|
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,112 @@
|
|
1
|
+
# Conekticut
|
2
|
+
|
3
|
+
This gem provides a simple yet extremely flexible way to interact with the [Conekta API](https://www.conekta.io/docs/api)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'conekticut'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install conekticut
|
18
|
+
|
19
|
+
## Configuring Conekticut
|
20
|
+
|
21
|
+
Conekticut can be configured in a rails initializer like so:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Conekticut.configure do |c|
|
25
|
+
c.public_key = "<your_conekta_public_api_key>"
|
26
|
+
c.private_key = "<your_conekta_public_api_key>"
|
27
|
+
c.use_ssl = true
|
28
|
+
c.ssl_cert_path = "<your_ssl_cert_path>"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
> If using rails you can dump this in a `conekticut.rb` initializer.
|
33
|
+
|
34
|
+
## Creating payments
|
35
|
+
|
36
|
+
The `create` method takes a hash with one of the following structures:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
payment_info_cc = {
|
40
|
+
"currency"=>"MXN",
|
41
|
+
"amount"=> 20000, #the amount should be specified in cents
|
42
|
+
"description"=>"Some Description",
|
43
|
+
"reference_id"=>"A transaction reference",
|
44
|
+
"card"=> {
|
45
|
+
"number"=> 4111111111111111,
|
46
|
+
"name"=>"Card owner",
|
47
|
+
"exp_month"=> 12,
|
48
|
+
"exp_year"=> 2015,
|
49
|
+
"cvc"=> 666, #Security code
|
50
|
+
"address"=> {
|
51
|
+
"street1"=>"Some street",
|
52
|
+
"city"=>"Some City",
|
53
|
+
"state"=>"Some State",
|
54
|
+
"country"=>"Some Country",
|
55
|
+
"zip"=>"Some ZIP :P"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
payment_info_oxxo = {
|
61
|
+
"currency"=>"MXN",
|
62
|
+
"amount"=> 20000, #the amount should be specified in cents
|
63
|
+
"description"=>"Some Description",
|
64
|
+
"reference_id"=>"A transaction reference",
|
65
|
+
"cash"=> {
|
66
|
+
"type"=>"oxxo"
|
67
|
+
},
|
68
|
+
"details"=> {
|
69
|
+
"name"=>"Some name",
|
70
|
+
"email"=>"Some email",
|
71
|
+
"phone"=>"Some phone number"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
payment_info_banc = {
|
76
|
+
"currency"=>"MXN",
|
77
|
+
"amount"=>20000,
|
78
|
+
"description"=>"Some description",
|
79
|
+
"reference_id"=>"A transaction reference",
|
80
|
+
"bank"=> {
|
81
|
+
"type"=>"banorte"
|
82
|
+
},
|
83
|
+
"details"=> {
|
84
|
+
"name"=>"Some name",
|
85
|
+
"email"=>"Some email",
|
86
|
+
"phone"=>"Some phone number"
|
87
|
+
}
|
88
|
+
}
|
89
|
+
```
|
90
|
+
|
91
|
+
After you have your payment info you can call:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
Conekticut::Payment.create("/charges", payment_info_cc)
|
95
|
+
```
|
96
|
+
|
97
|
+
This method will return a hash which is the representation of the JSON the API returns, use the info as you see fit.
|
98
|
+
|
99
|
+
## TODO
|
100
|
+
|
101
|
+
1. Support for returning payments
|
102
|
+
2. Support for canceling payments
|
103
|
+
3. Support for consulting your history
|
104
|
+
4. Better error handling
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
1. Fork it
|
109
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
110
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
111
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
112
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/conekticut.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 'conekticut/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conekticut"
|
8
|
+
spec.version = Conekticut::VERSION
|
9
|
+
spec.authors = ["Ian Rodriguez", "Carlos Ortega"]
|
10
|
+
spec.email = ["ian.rgz@gmail.com", "roh.race@gmail.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for the Conekta API}
|
12
|
+
spec.summary = %q{Lighting fast client for the Conekta API, more info at: https://www.conekta.io/}
|
13
|
+
spec.homepage = "https://github.com/ianrgz/conekticut"
|
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 = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency("activesupport", ">= 3.2.0")
|
22
|
+
spec.add_dependency('rest-client', '~> 1.6.0')
|
23
|
+
spec.add_dependency('multi_json', '~> 1.8.0')
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency("rspec", "~> 2.14.1")
|
28
|
+
spec.add_development_dependency('shoulda', '~> 3.5.0')
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Conekticut
|
2
|
+
module Client
|
3
|
+
module Configuration
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
add_config_option :public_key
|
8
|
+
add_config_option :private_key
|
9
|
+
add_config_option :conekta_version, "'0.2.0'"
|
10
|
+
add_config_option :api_base_path, "'https://api.conekta.io'"
|
11
|
+
add_config_option :api_version
|
12
|
+
add_config_option :use_ssl
|
13
|
+
add_config_option :ssl_cert_path
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def add_config_option(name, default_value = "nil")
|
18
|
+
class_eval <<-RUBY
|
19
|
+
def self.#{name}(value=#{default_value})
|
20
|
+
@#{name} = value if value
|
21
|
+
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
22
|
+
name = superclass.#{name}
|
23
|
+
return nil if name.nil? && !instance_variable_defined?("@#{name}")
|
24
|
+
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.#{name}=(value)
|
28
|
+
@#{name} = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def #{name}=(value)
|
32
|
+
@#{name} = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def #{name}
|
36
|
+
value = @#{name} if instance_variable_defined?(:@#{name})
|
37
|
+
value = self.class.#{name} unless instance_variable_defined?(:@#{name})
|
38
|
+
if value.instance_of?(Proc)
|
39
|
+
value.arity >= 1 ? value.call(self) : value.call
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
RUBY
|
45
|
+
end
|
46
|
+
|
47
|
+
def configure
|
48
|
+
yield self
|
49
|
+
end
|
50
|
+
end # end ClassMethods
|
51
|
+
end # end Configuration
|
52
|
+
end # end Client
|
53
|
+
end # end Conekticut
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "rest_client"
|
3
|
+
require "multi_json"
|
4
|
+
require "conekticut/client/configuration"
|
5
|
+
|
6
|
+
module Conekticut
|
7
|
+
module Client
|
8
|
+
class Payment
|
9
|
+
def self.create(url = nil, payment_info = {})
|
10
|
+
unless RequestHandler.has_valid_api_key?
|
11
|
+
raise StandardError, "Please, verify your api key."
|
12
|
+
end
|
13
|
+
|
14
|
+
request_options = {
|
15
|
+
:headers => {
|
16
|
+
:user_agent => "Conekta RubyBindings/#{Base.conekta_version}",
|
17
|
+
:authorization => "Basic #{::Base64.encode64("#{Base.public_key}:")}",
|
18
|
+
:accept=>"application/vnd.conekta-v#{ Base.api_version }+json"
|
19
|
+
}, :method => :post, :open_timeout => 30,
|
20
|
+
:payload => payment_info, :url => RequestHandler.format_api_path(url),
|
21
|
+
:timeout => 80
|
22
|
+
}
|
23
|
+
|
24
|
+
if RequestHandler.require_ssl?
|
25
|
+
request_options.update(:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
26
|
+
:ssl_ca_file => Base.ssl_cert_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
unless payment_info.respond_to? :to_hash
|
30
|
+
raise StandardError, "Expected: Hash, got: #{params.class}"
|
31
|
+
end
|
32
|
+
|
33
|
+
full_request_url = RequestHandler.format_api_path(url)
|
34
|
+
|
35
|
+
begin
|
36
|
+
response = ::RestClient::Request.execute(request_options)
|
37
|
+
rescue RestClient::UnprocessableEntity => e
|
38
|
+
return { "status" => 422, "message" => e.message }
|
39
|
+
end
|
40
|
+
|
41
|
+
::MultiJson.load response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Conekticut
|
2
|
+
module Client
|
3
|
+
class RequestHandler
|
4
|
+
def self.has_valid_api_key?
|
5
|
+
public_key = Conekticut::Client::Base.public_key
|
6
|
+
not public_key.empty? and not public_key =~ /\s/
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.require_ssl?
|
10
|
+
if Conekticut::Client::Base.use_ssl == true
|
11
|
+
ssl_cert = OpenSSL::PKey::RSA.new File.read(
|
12
|
+
Conekticut::SSLCert.new(Conekticut::Client::Base.ssl_cert_path)
|
13
|
+
)
|
14
|
+
else
|
15
|
+
puts "You are not using SSL Certs. We recommend to use it to avoid risks."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.format_api_path(request)
|
20
|
+
if request.end_with? ".json"
|
21
|
+
"#{Base.api_base_path}/#{request}"
|
22
|
+
else
|
23
|
+
"#{Base.api_base_path}/#{request}.json"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "conekticut/client/configuration"
|
2
|
+
require "conekticut/client/request_handler"
|
3
|
+
|
4
|
+
module Conekticut
|
5
|
+
module Client
|
6
|
+
class Base
|
7
|
+
attr_reader :file
|
8
|
+
|
9
|
+
include Conekticut::Client::Configuration
|
10
|
+
end # end Base
|
11
|
+
end # end Client
|
12
|
+
end # end Conekticut
|
data/lib/conekticut.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module Conekticut
|
5
|
+
class << self
|
6
|
+
def configure(&block)
|
7
|
+
Conekticut::Client::Base.configure(&block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Payment
|
12
|
+
def self.create(url = nil, payment_info = {})
|
13
|
+
Conekticut::Client::Payment.create(url, api_key, api_version, payment_info)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require "conekticut/version"
|
19
|
+
require "conekticut/client"
|
20
|
+
require "conekticut/sslcert"
|
21
|
+
require "conekticut/client/payment"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Conekticut do
|
4
|
+
before(:each) { @client_class = Class.new(Conekticut::Client::Base) }
|
5
|
+
|
6
|
+
describe ".configure" do
|
7
|
+
it "proxies to Client configuration" do
|
8
|
+
Conekticut::Client::Base.add_config_option(:test_config)
|
9
|
+
|
10
|
+
Conekticut.configure do |c|
|
11
|
+
c.test_config = "foo"
|
12
|
+
end
|
13
|
+
|
14
|
+
Conekticut::Client::Base.test_config.should == "foo"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Conekticut::Client::Base do
|
20
|
+
before(:each) { @client_class = Class.new(Conekticut::Client::Base) }
|
21
|
+
|
22
|
+
describe ".add_config_option" do
|
23
|
+
it "creates a class level accessor" do
|
24
|
+
@client_class.add_config_option :some_class_level_accessor
|
25
|
+
@client_class.some_class_level_accessor = "bar"
|
26
|
+
@client_class.some_class_level_accessor.should == "bar"
|
27
|
+
end
|
28
|
+
|
29
|
+
context "assigning a proc to a accessor" do
|
30
|
+
before(:each) do
|
31
|
+
@client_class.add_config_option :foo_bar
|
32
|
+
@client_class.foo_bar = the_proc
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the proc does not accept args" do
|
36
|
+
let(:the_proc) { proc { "return arg" } }
|
37
|
+
|
38
|
+
it "calls the proc with no arguments" do
|
39
|
+
@client_class.new.foo_bar.should == "return arg"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the proc accepts args" do
|
44
|
+
let(:the_proc) { proc {|arg| arg.should be_an_instance_of(@client_class) } }
|
45
|
+
|
46
|
+
it "calls the proc with arguments" do
|
47
|
+
@client_class.foo_bar
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
describe Conekticut::Client::Payment do
|
5
|
+
before :each do
|
6
|
+
Conekticut.configure do |c|
|
7
|
+
c.public_key = "1tv5yJp3xnVZ7eK67m4h"
|
8
|
+
c.ssl_cert_path = "spec/factories/ssl_cert.crt"
|
9
|
+
@payments_status_list = ["paid", "pending_payment"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".create" do
|
14
|
+
context "when incorrect data was submited" do
|
15
|
+
it "send request to conekta servers" do
|
16
|
+
payment_info = { "card"=> {} }
|
17
|
+
response = Conekticut::Client::Payment.create("/charges", payment_info)
|
18
|
+
response["status"].should eq 422
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when correct data was submited" do
|
23
|
+
context "with credit card payment" do
|
24
|
+
it "returns a json with status equal paid" do
|
25
|
+
payment_info = {
|
26
|
+
"currency"=>"MXN",
|
27
|
+
"amount"=> 20000,
|
28
|
+
"description"=>"Stogies",
|
29
|
+
"reference_id"=>"9839-wolf_pack",
|
30
|
+
"card"=> {
|
31
|
+
"number"=> 4111111111111111,
|
32
|
+
"name"=>"Thomas Logan",
|
33
|
+
"exp_month"=> 12,
|
34
|
+
"exp_year"=> 2015,
|
35
|
+
"cvc"=> 666,
|
36
|
+
"address"=> {
|
37
|
+
"street1"=>"250 Alexis St",
|
38
|
+
"city"=>"Red Deer",
|
39
|
+
"state"=>"Alberta",
|
40
|
+
"country"=>"Canada",
|
41
|
+
"zip"=>"T4N 0B8"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
response = Conekticut::Client::Payment.create("/charges", payment_info)
|
47
|
+
@payments_status_list.should include(response["status"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with bank payment" do
|
52
|
+
it "returns a json with status equal pending_payment" do
|
53
|
+
payment_info = {
|
54
|
+
"currency"=>"MXN",
|
55
|
+
"amount"=>20000,
|
56
|
+
"description"=>"Stogies",
|
57
|
+
"reference_id"=>"9839-wolf_pack",
|
58
|
+
"bank"=> {
|
59
|
+
"type"=>"bank"
|
60
|
+
},
|
61
|
+
"details"=> {
|
62
|
+
"name"=>"Wolverine",
|
63
|
+
"email"=>"logan@x-men.org",
|
64
|
+
"phone"=>"403-342-0642"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
response = Conekticut::Client::Payment.create("/charges", payment_info)
|
69
|
+
@payments_status_list.should include(response["status"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with oxxo payment" do
|
74
|
+
it "returns a json with status equal pending_payment" do
|
75
|
+
payment_info = {
|
76
|
+
"currency"=>"MXN",
|
77
|
+
"amount"=>20000,
|
78
|
+
"description"=>"Stogies",
|
79
|
+
"reference_id"=>"9839-wolf_pack",
|
80
|
+
"bank"=> {
|
81
|
+
"type"=>"oxxo"
|
82
|
+
},
|
83
|
+
"details"=> {
|
84
|
+
"name"=>"Wolverine",
|
85
|
+
"email"=>"logan@x-men.org",
|
86
|
+
"phone"=>"403-342-0642"
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
response = Conekticut::Client::Payment.create("/charges", payment_info)
|
91
|
+
@payments_status_list.should include(response["status"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Conekticut::Client::RequestHandler do
|
4
|
+
describe ".has_valid_api_key?" do
|
5
|
+
context "with valid api_key" do
|
6
|
+
it "returns true when it was initialized" do
|
7
|
+
Conekticut::Client::Base.public_key = "initialized"
|
8
|
+
Conekticut::Client::RequestHandler.has_valid_api_key?.should eq true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with invalid api_key" do
|
13
|
+
it "returns false when it has not spaces" do
|
14
|
+
Conekticut::Client::Base.public_key = "initial ized"
|
15
|
+
Conekticut::Client::RequestHandler.has_valid_api_key?.should eq false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns false when it was not initialized" do
|
19
|
+
Conekticut::Client::Base.public_key = ""
|
20
|
+
Conekticut::Client::RequestHandler.has_valid_api_key?.should eq false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".require_ssl?" do
|
26
|
+
context "when SSL Cert is used and it is available" do
|
27
|
+
before :each do
|
28
|
+
Conekticut::Client::Base.use_ssl = true
|
29
|
+
Conekticut::Client::Base.ssl_cert_path = "spec/factories/ssl_cert.crt"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns load the cert" do
|
33
|
+
Conekticut::Client::RequestHandler.require_ssl?.should_not be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when ssl_cert is not being used" do
|
38
|
+
before :each do
|
39
|
+
Conekticut::Client::Base.use_ssl = false
|
40
|
+
Conekticut::Client::Base.ssl_cert_path = "spec/factories/ssl_cert.crt"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns nil" do
|
44
|
+
Conekticut::Client::RequestHandler.require_ssl?.should eq nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".format_api_path" do
|
50
|
+
before :each do
|
51
|
+
Conekticut::Client::Base.api_base_path = "https://api.conekta.io"
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when .json request was not specified" do
|
55
|
+
before :each do
|
56
|
+
@full_request_url = Conekticut::Client::RequestHandler.format_api_path("my_request")
|
57
|
+
@expected_request_url = "https://api.conekta.io/my_request.json"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns the full request's url" do
|
61
|
+
@full_request_url.should eq @expected_request_url
|
62
|
+
end
|
63
|
+
|
64
|
+
it "automatically adds .json extension" do
|
65
|
+
@expected_request_url.should end_with ".json"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when .json request was specified" do
|
70
|
+
it "returns the full request's url" do
|
71
|
+
request_url = Conekticut::Client::RequestHandler.format_api_path("my_request.json")
|
72
|
+
request_url.should eq "https://api.conekta.io/my_request.json"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Conekticut::SSLCert do
|
4
|
+
describe "instance methods" do
|
5
|
+
describe "#to_path" do
|
6
|
+
context "when path was not specified" do
|
7
|
+
before :each do
|
8
|
+
Conekticut::Client::Base.ssl_cert_path = "my_ssl_cert_path"
|
9
|
+
end
|
10
|
+
|
11
|
+
it " returns Base.ssl_cert_path" do
|
12
|
+
ssl_cert_path = Conekticut::Client::Base.ssl_cert_path = "my_ssl_cert_path"
|
13
|
+
Conekticut::SSLCert.new.to_path.should eq ssl_cert_path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when path was specified" do
|
18
|
+
it "should load the expected cert" do
|
19
|
+
ssl_cert_path = Conekticut::Client::Base.ssl_cert_path = "my_ssl_cert_path"
|
20
|
+
Conekticut::SSLCert.new("expected_cert").to_path.should eq "expected_cert"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEpAIBAAKCAQEAwiDhkmqNLH8Q5QOGNtAyTRN3NFT3UKqhOPdfxfhuZAR+6by+
|
3
|
+
9sqlDE543DLvX8k/VSvLpZmH8SNFhdQC2Npz5a8wslUVVytNeYy/LLzzpN6Gq4MR
|
4
|
+
S3+i7zpumiEr/gUSbgTnXeEEWvhxlxP3+M7YVoipix9Q9qX1Ssf0KNh9MzYq73nb
|
5
|
+
+a51ONZJxCVpGHGGB7Oo24okQ6lpZPUtSXWltqkRlYyb0JjYIR8IRfzExyE5eJFf
|
6
|
+
zhal8rh/oKEzajd9jD7iFuvJ9eVVfkbjtKAHL2N1V2J4K2ey77xQ92478ii56VEV
|
7
|
+
LAszuEW/ui9MVS7LYf4NGoZrHguWDZK+5mPOoQIDAQABAoIBAQCslb71BHVt0amb
|
8
|
+
cH6pzH5rt5qKk98rgAbFNmeXAT5i/Pw3oO3FSnNhdYJNgZr+dVQwzDbIiq4o20q7
|
9
|
+
p7jAQbY3xIBuiuXmEUFXhqGPjIyvToY7hNKjZF3egPxDWqpZsvinhwSKmbndhnK1
|
10
|
+
9bLHKF180RKp9LVuEiz4xrtydMUZ+MmajoXYI+g1WkGwsK2ZTkmGsdEul4ZAW4aq
|
11
|
+
qX6Q3JJ0OiHbwu/FmzccKCnb/2CnMcBgnEPJQPUQLbQOa7ZUpsIGRvFe/Du+2iqq
|
12
|
+
nJ4/XzWJiOTzBJSeUckJfO5u1YGHzGZqD23vfs93dmnqZ2QgqbUGouKgH5h51xYM
|
13
|
+
khKzOkCBAoGBAOdkclljJYp+A6AlkbQjw3fXLkWlVGtblLZvYCS08xEuV5gPFn/b
|
14
|
+
LbeMR5OYRqHF/arRB42BSp/sCzax/wRWTS2YgxR8L8nJW0rv+m54dIWlsXfzkMDi
|
15
|
+
FKeuTSnqfV3eu875O6hafC7IHfzXE2bw5Pd2SfQLsTpGpvrtm6Vj42PtAoGBANbF
|
16
|
+
8NYcczFFX++gQPhvjGdzFMQwlStbS7+xEsvLeLA6OquorT6dUY1f34yQAQWOAsyL
|
17
|
+
ONDVps6EyMD81dWDWsybtn86btVq57XSkFRaGBTZh1LtvhGKLw2Gp3a4SBLrL/mR
|
18
|
+
L+2vOye1mqlmSModZk9MBA8z3xm9xTMZUj9p6OcFAoGBAOH7uqXL680O9vF/34Xj
|
19
|
+
67HtyHYiWoki/uERcv9GbaEY9lk+WwXxg/ufmAPwkwLJf81EqjCr1brL58O6IMoW
|
20
|
+
kvd13Ia0JmPXMD7GknkzUPF5ehIhIP0Pj4aX9yp5pYh40Ej6JiZsgJ2buZXGY1+E
|
21
|
+
4sk/kEg05xh4CfpE9l6XaGudAoGAThIwBLTczslIIWQgme56nFRB9Tsvzk3mkCz/
|
22
|
+
ByPUoELadvHe4Abx0TFLot3p8Sn5LH9jTM6NTz8Hdtexp2aTSBNGWKNWDLBKwFZl
|
23
|
+
brQ9Ur7sKSIQ2HFhv0n2b/p3AKGLk+3J/V2YZEvoh7GNviLHwQWB6EDT1ZidKYEH
|
24
|
+
29NU/T0CgYB9nP08v/rfVT674ZYxYrQ9didRB5mOTpO5qojjyzc5/SQV3wEEFs8a
|
25
|
+
DLLsz7ua53djKvQUkpy5tj24wVesnQ+wigaglw8KosCZ5R0gGJBVaaPtZlRDkF7r
|
26
|
+
e1NGQ2y80f1A2xxYQRQlrpRncQ5n7+NeIC/RUKUYBX4pfi6mQLychQ==
|
27
|
+
-----END RSA PRIVATE KEY-----
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
require "conekticut"
|
6
|
+
|
7
|
+
# Load files from support directory
|
8
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
9
|
+
|
10
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conekticut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Rodriguez
|
8
|
+
- Carlos Ortega
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.2.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rest-client
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.6.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: multi_json
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.8.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.8.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.14.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ~>
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.14.1
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: shoulda
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 3.5.0
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 3.5.0
|
112
|
+
description: Ruby wrapper for the Conekta API
|
113
|
+
email:
|
114
|
+
- ian.rgz@gmail.com
|
115
|
+
- roh.race@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .rspec
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- conekticut.gemspec
|
127
|
+
- lib/conekticut.rb
|
128
|
+
- lib/conekticut/client.rb
|
129
|
+
- lib/conekticut/client/configuration.rb
|
130
|
+
- lib/conekticut/client/payment.rb
|
131
|
+
- lib/conekticut/client/request_handler.rb
|
132
|
+
- lib/conekticut/sslcert.rb
|
133
|
+
- lib/conekticut/version.rb
|
134
|
+
- spec/client/configuration_spec.rb
|
135
|
+
- spec/client/payment_spec.rb
|
136
|
+
- spec/client/request_handler_spec.rb
|
137
|
+
- spec/client/request_spec.rb
|
138
|
+
- spec/client/sslcert_spec.rb
|
139
|
+
- spec/factories/ssl_cert.crt
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
homepage: https://github.com/ianrgz/conekticut
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.1.11
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: 'Lighting fast client for the Conekta API, more info at: https://www.conekta.io/'
|
165
|
+
test_files:
|
166
|
+
- spec/client/configuration_spec.rb
|
167
|
+
- spec/client/payment_spec.rb
|
168
|
+
- spec/client/request_handler_spec.rb
|
169
|
+
- spec/client/request_spec.rb
|
170
|
+
- spec/client/sslcert_spec.rb
|
171
|
+
- spec/factories/ssl_cert.crt
|
172
|
+
- spec/spec_helper.rb
|