Skip to content

Commit

Permalink
fixing rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Sambari committed Dec 15, 2019
1 parent c09881e commit 6d098b3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 99 deletions.
56 changes: 28 additions & 28 deletions lib/active_merchant/billing/gateways/tsys_multipass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class TsysMultipassGateway < Gateway
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club]

EMPTY_OBJ = {}
BLANK = ""
CONTENT_TYPE = "application/json"
BLANK = ''
CONTENT_TYPE = 'application/json'

WHITELISTED_RESPONSE_ROOT_KEYS = %w(
SaleResponse
AuthResponse
CaptureResponse
VoidResponse
ReturnResponse
SaleResponse
AuthResponse
CaptureResponse
VoidResponse
ReturnResponse
)

attr_reader :response, :parsed_body
Expand Down Expand Up @@ -67,12 +67,12 @@ def supports_scrubbing?
end

def scrub(transcript)
transcript
.gsub(/\"deviceID\":\K(?:(?!,).)*/, '[FILTERED]')
.gsub(/\"transactionKey\":\K(?:(?!,).)*/, '[FILTERED]')
.gsub(/\"cardNumber\":\K(?:(?!,).)*/, '[FILTERED]')
.gsub(/\"expirationDate\":\K(?:(?!,).)*/, '[FILTERED]')
.gsub(/\"token\":\K(?:(?!,).)*/, '[FILTERED]')
transcript.
gsub(/\"deviceID\":\K(?:(?!,).)*/, '[FILTERED]').
gsub(/\"transactionKey\":\K(?:(?!,).)*/, '[FILTERED]').
gsub(/\"cardNumber\":\K(?:(?!,).)*/, '[FILTERED]').
gsub(/\"expirationDate\":\K(?:(?!,).)*/, '[FILTERED]').
gsub(/\"token\":\K(?:(?!,).)*/, '[FILTERED]')
end

private
Expand All @@ -84,8 +84,8 @@ def request_params(options)
}.merge!(options)
end

def commit(request_body: )
@response =
def commit(request_body:)
@response =
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
request = Net::HTTP::Post.new(uri, {'Content-Type' => CONTENT_TYPE })
request.body = request_body
Expand All @@ -110,19 +110,19 @@ def commit(request_body: )
def success?
return false unless recognized_response_root_key?

parsed_body_root_value["status"] == "PASS"
parsed_body_root_value['status'] == 'PASS'
end

def message
return BLANK unless recognized_response_root_key?

parsed_body_root_value["responseMessage"]
parsed_body_root_value['responseMessage']
end

def error_code
return BLANK unless error?
return BLANK unless error?

response_code
response_code
end

def error?
Expand All @@ -132,30 +132,30 @@ def error?
def response_code
return BLANK unless recognized_response_root_key?

parsed_body_root_value["responseCode"]
parsed_body_root_value['responseCode']
end

def authorization
return BLANK unless recognized_response_root_key?

parsed_body_root_value["transactionID"]
parsed_body_root_value['transactionID']
end

def amount
return BLANK unless recognized_response_root_key?

parsed_body_root_value[ amount_key_mapping[parsed_body_root_key] ]
parsed_body_root_value[amount_key_mapping[parsed_body_root_key]]
end

# This method gives us mapping of which amount field to
# This method gives us mapping of which amount field to
# fetch based on the transaction response types.
def amount_key_mapping
{
"SaleResponse" => "processedAmount",
"AuthResponse" => "processedAmount",
"CaptureResponse" => "transactionAmount",
"VoidResponse" => "voidedAmount",
"ReturnResponse" => "returnedAmount"
'SaleResponse' => 'processedAmount',
'AuthResponse' => 'processedAmount',
'CaptureResponse' => 'transactionAmount',
'VoidResponse' => 'voidedAmount',
'ReturnResponse' => 'returnedAmount'
}
end

Expand Down
112 changes: 56 additions & 56 deletions test/remote/gateways/remote_tsys_multipass_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ def setup
@expiration_date = @fixtures[:card][:expiration_date]

@gateway = TsysMultipassGateway.new(
device_id: @fixtures[:device_id],
device_id: @fixtures[:device_id],
transaction_key: @fixtures[:transaction_key]
)
end

def test_successful_purchase
purchase_options = {
cardDataSource: "INTERNET",
transactionAmount: "100",
cardDataSource: 'INTERNET',
transactionAmount: '100',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

response = @gateway.purchase("100", @card_token, purchase_options)
response = @gateway.purchase('100', @card_token, purchase_options)

assert_equal true, response.success?
assert_equal "100", response.amount
assert_equal '100', response.amount
assert_equal '', response.error_code
assert_instance_of Response, response
end

def test_failed_purchase
purchase_options = {
cardDataSource: "INTERNET",
transactionAmount: "101",
cardDataSource: 'INTERNET',
transactionAmount: '101',
cardNumber: @card_token,
expirationDate: "INVALID VALUE"
expirationDate: 'INVALID VALUE'
}

response = @gateway.purchase("102", @card_token, purchase_options)
response = @gateway.purchase('102', @card_token, purchase_options)

assert_equal false, response.success?
assert_equal nil, response.authorization
Expand All @@ -47,29 +47,29 @@ def test_failed_purchase

def test_successful_authorize
auth_options = {
cardDataSource: "INTERNET",
transactionAmount: "103",
cardDataSource: 'INTERNET',
transactionAmount: '103',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

response = @gateway.authorize("103", @card_token, auth_options)
response = @gateway.authorize('103', @card_token, auth_options)

assert_equal true, response.success?
assert_equal "103", response.amount
assert_equal '103', response.amount
assert_equal '', response.error_code
assert_instance_of Response, response
end

def test_failed_authorize
auth_options = {
cardDataSource: "INTERNET",
transactionAmount: "104",
cardDataSource: 'INTERNET',
transactionAmount: '104',
cardNumber: @card_token,
expirationDate: "INVALID VALUE"
expirationDate: 'INVALID VALUE'
}

response = @gateway.authorize("104", @card_token, auth_options)
response = @gateway.authorize('104', @card_token, auth_options)

assert_equal false, response.success?
assert_equal nil, response.amount
Expand All @@ -80,124 +80,124 @@ def test_failed_authorize
def test_successful_capture
# Authorize first
auth_options = {
cardDataSource: "INTERNET",
transactionAmount: "105",
cardDataSource: 'INTERNET',
transactionAmount: '105',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

auth_id = @gateway.authorize("105", @card_token, auth_options).authorization
auth_id = @gateway.authorize('105', @card_token, auth_options).authorization

capture_options = {
transactionAmount: "105",
transactionAmount: '105',
transactionID: auth_id
}

response = @gateway.capture("105", @card_token, capture_options)
response = @gateway.capture('105', @card_token, capture_options)

assert_equal true, response.success?
assert_equal "105", response.amount
assert_equal "", response.error_code
assert_equal '105', response.amount
assert_equal '', response.error_code
assert_instance_of Response, response
end

def test_failed_capture
capture_options = {
transactionAmount: "106",
transactionID: "invalidtransactionid"
transactionAmount: '106',
transactionID: 'invalidtransactionid'
}

response = @gateway.capture("106", @card_token, capture_options)
response = @gateway.capture('106', @card_token, capture_options)

assert_equal false, response.success?
assert_equal nil, response.amount
assert_equal "F9901", response.error_code
assert_equal 'F9901', response.error_code
assert_instance_of Response, response
end

def test_successful_void
# Authorize first
auth_options = {
cardDataSource: "INTERNET",
transactionAmount: "107",
cardDataSource: 'INTERNET',
transactionAmount: '107',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

auth_id = @gateway.authorize("107", @card_token, auth_options).authorization
auth_id = @gateway.authorize('107', @card_token, auth_options).authorization

void_options = {
transactionAmount: "107",
transactionAmount: '107',
transactionID: auth_id
}

response = @gateway.void(@card_token, void_options)

assert_equal true, response.success?
assert_equal "107", response.amount
assert_equal "", response.error_code
assert_equal '107', response.amount
assert_equal '', response.error_code
assert_instance_of Response, response
end

def test_failed_void
void_options = {
transactionAmount: "108" ,
transactionID: "invalid auth id"
transactionAmount: '108',
transactionID: 'invalid auth id'
}

response = @gateway.void(@card_token, void_options)

assert_equal false, response.success?
assert_equal nil, response.amount
assert_equal "F9901", response.error_code
assert_equal 'F9901', response.error_code
assert_instance_of Response, response
end

def test_successful_refund
# Authorize first
auth_options = {
cardDataSource: "INTERNET",
transactionAmount: "109",
cardDataSource: 'INTERNET',
transactionAmount: '109',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

auth_id = @gateway.authorize("109", @card_token, auth_options).authorization
auth_id = @gateway.authorize('109', @card_token, auth_options).authorization

refund_options = {
transactionAmount: "109",
transactionAmount: '109',
transactionID: auth_id
}

response = @gateway.refund("109", @card_token, refund_options)
response = @gateway.refund('109', @card_token, refund_options)

assert_equal true, response.success?
assert_equal "109", response.amount
assert_equal "", response.error_code
assert_equal '109', response.amount
assert_equal '', response.error_code
assert_instance_of Response, response
end

def test_failed_refund
# Authorize first
purchase_options = {
cardDataSource: "INTERNET",
transactionAmount: "110",
cardDataSource: 'INTERNET',
transactionAmount: '110',
cardNumber: @card_token,
expirationDate: @expiration_date
expirationDate: @expiration_date
}

auth_id = @gateway.purchase("110", @card_token, purchase_options).authorization
auth_id = @gateway.purchase('110', @card_token, purchase_options).authorization

refund_options = {
transactionAmount: "10000", # More amount than purchased
transactionAmount: '10000', # More amount than purchased
transactionID: auth_id
}

response = @gateway.refund("10000", @card_token, refund_options)
response = @gateway.refund('10000', @card_token, refund_options)

assert_equal false, response.success?
assert_equal nil, response.amount
assert_equal "D0005", response.error_code
assert_equal 'D0005', response.error_code
assert_instance_of Response, response
end

Expand Down
Loading

0 comments on commit 6d098b3

Please sign in to comment.