compropago 0.0.2 → 0.1.0

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.
data/README.md CHANGED
@@ -6,7 +6,7 @@ This gem helps you integrate ComproPago's API to your ruby app.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'compropago', '~> 0.0.1'
9
+ gem 'compropago', '~> 0.1.0'
10
10
 
11
11
  And then execute:
12
12
 
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  We encourage you to set your API keys in an environment variable rather than hardcoding your API keys.
24
24
 
25
- compropago = Compropago::Client.new(ENV['COMPROPAGO_API_KEY'])
25
+ Compropago.api_key = "sk_test_my_api_key"
26
26
 
27
27
  Once you have created an instance of compropago, you can call the methods described in the <a href="http://compropago.com/documentacion/api">api reference</a> on it.
28
28
 
@@ -32,32 +32,31 @@ Once you have created an instance of compropago, you can call the methods descri
32
32
  ### Create a charge
33
33
 
34
34
  Creating a charge using only the required params <code>product_price</code>, <code>product_name</code>, <code>customer_name</code>, <code>customer_email</code>, <code>payment_type</code>.
35
-
36
- # create_charge(product_price, product_name, customer_name, customer_email, payment_type)
37
35
 
38
- compropago.create_charge(3150.0, 'iphone5s', 'Irma Sanz', 'no-replay@compropago.com', 'OXXO')
39
-
40
- Adding the optional params <code>product_id</code> and <code>image_url</code> to the request:
41
-
42
- # create_charge(product_price, product_name, customer_name, customer_email, payment_type, product_id, image_url)
43
-
44
- compropago.create_charge(3150.0, 'iphone5s', 'Irma Sanz', 'no-replay@email.com', 'OXXO', '5ku8g', 'image.jpg')
36
+ ```ruby
37
+ Compropago::Charge.create({ product_price: 10000.0,
38
+ product_name: "SAMSUNG GOLD CURL",
39
+ customer_name: "Roberto Miranda",
40
+ customer_email: "noreply@compropago.com",
41
+ payment_type: "OXXO"})
42
+ ```
45
43
 
46
44
  ### Verify a charge
47
45
 
48
46
  Verify a charge previously made.
49
47
 
50
- # verify_charge(payment_id)
51
-
52
- compropago.verify_charge('b75076ac-a94b-478a-945c-c2caf85be668')
48
+ ```ruby
49
+ Compropago::Charge.find("818f2e81-226a-4ff9-88a2-81a577aec380")
50
+ ```
53
51
 
54
52
  ### SMS payment instructions
55
53
 
56
54
  Send payment instructions over SMS.
57
55
 
58
- # send_payment_instructions(payment_id, customer_phone, customer_company_phone)
56
+ ```ruby
57
+ Compropago::SMS.create(payment_id: "818f2e81-226a-4ff9-88a2-81a577aec380", customer_phone: "2221515805", customer_company_phone: "TELCEL")
58
+ ```
59
59
 
60
- compropago.send_payment_instructions('b75076ac-a94b-478a-945c-c2caf85be668', '2221515805', 'TELCEL')
61
60
 
62
61
  ## Contributing
63
62
 
data/Rakefile CHANGED
@@ -1 +1,31 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ task :console do
6
+ Rake::Task["build"].invoke
7
+ Rake::Task["install"].invoke
8
+ puts "Loading development console..."
9
+ system("irb -r compropago")
10
+ end
11
+
12
+ task :help do
13
+ puts "Available rake tasks: "
14
+ puts "rake console - Run a IRB console with all enviroment loaded"
15
+ puts "rake test - Run tests"
16
+ end
17
+
18
+ Rake::TestTask.new("test:regular") do |t|
19
+ t.libs = ["test"]
20
+ t.pattern = "test/*_test.rb"
21
+ t.ruby_opts = ['-w']
22
+ end
23
+
24
+ Rake::TestTask.new("test:models") do |t|
25
+ t.libs = ["test"]
26
+ t.pattern = "test/models/*_test.rb"
27
+ t.ruby_opts = ['-w']
28
+ end
29
+
30
+ task :default => :test
31
+ task :test => ['test:regular', 'test:models']
data/compropago.gemspec CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "active_rest_client", "~> 1.0.4"
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "webmock", "~> 1.16.1"
23
26
  end
