transbank-sdk 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Dockerfile +6 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.md +11 -0
  8. data/Makefile +24 -0
  9. data/README.md +87 -0
  10. data/Rakefile +10 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/docker-compose.yml +20 -0
  14. data/lib/transbank/sdk.rb +23 -0
  15. data/lib/transbank/sdk/onepay/base.rb +115 -0
  16. data/lib/transbank/sdk/onepay/errors/errors.rb +17 -0
  17. data/lib/transbank/sdk/onepay/errors/integration_type_error.rb +8 -0
  18. data/lib/transbank/sdk/onepay/errors/invalid_options_error.rb +8 -0
  19. data/lib/transbank/sdk/onepay/errors/item_error.rb +8 -0
  20. data/lib/transbank/sdk/onepay/errors/refund_create_error.rb +8 -0
  21. data/lib/transbank/sdk/onepay/errors/response_error.rb +8 -0
  22. data/lib/transbank/sdk/onepay/errors/shopping_cart_error.rb +8 -0
  23. data/lib/transbank/sdk/onepay/errors/signature_error.rb +8 -0
  24. data/lib/transbank/sdk/onepay/errors/transaction_commit_error.rb +8 -0
  25. data/lib/transbank/sdk/onepay/errors/transaction_create_error.rb +8 -0
  26. data/lib/transbank/sdk/onepay/errors/transbank_error.rb +9 -0
  27. data/lib/transbank/sdk/onepay/models/channels.rb +15 -0
  28. data/lib/transbank/sdk/onepay/models/item.rb +103 -0
  29. data/lib/transbank/sdk/onepay/models/models.rb +10 -0
  30. data/lib/transbank/sdk/onepay/models/refund.rb +51 -0
  31. data/lib/transbank/sdk/onepay/models/shopping_cart.rb +65 -0
  32. data/lib/transbank/sdk/onepay/models/transaction.rb +141 -0
  33. data/lib/transbank/sdk/onepay/requests/refund_create_request.rb +45 -0
  34. data/lib/transbank/sdk/onepay/requests/request.rb +18 -0
  35. data/lib/transbank/sdk/onepay/requests/requests.rb +9 -0
  36. data/lib/transbank/sdk/onepay/requests/transaction_commit_request.rb +48 -0
  37. data/lib/transbank/sdk/onepay/requests/transaction_create_request.rb +80 -0
  38. data/lib/transbank/sdk/onepay/responses/refund_create_response.rb +24 -0
  39. data/lib/transbank/sdk/onepay/responses/response.rb +18 -0
  40. data/lib/transbank/sdk/onepay/responses/responses.rb +9 -0
  41. data/lib/transbank/sdk/onepay/responses/transaction_commit_response.rb +39 -0
  42. data/lib/transbank/sdk/onepay/responses/transaction_create_response.rb +32 -0
  43. data/lib/transbank/sdk/onepay/utils/json_utils.rb +73 -0
  44. data/lib/transbank/sdk/onepay/utils/net_helper.rb +38 -0
  45. data/lib/transbank/sdk/onepay/utils/request_builder.rb +88 -0
  46. data/lib/transbank/sdk/onepay/utils/signature_utils.rb +49 -0
  47. data/lib/transbank/sdk/onepay/utils/utils.rb +9 -0
  48. data/lib/transbank/sdk/version.rb +5 -0
  49. data/sdk_test.sh +2 -0
  50. data/transbank-sdk.gemspec +33 -0
  51. metadata +220 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 89626d07ac2ab60c173d5559dbf0f80354f50a8d48ae376c49ed501c62bf2665
