Skip to content

Commit

Permalink
Apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Jan 15, 2024
1 parent d898e5a commit 60b2e9e
Show file tree
Hide file tree
Showing 34 changed files with 484 additions and 383 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/gem_tasks'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new("spec")
task :default => :spec
task default: :spec
42 changes: 20 additions & 22 deletions datatrans.gemspec
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "datatrans/version"

Gem::Specification.new do |s|
s.name = "datatrans"
s.version = Datatrans::VERSION
s.authors = ["Tobias Miesel", "Thomas Maurer", "Corin Langosch", "Pascal Betz"]
s.email = ["[email protected]"]
s.homepage = ""
s.summary = %q{Datatrans Integration for Ruby on Rails}
s.description = %q{Datatrans Integration for Ruby on Rails}
s.name = "datatrans"
s.version = Datatrans::VERSION
s.authors = ["Tobias Miesel", "Thomas Maurer", "Corin Langosch", "Pascal Betz"]
s.email = ["[email protected]"]
s.homepage = ""
s.summary = "Datatrans Integration for Ruby on Rails"
s.description = "Datatrans Integration for Ruby on Rails"

s.rubyforge_project = "datatrans"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ["lib"]

s.required_ruby_version = '>= 2.6'
s.required_ruby_version = ">= 2.6"

s.add_dependency 'httparty'
s.add_dependency 'activesupport', '>= 5.2'
s.add_dependency 'i18n'
s.add_dependency 'builder'
s.add_dependency 'multi_xml', '>= 0.5.1'
s.add_dependency "httparty"
s.add_dependency "activesupport", ">= 5.2"
s.add_dependency "i18n"
s.add_dependency "builder"
s.add_dependency "multi_xml", ">= 0.5.1"

s.add_development_dependency 'actionpack', '>= 5.2'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.license = 'MIT'
s.add_development_dependency "actionpack", ">= 5.2"
s.add_development_dependency "appraisal"
s.add_development_dependency "rake"
s.add_development_dependency "rspec"
s.license = "MIT"
end
18 changes: 9 additions & 9 deletions lib/datatrans.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'active_support/core_ext/module'
require "active_support/core_ext/module"

module Datatrans
InvalidSignatureError = Class.new(StandardError)
end

require 'datatrans/version'
require 'datatrans/common'
require 'datatrans/config'
require 'datatrans/xml/transaction'
require 'datatrans/web/transaction'
require 'datatrans/json/transaction'
require "datatrans/version"
require "datatrans/common"
require "datatrans/config"
require "datatrans/xml/transaction"
require "datatrans/web/transaction"
require "datatrans/json/transaction"

begin
require 'action_view'
require 'datatrans/web/view_helper'
require "action_view"
require "datatrans/web/view_helper"
ActionView::Base.send(:include, Datatrans::Web::ViewHelper)
rescue LoadError
end
10 changes: 5 additions & 5 deletions lib/datatrans/common.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'openssl'
require "openssl"

module Datatrans::Common
def sign(*fields)
return nil unless self.datatrans.sign_key
key = self.datatrans.sign_key.split(/([a-f0-9][a-f0-9])/).reject(&:empty?)
return nil unless datatrans.sign_key
key = datatrans.sign_key.split(/([a-f0-9][a-f0-9])/).reject(&:empty?)
key = key.pack("H*" * key.size)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::MD5.new, key, fields.join)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("MD5"), key, fields.join)
end
end
end
22 changes: 11 additions & 11 deletions lib/datatrans/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Config
DEFAULT_SIGN_KEY = false

SUBDOMAINS = {
payment_page: 'pay',
server_to_server_api: 'api'
payment_page: "pay",
server_to_server_api: "api"
}
DOMAIN = 'datatrans.com'
DOMAIN = "datatrans.com"

attr_reader :environment, :merchant_id, :sign_key, :password, :proxy