@@ -0,0 +1,15 @@
1
+ require "compropago"
2
+ Compropago.api_key = "sk_test_my_api_key"
3
+ Compropago::Charge.find("1")
4
+
5
+ Compropago::Charge.create({ product_price: 10000.0,
6
+ product_name: "SAMSUNG GOLD CURL",
7
+ customer_name: "Roberto Miranda",
8
+ customer_email: "noreply@compropago.com",
9
+ payment_type: "OXXO"})
10
+ #=>
11
+ #<Compropago::Charge:0x007f99abb13220 @attributes={:payment_id=>"818f2e81-226a-4ff9-88a2-81a577aec380", :short_payment_id=>"b05aed", :payment_status=>"PENDING", :creation_date=>Wed, 30 Jul 2014 18:05:49 -0500, :expiration_date=>Thu, 31 Jul 2014 18:05:49 -0500, :product_information=>#<Compropago::Charge:0x007f99abb10d18 @attributes={:product_id=>"SMGCURL1", :product_name=>"SAMSUNG GOLD CURL", :product_price=>"10000.0"}, @dirty_attributes=#<Set: {}>>, :payment_instructions=>#<Compropago::Charge:0x007f99abb103e0 @attributes={:description=>"Para que el pago sea válido debes pagar la cantidad exacta de $10000.0", :step_1=>"Ir a la caja OXXO de 8:00 am a 8:00 pm", :step_2=>"Solicitar depósito bancario al número: Banco de Pruebas 0000 0000 0000 0000", :step_3=>"Deposite la cantidad exacta de: $10000.0", :note_extra_comition=>"Las tiendas Oxxo cobran en caja una comisión de $7.00 por el concepto de recepción de cobranza.", :note_expiration_date=>"Orden válida antes de 31/07/2014, en caso de vencimiento genera una nueva compra.", :note_confirmation=>"Tu pago será confirmado a través de SMS y correo electronico. ¡Gracias por usar ComproPago!"}, @dirty_attributes=#<Set: {}>>}, @dirty_attributes=#<Set: {}>, @_status=200>
12
+
13
+
14
+
15
+ Compropago::SMS.create(payment_id: "818f2e81-226a-4ff9-88a2-81a577aec380", customer_phone: "2221515805", customer_company_phone: "TELCEL")
data/lib/compropago.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  # API spec at http://compropago.com/documentacion/api
2
- require 'net/https'
3
- require 'uri'
4
-
5
2
  # Version
6
3
  require 'compropago/version'
7
-
8
- # Resources
9
- require 'compropago/client'
4
+ require "active_rest_client"
5
+ require "compropago/configuration"
10
6
 
11
7
  module Compropago