4
+ data.tar.gz: f06c90d4fda0552b151b386ac51ae8459a320200e71f99e31d09c9964153b51a
5
+ SHA512:
6
+ metadata.gz: a05375ec1dd0bf1add539335e9ea9adc74a86b52241ddfe25504aaaee53fe5d12402665045939ac3eb34c04ffeb158add6c1841eba115d7c33414cf5c8c0ae89
7
+ data.tar.gz: 85810e803d04a8c12d15cbcd7cdca8814cd897cc4e2f5e5ee515d08a927fca3d894fbb0cc0a13241c20d62e943330a4c33043536d7d7c99bfccfb606cb4474b3
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+ *.gem
11
+ Gemfile.lock
12
+ .built
13
+ .bundled
14
+
@@ -0,0 +1,8 @@
1
+ deploy:
2
+ provider: rubygems
3
+ api_key:
4
+ secure: DrUEm8pAjKtSekGBZz9/dMK92CSj2J+Zi1KOMLdDMckD4UCifusmbyqsp+RWAYBX1fWREyjMW0VvaPgj2eYOEaQrr6+TmygQMel1sFKSC6pOMVHQ3NMPwacVG5rGlNlK5+1PuNyR/ZGwtIdWkHe8+g9CvlvliNdY5KYtVs0pnwGUOMeQAwuIgM/w7uSm67zL7M3pYqEArU73EoX9puUS+k6aQ+KtxBckpqi7GtA5+42F8kTvEg+Y0h385qOvnQhjwepYh6YvfTeyzxc5fqFiBlO4TZp4rCoCpEeY1XO1VBCip+aGe5FVoWJrWkYONWdKV4GGzQd0Kd2Jmis4ieBDoi1julUK+uudy3CcjT3pSvSl6NyEpkUDJrJLZ9vn5P5SRJrUsWPDpkun5TptOnc1W1lgyJRypM47BbJ/qRzSr279iQmbvkEMci132Vp3v1Q17zDzBAyI13jirxNN4aw/PB0UCG7XRxqfEhnN391p1QVjB5u24G8r+gxABrJQA0WroKvQACstHd160wFWHxb57kSTaD32j3dzIbT+IdylF0ENmGQCohhUjwZt9ldv5cdQOyq0Jhsu9j8T/VzSRc52n1by1JQgl4nu4b7pmmNbfsEL6P13+m93TyKQiK0tr4CgdzF2XrY/bBJxoMvUTd2To4X77IRMayjkoZWEOT2RzrA=
5
+ gem: transbank-sdk
6
+ on:
7
+ tags: true
8
+ repo: TransbankDevelopers/transbank-sdk-ruby
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+ Todos los cambios notables a este proyecto serán documentados en este archivo.
3
+
4
+ El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.0.1]
8
+ ### Fixed
9
+ - Cambios para subir automáticamente la gema a RubyGems cuando se hace un nuevo release
10
+
11
+ ## [1.0.0] - 2018-10-23
12
+ ### Added
13
+ - Primer lanzamiento del SDK
@@ -0,0 +1,6 @@
1
+ FROM ruby:2.2-jessie
2
+ RUN apt-get update && apt-get install
3
+ RUN gem install bundler
4
+ RUN mkdir -p /sdk
5
+ WORKDIR /sdk
6
+ COPY . /sdk
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in transbank-sdk.gemspec
6
+ gemspec
@@ -0,0 +1,11 @@
1
+ Copyright 2018 Transbank
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,24 @@
1
+ SHELL := /bin/bash
2
+
3
+ all: build run
4
+
5
+ run: build
6
+ docker-compose run --rm web
7
+
8
+ build: .built .bundled
9
+
10
+ .built: Dockerfile
11
+ docker-compose build
12
+ touch .built
13
+
14
+ .bundled: Gemfile Gemfile.lock
15
+ docker-compose run --rm web bundle install
16
+ touch .bundled
17
+
18
+ logs:
19
+ docker-compose logs
20
+
21
+ clean:
22
+ docker-compose rm
23
+ rm .built
24
+ rm .bundled
@@ -0,0 +1,87 @@
1
+ # Transbank SDK Ruby
2
+
3
+ SDK Oficial de Transbank
4
+
5
+ ## Requisitos:
6
+
7
+ - Ruby 2.2+
8
+
9
+ # Instalación
10
+
11
+ Puedes instalar el SDK directamente
12
+ ```bash
13
+ gem install transbank-sdk
14
+ ```
15
+
16
+ o añadirlo a tu `Gemfile`
17
+ ```ruby
18
+ gem 'transbank-sdk'
19
+ ```
20
+ y luego ejecutar
21
+ ```bash
22
+ bundle install
23
+ ```
24
+ ## Documentación
25
+
26
+ Puedes encontrar toda la documentación de cómo usar este SDK en el sitio https://www.transbankdevelopers.cl.
27
+
28
+ Actualmente este SDK contiene sólo Onepay.
29
+
30
+ La documentación relevante para usar este SDK es:
31
+
32
+ - Documentación general sobre [Onepay](https://www.transbankdevelopers.cl/producto/onepay).
33
+ - Documentación sobre [ambientes, deberes del comercio, puesta en producción,
34
+ etc](https://www.transbankdevelopers.cl/documentacion/como_empezar#ambientes).
35
+ - Referencia detallada sobre [Onepay](https://www.transbankdevelopers.cl/referencia/onepay).
36
+
37
+ ## Información para contribuir y desarrollar este SDK
38
+
39
+ ### Requerimientos
40
+ - Docker
41
+ - Make
42
+ - Plugin de editorconfig para tu editor favorito.
43
+
44
+ ### Standares
45
+
46
+ - Para los commits respetamos las siguientes normas: https://chris.beams.io/posts/git-commit/
47
+ - Usamos ingles, para los mensajes de commit.
48
+ - Se pueden usar tokens como WIP, en el subject de un commit, separando el token con `:`, por ejemplo:
49
+ `WIP: This is a useful commit message`
50
+ - Para los nombres de ramas también usamos ingles.
51
+ - Se asume, que una rama de feature no mezclada, es un feature no terminado.
52
+ - El nombre de las ramas va en minúsculas.
53
+ - Las palabras se separan con `-`.
54
+ - Las ramas comienzan con alguno de los short lead tokens definidos, por ejemplo: `feat/tokens-configuration`
55
+
56
+ #### Short lead tokens
57
+ ##### Commits
58
+ - WIP = Trabajo en progreso.
59
+ ##### Ramas
60
+ - feat = Nuevos features
61
+ - chore = Tareas, que no son visibles al usuario.
62
+ - bug = Resolución de bugs.
63
+
64
+ ### Todas las mezclas a master se hacen mediante Pull Request.
65
+
66
+ ### Test
67
+ Primero y solamente una vez para instalar gemas debes usar el siguiente comando en una terminal.
68
+ ```bash
69
+ make build
70
+ ```
71
+
72
+ Para ejecutar los test localmente debes usar el siguiente comando en una terminal.
73
+ ```bash
74
+ make
75
+ ```
76
+
77
+ ### Deploy de una nueva versión.
78
+ Para generar una nueva versión, se debe crear un PR (con un título "Prepare release X.Y.Z" con los valores que correspondan para X, Y y Z). Se debe seguir el estándar semver para determinar si se incrementa el valor de X (si hay cambios no retrocompatibles), Y (para mejoras retrocompatibles) o Z (si sólo hubo correcciones a bugs).
79
+
80
+ En ese PR deben incluirse los siguientes cambios:
81
+
82
+ Modificar el archivo CHANGELOG.md para incluir una nueva entrada (al comienzo) para X.Y.Z que explique en español los cambios de cara al usuario del SDK.
83
+ Modificar este README.md para que los ejemplos usen la nueva versión X.Y.Z
84
+
85
+ Luego de obtener aprobación del pull request, debe mezclarse a master e inmediatamente generar un release en GitHub con el tag vX.Y.Z. En la descripción del release debes poner lo mismo que agregaste al changelog.
86
+
87
+ Con eso Travis CI generará automáticamente una nueva versión de la librería y la publicará en RubyGems.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "transbank/sdk"
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,20 @@
1
+ version: '2'
2
+ services:
3
+ web: &web
4
+ tty: true
5
+ stdin_open: true
6
+ build:
7
+ context: .
8
+ dockerfile: Dockerfile
9
+ command: rake test
10
+ volumes:
11
+ - .:/sdk
12
+ volumes_from:
13
+ - bundle_cache
14
+ ports:
15
+ - "8000:8000"
16
+
17
+ bundle_cache:
18
+ image: ruby:2.2-jessie # Should be the same as the app Dockerfile.dev base image
19
+ volumes:
20
+ - /usr/local/bundle
@@ -0,0 +1,23 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'base64'
6
+
7
+
8
+ require "transbank/sdk/version"
9
+
10
+ require 'transbank/sdk/onepay/errors/errors'
11
+
12
+ require 'transbank/sdk/onepay/utils/utils'
13
+
14
+ require 'transbank/sdk/onepay/requests/requests'
15
+ require 'transbank/sdk/onepay/responses/responses'
16
+
17
+ require 'transbank/sdk/onepay/models/models'
18
+ require 'transbank/sdk/onepay/base'
19
+
20
+ module Transbank
21
+ module Onepay
22
+ end
23
+ end
@@ -0,0 +1,115 @@
1
+ module Transbank
2
+ module Onepay
3
+ class Base
4
+ # The base class for Transbank Onepay
5
+ DEFAULT_CALLBACK = "http://no.callback.has/been.set".freeze
6
+ DEFAULT_API_KEY = 'dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw'.freeze
7
+ DEFAULT_SHARED_SECRET = '?XW#WOLG##FBAGEAYSNQ5APD#JF@$AYZ'.freeze
8
+
9
+ @app_keys = {TEST: '1a0c0639-bd2f-4846-8d26-81f43187e797',
10
+ LIVE: '2B571C49-C1B6-4AD1-9806-592AC68023B7',
11
+ MOCK: '04533c31-fe7e-43ed-bbc4-1c8ab1538afp'}.freeze
12
+ @integration_types = {TEST: 'https://onepay.ionix.cl'.freeze,
13
+ LIVE: 'https://www.onepay.cl'.freeze,
14
+ MOCK: 'https://transbank-onepay-ewallet-mock.herokuapp.com'.freeze}.freeze
15
+ @callback_url = self::DEFAULT_CALLBACK
16
+ @api_key = ENV['ONEPAY_API_KEY'].nil? ? DEFAULT_API_KEY : ENV['ONEPAY_API_KEY']
17
+ @shared_secret = ENV['ONEPAY_SHARED_SECRET'].nil? ? DEFAULT_SHARED_SECRET : ENV['ONEPAY_SHARED_SECRET']
18
+
19
+ @integration_type = :TEST
20
+ @app_scheme = nil
21
+ @default_channel = Transbank::Onepay::Channel::WEB
22
+
23
+ class << self
24
+ # Contains all valid integration types
25
+ # @return [Hash<String, String>]
26
+ attr_reader :integration_types
27
+
28
+ # Your Api key, given by Transbank
29
+ # @return [String]
30
+ attr_writer :api_key
31
+
32
+ # Your callback URL, used to resume the payment process after validating with
33
+ # Transbank when paying on Channel::MOBILE
34
+ # @param [String]
35
+ # @return [String]
36
+ attr_accessor :callback_url
37
+
38
+ # Your shared secret, given by Transbank
39
+ # @param [String]
40
+ # @return [String]
41
+ attr_writer :shared_secret
42
+
43
+ # The current integration type
44
+ # @param [String, Symbol]
45
+ # @return [Symbol]
46
+ attr_reader :integration_type
47
+
48
+ # The URI for the app (eg the Android Intent that starts the app/the iOS
49
+ # equivalent)
50
+ # @param [String]
51
+ # @return [String]
52
+ attr_writer :app_scheme
53
+
54
+ # The default channel. Value must be in Channel.values
55
+ # @return [String] One of the values from Channel.values
56
+ attr_reader :default_channel
57
+
58
+ # @return [String] the URL that is used by the current integration type
59
+ def current_integration_type_url
60
+ @integration_types[@integration_type]
61
+ end
62
+
63
+ # @return [String] the app key used by the current integration type
64
+ def current_integration_type_app_key
65
+ @app_keys[@integration_type]
66
+ end
67
+
68
+ # Sets the current integration type
69
+ # @param type [String] Type of integration to be set. Must be included one
70
+ # of the keys of self.integration_types
71
+ # @raise [IntegrationTypeError] if the given type is not valid
72
+ def integration_type=(type)
73
+ return @integration_type = type.to_sym unless @integration_types[type.to_sym].nil?
74
+ valid_values = @integration_types.keys.join(', ')
75
+ raise Transbank::Onepay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
76
+ end
77
+
78
+ # Returns the app_scheme
79
+ # @return [String] the app scheme, either the one set on @app_scheme or,
80
+ # failing that, the value of ENV['ONEPAY_APP_SCHEME'] (your env variable)
81
+ def app_scheme
82
+ return ENV['ONEPAY_APP_SCHEME'] unless @app_scheme
83
+ @app_scheme
84
+ end
85
+
86
+ def api_key
87
+ return ENV['ONEPAY_API_KEY'] if @api_key.nil?
88
+ @api_key
89
+ end
90
+
91
+ # Returns the 'ONEPAY_API_KEY' env variable, or, if ONEPAY_API_KEY
92
+ # doesn't exist, returns a default api key
93
+ # @return [String] ENV['ONEPAY_API_KEY] or DEFAULT_API_KEY
94
+ def default_api_key
95
+ env_api_key = ENV['ONEPAY_API_KEY']
96
+ env_api_key.nil? ? DEFAULT_API_KEY : env_api_key
97
+ end
98
+
99
+ def shared_secret
100
+ return ENV['ONEPAY_SHARED_SECRET'] if @shared_secret.nil?
101
+ @shared_secret
102
+ end
103
+
104
+ # Returns the 'ONEPAY_SHARED_SECRET' env variable, or, if ONEPAY_SHARED_SECRET
105
+ # doesn't exist, returns a default shared secret
106
+ # @return [String] ENV['ONEPAY_SHARED_SECRET'] or DEFAULT_SHARED_SECRET
107
+ def default_shared_secret
108
+ env_shared_secret = ENV['ONEPAY_SHARED_SECRET']
109
+ env_shared_secret.nil? ? DEFAULT_SHARED_SECRET : env_shared_secret
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,17 @@
1
+ require 'transbank/sdk/onepay/errors/transbank_error'
2
+ require 'transbank/sdk/onepay/errors/integration_type_error'
3
+ require 'transbank/sdk/onepay/errors/invalid_options_error'
4
+ require 'transbank/sdk/onepay/errors/item_error'
5
+ require 'transbank/sdk/onepay/errors/refund_create_error'
6
+ require 'transbank/sdk/onepay/errors/response_error'
7
+ require 'transbank/sdk/onepay/errors/shopping_cart_error'
8
+ require 'transbank/sdk/onepay/errors/signature_error'
9
+ require 'transbank/sdk/onepay/errors/transaction_commit_error'
10
+ require 'transbank/sdk/onepay/errors/transaction_create_error'
11
+
12
+ module Transbank
13
+ module Onepay
14
+ module Errors
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Transbank
2
+ module Onepay
3
+ module Errors
4
+ class IntegrationTypeError < TransbankError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Transbank
2
+ module Onepay
3
+ module Errors
4
+ class InvalidOptionsError < TransbankError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Transbank
2
+ module Onepay
3
+ module Errors
4
+ class ItemError < TransbankError
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Transbank
2
+ module Onepay
3
+ module Errors
4
+ class RefundCreateError < TransbankError
5
+ end
6
+ end
7
+ end
8
+ end