kamba_signature_generation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 424b8cc32a1b716be1534c2e4d18a591e986585da04a1356d4ed33c52f9e3269
4
+ data.tar.gz: 605bac9153aa96a4be97b132d2451da907d031d47094bafc0bd45ba3ed35f308
5
+ SHA512:
6
+ metadata.gz: e08b4dbe91be7828cb42a3996e229e0495d4199bc94dab771e8f8b459b4587ab3b73bee7ffeedc0be6994fa068b4cfa30a70500be75b6b319eddb514478cd9f9
7
+ data.tar.gz: a8ae6353e7063156d3aedc7eb3cf745470d9b145d5fea49d7b63c7238d86f44c3234165bc73c81202c506a313a27faa42314e252d343ccde9311214eb51b8382
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "rspec"
5
+ gem "rake"
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.3)
5
+ rake (12.3.2)
6
+ rspec (3.8.0)
7
+ rspec-core (~> 3.8.0)
8
+ rspec-expectations (~> 3.8.0)
9
+ rspec-mocks (~> 3.8.0)
10
+ rspec-core (3.8.0)
11
+ rspec-support (~> 3.8.0)
12
+ rspec-expectations (3.8.2)
13
+ diff-lcs (>= 1.2.0, < 2.0)
14
+ rspec-support (~> 3.8.0)
15
+ rspec-mocks (3.8.0)
16
+ diff-lcs (>= 1.2.0, < 2.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-support (3.8.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ rake
25
+ rspec
26
+
27
+ BUNDLED WITH
28
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Herneto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Kamba Signature Generation
2
+
3
+ Gem ruby para gerar a assinatura necessária para processar o checkout nos serviços da Kamba.
4
+ ## Instalação
5
+
6
+ Adicione essa linha ao Gemfile da sua applicação:
7
+
8
+ ```ruby
9
+ gem 'kamba_signature_generation'
10
+ ```
11
+
12
+ E execute:
13
+
14
+ $ bundle
15
+
16
+ ou instale por você mesmo:
17
+
18
+ $ gem install kamba_signature_generation
19
+
20
+ ## Configuração
21
+
22
+ ```ruby
23
+ require 'kamba_signature_generation'
24
+
25
+ KambaSignatureGeneration.secret_key = 'sua-chave-secreta-kamba'
26
+ ```
27
+
28
+ Ou simplesmente atribua o valor da sua chaves-chave-kamba secreta a seguinte variável de ambiente: `ENV["KAMBA_SECRET_KEY"]`.
29
+
30
+ Usando Ruby on Rails? Coloque isso em config/initializers em novo arquivo chamado kamba_signature_generation.rb.
31
+
32
+ ## Uso
33
+
34
+ ```ruby
35
+ checkout_config = {
36
+ "channel"=>"WEB",
37
+ "initial_amount"=>10000,
38
+ "notes"=> "Curso API Iniciantes",
39
+ "redirect_url_success"=>"https://seusite.com/curso/api-iniciantes"
40
+ }
41
+ @signature = KambaSignatureGeneration::API.generate_signature('KAMBA-API-MODE', checkout_config)
42
+ ```
43
+ Obs: `KAMBA-API-MODE: sandbox, staging ou production`
44
+
45
+
46
+ **Configurações `checkout_config`:**
47
+ - Para o nosso propósito o valor do campo `channel`, permanecerá igual à **WEB** como no exemplo.
48
+ - `initial_amount`, este campo recebe o preço do produto ou serviço a ser comercializado.
49
+ - Substitua o valor do campo `notes` por uma anotação ou descrição geral a cerca do pagamento, e coloque o preço do mesmo no valor do campo `initial_amount`.
50
+ - O campo `redirect_url_success` recebe o endereço da página na qual pretende-se ser redirecionada após o pagamento com sucesso.
51
+
52
+ Finalmente, use o valor de `@signature` para assinar processar o checkout.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kamba_signature_generation"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kamba_signature_generation/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kamba_signature_generation"
8
+ spec.version = KambaSignatureGeneration::VERSION
9
+ spec.authors = ["Hernani Neto"]
10
+ spec.email = ["hernaniprogramacao@gmail.com"]
11
+
12
+
13
+ spec.summary = %q{Kamba Signature Generation}
14
+ spec.description = %q{A gem to generate signatures based on your Kamba secret key to use with Kamba Checkout Js.}
15
+ spec.homepage = "https://github.com/usekamba/generate-signature-ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.17"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
@@ -0,0 +1,14 @@
1
+ require "kamba_signature_generation/version"
2
+
3
+ module KambaSignatureGeneration
4
+ class Error < StandardError; end
5
+
6
+ require 'time'
7
+ require 'json'
8
+ require 'digest'
9
+ require 'openssl'
10
+ require 'base64'
11
+
12
+ require 'kamba_signature_generation/api'
13
+ require 'kamba_signature_generation/config'
14
+ end
@@ -0,0 +1,18 @@
1
+ module KambaSignatureGeneration
2
+ class API
3
+ def self.generate_signature(checkout)
4
+ secret_key = KambaSignatureGeneration.secret_key
5
+
6
+ json_string = checkout.to_json
7
+ canonical_string = "POST,application/json,#{generate_md5(json_string)},#{'/v1/checkouts'}"
8
+
9
+ digest = OpenSSL::Digest.new('sha1')
10
+ hmac_signature = OpenSSL::HMAC.digest(digest, secret_key, canonical_string)
11
+ Base64.strict_encode64(hmac_signature)
12
+ end
13
+
14
+ def self.generate_md5(checkout)
15
+ Digest::MD5.base64digest(checkout)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module KambaSignatureGeneration
2
+ class << self
3
+ def secret_key=(key)
4
+ @secret_key= key
5
+ end
6
+
7
+ def secret_key
8
+ @secret_key || ENV["KAMBA_SECRET_KEY"]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module KambaSignatureGeneration
2
+ VERSION = "0.1.0"
3
+ end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'KambaSignatureGeneration::API' do
4
+ describe 'Generating Signature' do
5
+ before(:each) do
6
+ @checkout = {
7
+ 'channel'=>'WEB',
8
+ 'initial_amount'=>5500,
9
+ 'notes'=> 'Alguma note exemplo.',
10
+ 'redirect_url_success'=> 'http://amarildolucas.com/curso/aplicativo-movel-com-swift/sucesso'
11
+ }
12
+ KambaSignatureGeneration.secret_key = '123'
13
+ end
14
+
15
+ it 'should generate signature' do
16
+ signature = KambaSignatureGeneration::API.generate_signature(@checkout)
17
+ signature.should_not == '123'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+
2
+
3
+ describe 'KambaSignatureGeneration' do
4
+ describe 'secret_key' do
5
+ before(:each) do
6
+ @default_secret_key = KambaSignatureGeneration.secret_key
7
+ KambaSignatureGeneration.secret_key = nil
8
+ ENV['KAMBA_SECRET_KEY'] = nil
9
+ end
10
+
11
+ after(:each) do
12
+ KambaSignatureGeneration.secret_key = @default_secret_key
13
+ end
14
+
15
+ it 'should set and read instance variable' do
16
+ KambaSignatureGeneration.secret_key = '123'
17
+ KambaSignatureGeneration.secret_key.should == '123'
18
+ end
19
+
20
+ it 'should fallback to ENV variable' do
21
+ ENV['KAMBA_SECRET_KEY'] = 'checkout'
22
+ KambaSignatureGeneration.secret_key.should == 'checkout'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+ require "kamba_signature_generation"
3
+
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kamba_signature_generation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hernani Neto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A gem to generate signatures based on your Kamba secret key to use with
56
+ Kamba Checkout Js.
57
+ email:
58
+ - hernaniprogramacao@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - kamba_signature_generation.gemspec
71
+ - lib/kamba_signature_generation.rb
72
+ - lib/kamba_signature_generation/api.rb
73
+ - lib/kamba_signature_generation/config.rb
74
+ - lib/kamba_signature_generation/version.rb
75
+ - spec/api_spec.rb
76
+ - spec/config_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/usekamba/generate-signature-ruby
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Kamba Signature Generation
102
+ test_files: []