midas_client 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4fbb815f17bc12304c4c95d8675e1d70166beca
4
+ data.tar.gz: 8ee926b6500c6a2757590533805c88f7ce4f4b2f
5
+ SHA512:
6
+ metadata.gz: 3775df6365be00cefbc2833ac721721de07ec32e4c8816f7a0ff38f391440af42058b21092ae121b70ff72c775043f3dac0f152fde0c7d670cefaf4abde9c5af
7
+ data.tar.gz: c12116d971e535e5c9e3e772c5b13ea8682fd24f94cd309c785944d2811f75651ec2b87cf1e57affdadd578f04b97029b302c5fe2680047b03341dd6a39d7d10
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ .idea/
12
+ exe/
13
+ bin/
14
+
15
+ midas_client-*.gem
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ midas_client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.0.pre.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at coliveira@ansertecnologia.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in midas_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Carlos Andre Oliveira
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,50 @@
1
+ # MidasClient
2
+ Midas Client its a Ruby GEM that's allow user to send requests do Anser Payment API
3
+
4
+ [[https://ansertecnologia.atlassian.net/wiki/x/EYCyAg]]
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'midas_client'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install midas_client
21
+
22
+ ## Usage
23
+
24
+ Request
25
+
26
+ $ transaction = MidasClient::Transaction.new('pdv01','/eFRsg8RLne+I0GlECQofYvnsDfb0w==')
27
+ $ transaction.card_store({"externalId":"teste_midas_client_00002", "pan":"5529525900844124", "expirationMonth":"01", "expirationYear":"2021", "holderName":"TESTE MIDAS CLIENT", "customer":{ "documentType":"CPF", "documentNumber":"36549450152"}})
28
+
29
+ Response
30
+
31
+ $ [MIDAS_CLIENT][CALLER:request][17/05/2017 20:48:05.087]METHOD: post URL: https://sandbox.ansertecnologia.net/midas-core/v2/creditcard login: pdv01 password: /eFRsg8RLne+I0GlECQofYvnsDfb0w== payload: {:externalId=>"teste_midas_client_00002", :pan=>"552952@@@@@@4124", :expirationMonth=>"01", :expirationYear=>"2021", :holderName=>"TESTE MIDAS CLIENT", :customer=>{:documentType=>"CPF", :documentNumber=>"36549450152"}}
32
+ $ [MIDAS_CLIENT][CALLER:request][17/05/2017 20:48:06.103][RESPONSE] {:result=>{:success=>true, :code=>"010", :message=>"O cartao jah foi armazenado anteriormente"}, :brand=>"MASTER", :cardToken=>"f887d732863eb3ef2e45c0bd8b57ed33"}
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/midas_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
48
+ ## Code of Conduct
49
+
50
+ Everyone interacting in the MidasClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/midas_client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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,24 @@
1
+ default: &default
2
+ operations:
3
+ context: "/midas-core/v2"
4
+ store: "/creditcard"
5
+ synchronous_transaction: "/transaction/creditcard"
6
+ asynchronous_transaction: "/transaction/creditcard/dispatch"
7
+ authorize: "/transaction/creditcard/authorize"
8
+ confirm: "/transaction/creditcard/{transactionToken}/capture"
9
+ cancel: "/transaction/creditcard/{transactionToken}/cancel"
10
+ refund: "/transaction/creditcard/{transactionToken}/refund"
11
+ query_by_transaction: "/transaction/{transactionToken}"
12
+ callback: "http://matricula.crossfitlendarios.com.br/callback"
13
+ subscriptions:
14
+ context: "/midas-core/v2"
15
+ by_token: "/subscription/{subscriptionToken}"
16
+ invoices: "/subscription/{subscriptionToken}/invoices"
17
+ invoice_transactions: "/invoice/{invoiceToken}/transactions"
18
+ create: "/subscription/creditcard"
19
+ cancel: "/subscription/{subscriptionToken}/cancel"
20
+ callback: "https://matricula.crossfitlendarios.com.br/callback"
21
+ queries:
22
+ context: "/midas-query/v2"
23
+ by_period: "/transactions"
24
+ subscriptions: "/subscriptions"
@@ -0,0 +1,31 @@
1
+ config:
2
+ multiple_cards: false
3
+ delete_cards: false
4
+ cache_key: '%Y-%m-%d-%H:%M'
5
+ midas:
6
+ pos: "pdv01"
7
+ password: "/eFRsg8RLne+I0GlECQofYvnsDfb0w=="
8
+ url: "https://sandbox.ansertecnologia.net"
9
+ operations:
10
+ context: "/midas-core/v2"
11
+ store: "/creditcard"
12
+ synchronous_transaction: "/transaction/creditcard"
13
+ asynchronous_transaction: "/transaction/creditcard/dispatch"
14
+ authorize: "/transaction/creditcard/authorize"
15
+ confirm: "/transaction/creditcard/{transactionToken}/capture"
16
+ cancel: "/transaction/creditcard/{transactionToken}/cancel"
17
+ refund: "/transaction/creditcard/{transactionToken}/refund"
18
+ query_by_transaction: "/transaction/{transactionToken}"
19
+ callback: "http://matricula.crossfitlendarios.com.br/callback"
20
+ subscriptions:
21
+ context: "/midas-core/v2"
22
+ by_token: "/subscription/{subscriptionToken}"
23
+ invoices: "/subscription/{subscriptionToken}/invoices"
24
+ invoice_transactions: "/invoice/{invoiceToken}/transactions"
25
+ create: "/subscription/creditcard"
26
+ cancel: "/subscription/{subscriptionToken}/cancel"
27
+ callback: "https://matricula.crossfitlendarios.com.br/callback"
28
+ queries:
29
+ context: "/midas-query/v2"
30
+ by_period: "/transactions"
31
+ subscriptions: "/subscriptions"
@@ -0,0 +1,31 @@
1
+ config:
2
+ multiple_cards: false
3
+ delete_cards: false
4
+ cache_key: '%Y-%m-%d'
5
+ midas:
6
+ pos: "lendarios-01"
7
+ password: "b0FIYhr/xCvGFMuR1Wg059X/0cqwLg=="
8
+ url: "https://api.ansertecnologia.net"
9
+ operations:
10
+ context: "/midas-core/v2"
11
+ store: "/creditcard"
12
+ synchronous_transaction: "/transaction/creditcard"
13
+ asynchronous_transaction: "/transaction/creditcard/dispatch"
14
+ authorize: "/transaction/creditcard/authorize"
15
+ confirm: "/transaction/creditcard/{transactionToken}/capture"
16
+ cancel: "/transaction/creditcard/{transactionToken}/cancel"
17
+ refund: "/transaction/creditcard/{transactionToken}/refund"
18
+ query_by_transaction: "/transaction/{transactionToken}"
19
+ callback: "http://matricula.crossfitlendarios.com.br/callback"
20
+ subscriptions:
21
+ context: "/midas-core/v2"
22
+ by_token: "/subscription/{subscriptionToken}"
23
+ invoices: "/subscription/{subscriptionToken}/invoices"
24
+ invoice_transactions: "/invoice/{invoiceToken}/transactions"
25
+ create: "/subscription/creditcard"
26
+ cancel: "/subscription/{subscriptionToken}/cancel"
27
+ callback: "https://matricula.crossfitlendarios.com.br/callback"
28
+ queries:
29
+ context: "/midas-query/v2"
30
+ by_period: "/transactions"
31
+ subscriptions: "/subscriptions"
File without changes
@@ -0,0 +1,12 @@
1
+ require 'rest_client'
2
+ require "midas_client/version"
3
+ require "midas_client/util"
4
+ require "midas_client/endpoints"
5
+ require "midas_client/request"
6
+ require "midas_client/transaction"
7
+ require "midas_client/subscription"
8
+
9
+ module MidasClient
10
+ @@spec = Gem::Specification.find_by_name("midas_client")
11
+ @@gem_root = @@spec.gem_dir
12
+ end
@@ -0,0 +1,44 @@
1
+ module MidasClient
2
+ module EndPoints
3
+
4
+ def self.get_env
5
+ Rails.env == "production" ? Production : Development
6
+ end
7
+
8
+ Development ={
9
+ url: "https://sandbox.ansertecnologia.net",
10
+ context: "/midas-core/v2",
11
+ }
12
+
13
+ Production ={
14
+ url: "https://api.ansertecnologia.net",
15
+ context: "/midas-core/v2",
16
+ }
17
+
18
+ Operations = {
19
+ store: "/creditcard",
20
+ synchronous_transaction: "/transaction/creditcard",
21
+ asynchronous_transaction: "/transaction/creditcard/dispatch",
22
+ authorize: "/transaction/creditcard/authorize",
23
+ confirm: "/transaction/creditcard/{transactionToken}/capture",
24
+ cancel: "/transaction/creditcard/{transactionToken}/cancel",
25
+ refund: "/transaction/creditcard/{transactionToken}/refund",
26
+ query_by_transaction: "/transaction/{transactionToken}",
27
+ callback: "http://matricula.crossfitlendarios.com.br/callback",
28
+ }
29
+
30
+ Subscriptions = {
31
+ by_token: "/subscription/{subscriptionToken}",
32
+ invoices: "/subscription/{subscriptionToken}/invoices",
33
+ invoice_transactions: "/invoice/{invoiceToken}/transactions",
34
+ create: "/subscription/creditcard",
35
+ cancel: "/subscription/{subscriptionToken}/cancel",
36
+ callback: "https://matricula.crossfitlendarios.com.br/callback"
37
+ }
38
+
39
+ Queries = {
40
+ by_period: "/transactions",
41
+ subscriptions: "/subscriptions"
42
+ }
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ module MidasClient
2
+ class Queries < MidasClient::Request
3
+
4
+ include MidasClient::EndPoints
5
+
6
+ # This method performs a query by a range date.
7
+ # This is a is synchronous operation, using method GET
8
+ #
9
+ # Params:
10
+ # start_date: date format YYYY-MM-DD
11
+ # send_date: date format YYYY-MM-DD
12
+ #
13
+ #
14
+ # Response:
15
+ # result: {
16
+ # success: true/false
17
+ # code: "XXX"
18
+ # message: "Some message to you"
19
+ # }
20
+ def self.query_transaction_by_date(start_date=(Date.today() - 7).strftime("%Y-%m-%d"), end_date = Date.today().strftime("%Y-%m-%d"), status = nil)
21
+ # inicializa as variáveis de retorno
22
+ result ={}
23
+
24
+ # define o método de envio da requisição
25
+ method = :get
26
+
27
+ # monta a URL de chamada da requisição
28
+ endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Queries[:by_period].gsub("{transactionToken}", transaction_token)
29
+
30
+ # monta os parâmetros da requisição na url
31
+ if status.blank?
32
+ params = { startDate: start_date, endDate: end_date}
33
+ else
34
+ params = { startDate: start_date, endDate: end_date, status: status}
35
+ end
36
+ #endpoint= "#{endpoint}/#{transaction_token}"
37
+
38
+ # faz a chamada a plataforma de pagamento (MIDAS)
39
+ response = request(method, endpoint, self.login, self.password, params)
40
+
41
+ result = response[:result]
42
+ pagging = response[:pagging]
43
+ if response[:transactions].kind_of?(Array) || response[:transactions].blank?
44
+ transactions = response[:transactions]
45
+ else
46
+ transaction_array = []
47
+ transaction_array << response[:transactions]
48
+ transactions = transaction_array
49
+ end
50
+
51
+ return result, pagging, transactions
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,60 @@
1
+ module MidasClient
2
+ class Request
3
+ include Util
4
+ include RestClient
5
+
6
+ attr_accessor :login, :password
7
+
8
+ def initialize(login, password)
9
+ @login = login
10
+ @password = password
11
+ log("POS #{login} INITIALIZED!")
12
+ end
13
+
14
+
15
+ # Method that's wrap generic response
16
+ def base_result(success, code, message)
17
+ {
18
+ result: {
19
+ success: success,
20
+ code: code,
21
+ message: "#{message}"
22
+ }
23
+ }.to_hash
24
+
25
+ end
26
+
27
+ # Method that's wrap rest-client generic request
28
+ def request(method, endpoint, login, password, parameters, headers={content_type: :json, accept: :json})
29
+ # inicia a contagem da execução
30
+ start_time_execution = Time.now
31
+ log "METHOD: #{method} URL: #{endpoint} login: #{login} password: #{password} payload: #{self.sanitize_pci(parameters)}"
32
+ begin
33
+ response = RestClient::Request.execute(method: method,
34
+ url: endpoint,
35
+ user: login,
36
+ password: password,
37
+ content_type: :json,
38
+ ssl_version: :TLSv1_2,
39
+ payload: (parameters.to_json unless parameters.nil?),
40
+ headers: headers)
41
+ rescue => e
42
+ response = e.response || e
43
+ end
44
+
45
+ # parsing da resposta
46
+ begin
47
+ response = JSON.parse(response, symbolize_names: true )
48
+ rescue => e
49
+ error_log "METHOD: #{method} URL: #{endpoint} login: #{login} Mensagem: #{e.to_s}"
50
+ response = base_result(false, "999", "Operação não concluída. Motivo: #{e.to_s}")
51
+ ensure
52
+ total_time_execution = Time.now - start_time_execution
53
+ log "[RESPONSE] #{self.sanitize_pci(response)}"
54
+
55
+ log "Executado #{method} URL: #{endpoint} LOGIN: #{login} TEMPO: #{total_time_execution}s SUCCESS: #{response[:result][:success]}"
56
+ end
57
+ response
58
+ end
59
+ end
60
+ end