12
-
13
- end
8
+ autoload :Base, 'compropago/base'
9
+ autoload :Charge, 'compropago/charge'
10
+ autoload :SMS, 'compropago/sms'
11
+ end
@@ -0,0 +1,4 @@
1
+ module Compropago
2
+ class Base < ActiveRestClient::Base
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Compropago
2
+ class Charge < Base
3
+ get :find, "/charges/:id"
4
+ post :create, "/charges"
5
+
6
+ STORES = %w(OXXO SEVEN_ELEVEN EXTRA TELECOMM WALMART
7
+ SORIANA BODEGA_AURRERA SAMS_CLUB CASA_LEY CHEDRAUI PITICO
8
+ SUPERAMA ELEKTRA COPPEL VIPS EL_PORTON FARMACIA_BENAVIDES
9
+ FARMACIA_ABC FARMACIA_ESQUIVAR)
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module Compropago
2
+ # Stores runtime configuration information.
3
+ #
4
+ # @example Standard settings
5
+ # Compropago.api_url = "https://api.compropago.com/v1"
6
+ # Compropago.api_key = "MyAPIKey"
7
+ ActiveRestClient::Base.base_url = "https://api.compropago.com/v1"
8
+
9
+ def self.api_key
10
+ @api_key
11
+ end
12
+
13
+ def self.api_url
14
+ ActiveRestClient::Base.base_url
15
+ end
16
+
17
+ def self.api_key=(api_key)
18
+ @api_key = api_key
19
+ ActiveRestClient::Base.faraday_config do |faraday|
20
+ faraday.request :basic_auth, api_key, nil
21
+ faraday.request :url_encoded # form-encode POST params
22
+ faraday.response :logger # log requests to STDOUT
23
+ faraday.response :raise_error
24
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
25
+
26
+ #FIXME https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates#solutions-to-avoid
27
+ faraday.ssl.merge!({ verify: false })
28
+ end
29
+ end
30
+
31
+ def self.api_url=(api_url)
32
+ ActiveRestClient::Base.base_url = api_url
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ require "uri"
2
+ require 'faraday_middleware'
3
+ Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{ |f| require f }
4
+ module Compropago
5
+ module Connection
6
+
7
+ def api_connection
8
+ @api_connection = Faraday.new(:url => Compropago.configuration.api_url) do |faraday|
9
+ faraday.request :basic_authentication, Compropago.configuration.api_key
10
+ faraday.request :url_encoded # form-encode POST params
11
+ faraday.response :logger # log requests to STDOUT
12
+ faraday.response :raise_error
13
+ #faraday.use FaradayMiddleware::RaiseHttpException
14
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Compropago
2
+ class SMS < Base
3
+ post :create, "/charges/:payment_id/sms"
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Compropago
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ class ConfigurationTest < MiniTest::Test
4
+ def test_must_set_the_conf_vars
5
+ assert_equal Compropago.api_url, "https://api.compropago.com/v1"
6
+
7
+ Compropago.api_url = "https://api.compropago.com/v2"
8
+ Compropago.api_key = "MyToken"
9
+ assert_equal Compropago.api_url, "https://api.compropago.com/v2"
10
+ assert_equal Compropago.api_key, "MyToken"
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ testdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
3
+
4
+ libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
5
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
6
+
7
+ require "rubygems"
8
+ require "compropago"
9
+ require "minitest/autorun"
10
+ require "minitest/unit"
11
+ require 'webmock/minitest'
12
+
13
+ class MiniTest::Test
14
+ def setup
15
+ end
16
+ end
17
+
18
+ def load_fixture(name)
19
+ File.new(File.dirname(__FILE__) + "/fixtures/#{name}.json")
20
+ end
21
+
22
+ # GET
23
+ def stub_get(path, fixture)
24
+ stub_request(:get, Regexp.new("#{Compropago.configuration.api_url}#{path}")).
25
+ to_return(:body => load_fixture(fixture))
26
+ end
27
+
28
+ # POST
29
+ def stub_post(path, fixture, status_code=200)
30
+ stub_request(:post, Regexp.new("#{Compropago.configuration.api_url}#{path}")).
31
+ to_return(:body => load_fixture(fixture), :status => status_code)
32
+ end
33
+
34
+ # PUT
35
+ def stub_put(path, fixture)
36
+ stub_request(:put, Regexp.new("#{Compropago.configuration.api_url}#{path}")).
37
+ to_return(:body => load_fixture(fixture))
38
+ end
39
+
40
+
41
+ # DELETE
42
+ def stub_delete(path)
43
+ stub_request(:delete, Regexp.new("#{Compropago.configuration.api_url}#{path}"))
44
+ end
45
+
46
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compropago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-26 00:00:00.000000000 Z
12
+ date: 2014-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: active_rest_client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.4
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: bundler
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,6 +59,38 @@ dependencies:
43
59
  - - ! '>='
44
60
  - !ruby/object:Gem::Version
45
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.16.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.16.1
46
94
  description: Ruby gem for making calls to ComproPago API
47
95
  email:
48
96
  - soporte@compropago.com
@@ -56,9 +104,17 @@ files:
56
104
  - README.md
57
105
  - Rakefile
58
106
  - compropago.gemspec
107
+ - example/example.rb
59
108
  - lib/compropago.rb
109
+ - lib/compropago/base.rb
110
+ - lib/compropago/charge.rb
60
111
  - lib/compropago/client.rb
112
+ - lib/compropago/configuration.rb
113
+ - lib/compropago/connection.rb
114
+ - lib/compropago/sms.rb
61
115
  - lib/compropago/version.rb
116
+ - test/configuration_test.rb
117
+ - test/test_helper.rb
62
118
  homepage: http://compropago.com
63
119
  licenses:
64
120
  - MIT
@@ -72,22 +128,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
128
  - - ! '>='
73
129
  - !ruby/object:Gem::Version
74
130
  version: '0'
75
- segments:
76
- - 0
77
- hash: -2503675149839758176
78
131
  required_rubygems_version: !ruby/object:Gem::Requirement
79
132
  none: false
80
133
  requirements:
81
134
  - - ! '>='
82
135
  - !ruby/object:Gem::Version
83
136
  version: '0'
84
- segments:
85
- - 0
86
- hash: -2503675149839758176
87
137
  requirements: []
88
138
  rubyforge_project:
89
139
  rubygems_version: 1.8.25
90
140
  signing_key:
91
141
  specification_version: 3
92
142
  summary: Ruby bindings for ComproPago
93
- test_files: []
143
+ test_files:
144
+ - test/configuration_test.rb
145
+ - test/test_helper.rb