Expand All @@ -21,10 +21,10 @@ class Config
# * :proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass)
def initialize(options = {})
@merchant_id = options[:merchant_id]
raise ArgumentError.new(":merchant_id is required") unless self.merchant_id
raise ArgumentError.new(":merchant_id is required") unless merchant_id
self.environment = options[:environment] || DEFAULT_ENVIRONMENT
@password = options[:password]
raise ArgumentError.new(":password is required") unless self.password
raise ArgumentError.new(":password is required") unless password
@sign_key = options[:sign_key] || DEFAULT_SIGN_KEY
@proxy = options[:proxy] || {}
end
Expand All @@ -34,7 +34,7 @@ def environment=(environment)
if ENVIRONMENTS.include?(environment)
@environment = environment
else
raise "Unknown environment '#{environment}'. Available: #{ENVIRONMENTS.join(', ')}"
raise "Unknown environment '#{environment}'. Available: #{ENVIRONMENTS.join(", ")}"
end
end

Expand All @@ -43,16 +43,16 @@ def url(what, options = {})
case what
when :web_authorize_url
subdomain = SUBDOMAINS[:payment_page]
path = '/upp/jsp/upStart.jsp'
path = "/upp/jsp/upStart.jsp"
when :xml_authorize_url
subdomain = SUBDOMAINS[:server_to_server_api]
path = '/upp/jsp/XML_authorize.jsp'
path = "/upp/jsp/XML_authorize.jsp"
when :xml_settlement_url
subdomain = SUBDOMAINS[:server_to_server_api]
path = '/upp/jsp/XML_processor.jsp'
path = "/upp/jsp/XML_processor.jsp"
when :xml_status_url
subdomain = SUBDOMAINS[:server_to_server_api]
path = '/upp/jsp/XML_status.jsp'
path = "/upp/jsp/XML_status.jsp"
when :init_transaction
subdomain = SUBDOMAINS[:server_to_server_api]
path = "/v1/transactions"
Expand All @@ -73,7 +73,7 @@ def url(what, options = {})
else
raise "Unknown wanted action '#{what}'."
end
subdomain += '.sandbox' unless self.environment == :production
subdomain += ".sandbox" unless environment == :production
"https://#{subdomain}.#{DOMAIN}#{path}"
end

Expand Down
28 changes: 14 additions & 14 deletions lib/datatrans/json/transaction.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'active_support/core_ext/hash'
require "active_support/core_ext/hash"

module Datatrans::JSON
class Transaction
Expand All @@ -11,36 +11,36 @@ def initialize(datatrans, params)
end

def authorize
self.request = Authorize.new(self.datatrans, params)
@response = AuthorizeResponse.new(self.datatrans, request.process)
self.request = Authorize.new(datatrans, params)
@response = AuthorizeResponse.new(datatrans, request.process)
@response.successful?
end

def merchant_authorize
self.request = MerchantAuthorize.new(self.datatrans, params)
@response = MerchantAuthorizeResponse.new(self.datatrans, request.process)
self.request = MerchantAuthorize.new(datatrans, params)
@response = MerchantAuthorizeResponse.new(datatrans, request.process)
@response.successful?
end

def status
self.request = Status.new(self.datatrans, params)
@response = StatusResponse.new(self.datatrans, request.process)
self.request = Status.new(datatrans, params)
@response = StatusResponse.new(datatrans, request.process)
@response.successful?
end

def settle
self.request = Settle.new(self.datatrans, params)
@response = SettleResponse.new(self.datatrans, request.process)
self.request = Settle.new(datatrans, params)
@response = SettleResponse.new(datatrans, request.process)
@response.successful?
end

def transaction_path
self.datatrans.url(:start_json_transaction, transaction_id: params[:transaction_id])
datatrans.url(:start_json_transaction, transaction_id: params[:transaction_id])
end
end
end

require 'datatrans/json/transaction/authorize'
require 'datatrans/json/transaction/merchant_authorize'
require 'datatrans/json/transaction/status'
require 'datatrans/json/transaction/settle'
require "datatrans/json/transaction/authorize"
require "datatrans/json/transaction/merchant_authorize"
require "datatrans/json/transaction/status"
require "datatrans/json/transaction/settle"
32 changes: 16 additions & 16 deletions lib/datatrans/json/transaction/authorize.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'httparty'
require 'datatrans/json/transaction/response'
require "httparty"
require "datatrans/json/transaction/response"

