kamba_checkout 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0277e0eb7550877cc851049ec1cf7d21e2d7e23a535f6c108f23eca17d82e4de
4
+ data.tar.gz: 96889802bc7f22e45cd3265fb8818493c4a9d4af88087b18d1f68291e11439f3
5
+ SHA512:
6
+ metadata.gz: a7d7d09ddc90d6c25f3358f44e53acbad9227adf93084f00490f460147f27a192d0389bd51b04936f8f1f7c003aa73aab4f6075f75c0b67cc0715d446fe9faa1
7
+ data.tar.gz: ce6c43de752cfacece25073bac41af93ae4ef5408e4053366e5ab15acbe24ecd1935d0b6d04563fae90e3647e1b8df302b0f625c8e6d675597cbfae20a466f0a
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.5.1
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
@@ -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
@@ -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.
@@ -0,0 +1,98 @@
1
+ # KambaCheckout
2
+
3
+ Gem ruby para configurar 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_checkout'
10
+ ```
11
+
12
+ E execute:
13
+
14
+ $ bundle
15
+
16
+ ou instale por você mesmo:
17
+
18
+ $ gem install kamba_checkout
19
+
20
+ ## Configuração
21
+
22
+ ```ruby
23
+ require 'kamba_checkout'
24
+
25
+ KambaCheckout.api_key = 'sua-chave-da-api-kamba'
26
+ KambaCheckout.secret_key = 'sua-chave-secreta-kamba'
27
+ ```
28
+
29
+ Ou simplesmente atribua os valores das suas chaves as seguintes variáveis de ambiente: `ENV["KAMBA_API_KEY"]` e `ENV["KAMBA_SECRET_KEY"]`.
30
+
31
+ Usando Ruby on Rails? Coloque isso em config/initializers em novo arquivo chamado kamba_checkout.rb.
32
+
33
+ ## Uso
34
+
35
+ ```ruby
36
+ checkout_config = {
37
+ "channel"=>"WEB",
38
+ "initial_amount"=>10000,
39
+ "notes"=> "Curso API Iniciantes",
40
+ "redirect_url_success"=>"https://seusite.com/curso/api-iniciantes"
41
+ }
42
+ @checkout = KambaCheckout::API.generate_checkout('KAMBA-API-MODE', checkout_config)
43
+ ```
44
+ Obs: `KAMBA-API-MODE: sandbox, staging ou production`
45
+
46
+
47
+ **Configurações `checkout_config`:**
48
+ - Para o nosso propósito o valor do campo `channel`, permanecerá igual à **WEB** como no exemplo.
49
+ - `initial_amount`, este campo recebe o preço do produto ou serviço a ser comercializado.
50
+ - 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`.
51
+ - O campo `redirect_url_success` recebe o endereço da página na qual pretende-se ser redirecionada após o pagamento com sucesso.
52
+
53
+ ## Usando Ruby on Rails?
54
+
55
+ Coloque o código acima na action que renderiza a página que vai conter o checkout e siga as instruções:
56
+
57
+ **Passo 1:**
58
+ ## Página do comerciante
59
+ Faça a chamada à biblioteca no cabeçalho da sua página Web ou no corpo da página antes das outras configurações javascript que poderão ser configuradas:
60
+
61
+ ```html
62
+ <head>
63
+ <script src="http://comerciante.usekamba.com/checkout/0.0.1/kamba-web-sdk.js" charset="utf-8"></script>
64
+ </head>
65
+ ```
66
+
67
+ **Passo 2:**
68
+ Faça a inclusão do botão "Pagar com KAMBA" dentro do corpo da sua página Web em qualquer lugar onde desejar que o botão seja apresentado.
69
+
70
+ ```html
71
+ <body>
72
+ <button class="btnOpenWidgetKamba" onclick="start_payment()"></button>
73
+ </body>
74
+ ```
75
+
76
+ **Passo 3:**
77
+ Cole o código abaixo dentro da tag html `<body></body>` no corpo da sua página Web, de preferência no final da página.
78
+
79
+ ```html
80
+ <body>
81
+ <script type="text/javascript">
82
+ function start_payment() {
83
+ kamba(api_config = {
84
+ environment: '<%= @checkout.environment %>', // Use variável de ambiente para segurança.
85
+ api_key: '<%= @checkout.api_key %>', // Use variável de ambiente para segurança.
86
+ checkout_time: '<%= @checkout.time %>',
87
+ checkout_signature: '<%= @checkout.signature %>'
88
+ },
89
+ checkout_config = {
90
+ channel: '<%= @checkout.channel %>',
91
+ initial_amount: <%= @checkout.initial_amount %>,
92
+ notes: '<%= @checkout.notes %>',
93
+ redirect_url_success: '<%= @checkout.redirect_url_success %>'
94
+ });
95
+ }
96
+ </script>
97
+ </script>
98
+ </body>
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kamba_checkout"
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__)
@@ -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,23 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kamba_checkout/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kamba_checkout"
8
+ spec.version = KambaCheckout::VERSION
9
+ spec.authors = ["Hernani Neto"]
10
+ spec.email = ["hernaniprogramacao@gmail.com"]
11
+
12
+ spec.summary = %q{Kamba Checkout}
13
+ spec.description = %q{A gem to generate signatures based on your Kamba secret Key to use Kamba Checkout Js.}
14
+ spec.homepage = "https://github.com/usekamba/kamba_checkout_ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.17"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
@@ -0,0 +1,13 @@
1
+ require "kamba_checkout/version"
2
+
3
+ module KambaCheckout
4
+ require 'time'
5
+ require 'json'
6
+ require 'digest'
7
+ require 'openssl'
8
+ require 'base64'
9
+
10
+ require 'kamba_checkout/model/response'
11
+ require 'kamba_checkout/api'
12
+ require 'kamba_checkout/config'
13
+ end
@@ -0,0 +1,22 @@
1
+ module KambaCheckout
2
+ class API
3
+ def self.generate_checkout(environment, checkout)
4
+ time = Time.now.httpdate
5
+ secret_key = KambaCheckout.secret_key
6
+
7
+ json_string = checkout.to_json
8
+ canonical_string = "POST,application/json,#{generate_md5(json_string)},#{'/v1/checkouts'},#{time}"
9
+ digest = OpenSSL::Digest.new('sha1')
10
+
11
+ hmac_signature = OpenSSL::HMAC.digest(digest, secret_key, canonical_string)
12
+ signature = Base64.strict_encode64(hmac_signature)
13
+ KambaCheckout::Response.new(environment, checkout, signature, time)
14
+ end
15
+
16
+ private
17
+
18
+ def self.generate_md5(checkout)
19
+ Digest::MD5.base64digest(checkout)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module KambaCheckout
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
+
11
+ def api_key=(key)
12
+ @api_key= key
13
+ end
14
+
15
+ def api_key
16
+ @api_key || ENV["KAMBA_API_KEY"]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module KambaCheckout
2
+ class Response
3
+ attr_accessor :signature, :time, :environment, :checkout_config, :api_key, :channel, :initial_amount, :notes, :redirect_url_success
4
+ def initialize(environment, checkout, signature, time)
5
+ @environment = environment
6
+ @channel = checkout['channel']
7
+ @initial_amount = checkout['initial_amount']
8
+ @notes = checkout['notes']
9
+ @redirect_url_success = checkout['redirect_url_success']
10
+ @signature = signature
11
+ @time = time
12
+ @api_key = KambaCheckout.api_key
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module KambaCheckout
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ describe 'KambaCheckout::API' do
2
+ describe 'Generating Signature' do
3
+ before(:each) do
4
+ @checkout = {
5
+ 'channel'=>'WEB',
6
+ 'initial_amount'=>5500,
7
+ 'notes'=> 'Alguma note exemplo.',
8
+ 'redirect_url_success'=> 'http://amarildolucas.com/curso/aplicativo-movel-com-swift/sucesso'
9
+ }
10
+ KambaCheckout.secret_key = '123'
11
+ end
12
+
13
+ it 'should generate signature' do
14
+ user = KambaCheckout::API.generate_signature('sandbox', @checkout)
15
+ user.time.should == Time.now.httpdate
16
+ user.signature.should_not == '123'
17
+ user.environment.should == 'sandbox'
18
+ user.checkout_config = @checkout.to_json
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'KambaCheckout' do
4
+ describe 'secret_key' do
5
+ before(:each) do
6
+ @default_secret_key = KambaCheckout.secret_key
7
+ KambaCheckout.secret_key = nil
8
+ ENV['KAMBA_SECRET_KEY'] = nil
9
+ end
10
+
11
+ after(:each) do
12
+ KambaCheckout.secret_key = @default_secret_key
13
+ KambaCheckout.api_key = @default_sec_key
14
+ end
15
+
16
+ it 'should set and read instance variable' do
17
+ KambaCheckout.secret_key = '123'
18
+ KambaCheckout.secret_key.should == '123'
19
+ end
20
+
21
+ it 'should fallback to ENV variable' do
22
+ ENV['KAMBA_SECRET_KEY'] = 'checkout'
23
+ KambaCheckout.secret_key.should == 'checkout'
24
+ end
25
+ end
26
+ describe 'api_key' do
27
+ before(:each) do
28
+ @default_api_key = KambaCheckout.api_key
29
+ KambaCheckout.api_key = nil
30
+ ENV['KAMBA_API_KEY'] = nil
31
+ end
32
+
33
+ after(:each) do
34
+ KambaCheckout.api_key = @default_api_key
35
+ end
36
+
37
+ it 'should set and read instance variable' do
38
+ KambaCheckout.api_key = '123'
39
+ KambaCheckout.api_key.should == '123'
40
+ end
41
+
42
+ it 'should fallback to ENV variable' do
43
+ ENV['KAMBA_API_KEY'] = 'checkout'
44
+ KambaCheckout.api_key.should == 'checkout'
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+ require "kamba_checkout"
3
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kamba_checkout
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-17 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 Kamba
56
+ Checkout Js.
57
+ email:
58
+ - hernaniprogramacao@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-version"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - kamba_checkout.gemspec
74
+ - lib/kamba_checkout.rb
75
+ - lib/kamba_checkout/api.rb
76
+ - lib/kamba_checkout/config.rb
77
+ - lib/kamba_checkout/model/response.rb
78
+ - lib/kamba_checkout/version.rb
79
+ - spec/api_spec.rb
80
+ - spec/config_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: https://github.com/usekamba/kamba_checkout_ruby
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.7.6
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Kamba Checkout
106
+ test_files: []