class Datatrans::JSON::Transaction
class Authorize
Expand All @@ -13,30 +13,30 @@ def initialize(datatrans, params)

def post(url, options = {})
options = options
.merge(self.datatrans.proxy)
.merge(:basic_auth => { :username => self.datatrans.merchant_id, :password => self.datatrans.password })
.merge(datatrans.proxy)
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
HTTParty.post(url, **options)
end

def process
post(self.datatrans.url(:init_transaction),
:headers => { 'Content-Type' => 'application/json' },
:body => request_body.to_json).parsed_response
post(datatrans.url(:init_transaction),
headers: {"Content-Type" => "application/json"},
body: request_body.to_json).parsed_response
end

def request_body
auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]

body = {
"currency": params[:currency],
"refno": params[:refno],
"amount": params[:amount],
"autoSettle": auto_settle,
"paymentMethods": params[:payment_methods],
"redirect": {
"successUrl": params[:success_url],
"cancelUrl": params[:cancel_url],
"errorUrl": params[:error_url]
currency: params[:currency],
refno: params[:refno],
amount: params[:amount],
autoSettle: auto_settle,
paymentMethods: params[:payment_methods],
redirect: {
successUrl: params[:success_url],
cancelUrl: params[:cancel_url],
errorUrl: params[:error_url]
}
}

Expand Down
24 changes: 12 additions & 12 deletions lib/datatrans/json/transaction/merchant_authorize.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'httparty'
require 'datatrans/json/transaction/response'
require "httparty"
require "datatrans/json/transaction/response"

class Datatrans::JSON::Transaction
class MerchantAuthorize
Expand All @@ -13,26 +13,26 @@ def initialize(datatrans, params)

def post(url, options = {})
options = options
.merge(self.datatrans.proxy)
.merge(:basic_auth => { :username => self.datatrans.merchant_id, :password => self.datatrans.password })
.merge(datatrans.proxy)
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
HTTParty.post(url, **options)
end

def process
post(self.datatrans.url(:authorize_transaction),
:headers => { 'Content-Type' => 'application/json' },
:body => request_body.to_json).parsed_response
post(datatrans.url(:authorize_transaction),
headers: {"Content-Type" => "application/json"},
body: request_body.to_json).parsed_response
end

def request_body
auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]

{
"currency": params[:currency],
"refno": params[:refno],
"amount": params[:amount],
"card": params[:card],
"autoSettle": auto_settle,
currency: params[:currency],
refno: params[:refno],
amount: params[:amount],
card: params[:card],
autoSettle: auto_settle
}
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/datatrans/json/transaction/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ def initialize(datatrans, params)
end

def successful?
raise 'overwrite in subclass!'
raise "overwrite in subclass!"
end

def error_code
params["error"]["code"] rescue nil
params["error"]["code"]
rescue
nil
end

def error_message
params["error"]["message"] rescue nil
params["error"]["message"]
rescue
nil
end
end
end
20 changes: 10 additions & 10 deletions lib/datatrans/json/transaction/settle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'httparty'
require 'datatrans/json/transaction/response'
require "httparty"
require "datatrans/json/transaction/response"

class Datatrans::JSON::Transaction
class Settle
Expand All @@ -13,22 +13,22 @@ def initialize(datatrans, params)

def post(url, options = {})
options = options
.merge(self.datatrans.proxy)
.merge(:basic_auth => { :username => self.datatrans.merchant_id, :password => self.datatrans.password })
.merge(datatrans.proxy)
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
HTTParty.post(url, **options)
end

def process
post(self.datatrans.url(:json_settle_url, transaction_id: params[:transaction_id]),
:headers => { 'Content-Type' => 'application/json' },
:body => request_body.to_json).parsed_response
post(datatrans.url(:json_settle_url, transaction_id: params[:transaction_id]),
headers: {"Content-Type" => "application/json"},
body: request_body.to_json).parsed_response
end

def request_body
{
"currency": params[:currency],
"amount": params[:amount],
"refno": params[:refno]
currency: params[:currency],
amount: params[:amount],
refno: params[:refno]
}
end
end
Expand Down
Loading

0 comments on commit 60b2e9e

Please sign in to comment.