Skip to content

Commit

Permalink
Add settlement search
Browse files Browse the repository at this point in the history
  • Loading branch information
incarnate committed Mar 1, 2016
1 parent e104a73 commit 9347d43
Show file tree
Hide file tree
Showing 21 changed files with 533 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes will be documented in this file

## 1.1.0

- Add settlement search support

## 1.0.1

- Fix for endpoint names ('production' & 'sandbox') not working
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)

Copyright (c) 2015 Web Active Corporation Pty Ltd
Copyright (c) 2015-2016 Web Active Corporation Pty Ltd

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions lib/eway_rapid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'query_customer_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'query_transaction_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'refund_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'settlement_search_response')

require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'cancel_authorisation_request')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'cancel_authorisation_response')
Expand All @@ -34,12 +35,15 @@
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_payment_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_refund_request')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_refund_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_settlement_search_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'transaction_search_response')

require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'customer_to_internal_customer')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'direct_payment_to_trans_status')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'direct_refund_to_trans_status')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_customer_to_customer')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_settlement_to_settlement')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_summary_to_summary')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_trans_to_trans')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_transaction_to_address')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_transaction_to_status')
Expand Down Expand Up @@ -67,6 +71,7 @@
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_payment_to_create_cust')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_payment_to_create_trans')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_refund_to_refund_response')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_settlement_to_settlement')
require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'search_to_query_trans')

require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'process', 'rest_process')
Expand Down
19 changes: 19 additions & 0 deletions lib/eway_rapid/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ module Constants
CUSTOMER_VIEW = 'CustomView'
VERIFY_CUSTOMER_PHONE = 'VerifyCustomerPhone'
VERIFY_CUSTOMER_EMAIL = 'VerifyCustomerEmail'
SETTLEMENT_SUMMARIES = 'SettlementSummaries'
SETTLEMENT_TRANSACTIONS = 'SettlementTransactions'
SETTLEMENT_ID = 'SettlementID'
CURRENCY = 'Currency'
TOTAL_CREDIT = 'TotalCredit'
TOTAL_DEBIT = 'TotalDebit'
TOTAL_BALANCE = 'TotalBalance'
BALANCE_PER_CARD_TYPE = 'BalancePerCardType'
CARD_TYPE = 'CardType'
NUMBER_OF_TRANSACTIONS = 'NumberOfTransactions'
CREDIT = 'Credit'
DEBIT = 'Debit'
BALANCE = 'Balance'
EWAY_CUSTOMER_ID = 'eWAYCustomerID'
TXN_REFERENCE = 'TxnReference'
AMOUNT = 'Amount'
TRANSACTION_DATE = 'TransactionDateTime'
SETTLEMENT_DATE = 'SettlementDateTime'
JSON_SUFFIX = '.json'
LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE = 'S9990'
API_KEY_INVALID_ERROR_CODE = 'S9991'
Expand Down Expand Up @@ -122,5 +140,6 @@ module Constants
TRANSACTION_QUERY_WITH_INVOICE_REF_METHOD = 'InvoiceRef'
REFUND_SUB_PATH_METHOD = 'Refund'
CAPTURE_PAYMENT_METHOD = 'CapturePayment'
SETTLEMENT_SEARCH_METHOD = 'Search/Settlement?'
end
end
26 changes: 26 additions & 0 deletions lib/eway_rapid/entities/direct_settlement_search_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module EwayRapid
class DirectSettlementSearchResponse
attr_accessor :settlement_summaries
attr_accessor :settlement_transactions
attr_accessor :error

def to_json(summaries={}, transactions={})
{Constants::SETTLEMENT_SUMMARIES => summaries,
Constants::SETTLEMENT_TRANSACTIONS => transactions,
Constants::ERRORS_CAPITALIZED => error}.to_json
end

def self.from_json(json)
hash = JSON.parse(json)
from_hash(hash)
end

def self.from_hash(hash)
settlement_search_response = DirectSettlementSearchResponse.new
settlement_search_response.settlement_summaries = InternalModels::SettlementSummary.from_array(hash[Constants::SETTLEMENT_SUMMARIES])
settlement_search_response.settlement_transactions = InternalModels::SettlementTransaction.from_array(hash[Constants::SETTLEMENT_TRANSACTIONS])
settlement_search_response.error = hash[Constants::ERRORS_CAPITALIZED]
settlement_search_response
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module EwayRapid
module Message
module Convert
class InternalSettlementToSettlement

# @param [InternalModels::SettlementTransaction] i_settlement
# @return [Models::SettlementTransaction]
def do_convert(i_settlement)
settlement = Models::SettlementTransaction.new
settlement.settlement_id = i_settlement.settlement_id
settlement.eway_customer_id = i_settlement.eway_customer_id
settlement.currency = i_settlement.currency
settlement.currency_code = i_settlement.transaction_id
settlement.transaction_id = i_settlement.transaction_id
settlement.txn_reference = i_settlement.txn_reference
settlement.card_type = i_settlement.card_type
settlement.amount = i_settlement.amount
settlement.transaction_type = i_settlement.transaction_type
settlement.transaction_date = Time.at(i_settlement.transaction_date.delete('^0-9').to_i / 1000.0 )
settlement.settlement_date = Time.at(i_settlement.settlement_date.delete('^0-9').to_i / 1000.0 )
settlement
end

end
end
end
end
39 changes: 39 additions & 0 deletions lib/eway_rapid/message/convert/internal_summary_to_summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module EwayRapid
module Message
module Convert
class InternalSummaryToSummary

# @param [InternalModels::SettlementSummary] i_summary
# @return [Models::SettlementSummary]
def do_convert(i_summary)
summary = Models::SettlementSummary.new
summary.settlement_id = i_summary.settlement_id
summary.currency = i_summary.currency
summary.currency_code = i_summary.currency_code
summary.total_credit = i_summary.total_credit
summary.total_debit = i_summary.total_debit
summary.total_balance = i_summary.total_balance
summary.balance_per_card_type = []
i_summary.balance_per_card_type.each {|balance|
obj = get_balance(balance)
summary.balance_per_card_type.push(obj)
}
summary
end

# @param [InternalModels::BalancePerCardType] i_balance
# @return [Models::BalancePerCardType]
def get_balance(i_balance)
balance = Models::BalancePerCardType.new
balance.card_type = i_balance.card_type
balance.number_of_transactions = i_balance.number_of_transactions
balance.credit = i_balance.credit
balance.debit = i_balance.debit
balance.balance = i_balance.balance
balance
end

end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module EwayRapid
module Message
module Convert
module Response
class DirectSettlementToSettlement

# @param [DirectSettlementSearchResponse] response
# @return [SettlementSearchResponse]
def do_convert(response)
settlement_search_response = SettlementSearchResponse.new

if response.settlement_summaries && response.settlement_summaries.length > 0
summary_convert = InternalSummaryToSummary.new
settlement_search_response.settlement_summaries = []
response.settlement_summaries.each {|summary|
obj = summary_convert.do_convert(summary)
settlement_search_response.settlement_summaries.push(obj)
}
end

if response.settlement_transactions && response.settlement_summaries.length > 0
settlement_convert = InternalSettlementToSettlement.new
settlement_search_response.settlement_transactions = []
response.settlement_transactions.each {|transaction|
obj = settlement_convert.do_convert(transaction)
settlement_search_response.settlement_transactions.push(obj)
}
end

settlement_search_response.errors = response.error.split(/\s*,\s*/) if response.error

settlement_search_response
end
end
end
end
end
end
24 changes: 24 additions & 0 deletions lib/eway_rapid/message/process/transaction_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ def self.make_result(response)
converter.do_convert(transaction_search_resp)
end
end

# Settlement search message process
class SettlementSearchMsgProcess
include RestProcess

def self.create_request(input)
hash = {}
input.instance_variables.map do |var|
hash[var.to_s.delete('@').split('_').collect(&:capitalize).join] = input.instance_variable_get(var)
end

URI.encode_www_form(hash)
end

def self.send_request(url, api_key, password)
SettlementSearchMsgProcess.new.do_get(url, api_key, password)
end

def self.make_result(response)
settlement_search_resp = DirectSettlementSearchResponse.from_json(response)
converter = Convert::Response::DirectSettlementToSettlement.new
converter.do_convert(settlement_search_resp)
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/eway_rapid/models/enums.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,19 @@ def self.calculate_status(index)
end
end
end

class CardType
ALL = 'ALL'
VISA = 'VI'
MASTERCARD = 'MC'
AMEX = 'AX'
DINERS = 'DC'
JCB = 'JC'
MAESTRO_UK = 'MD'
MAESTRO_INTERNATIONAL = 'MI'
SOLO = 'SO'
LASER = 'LA'
DISCOVER = 'DS'
end
end
end
112 changes: 112 additions & 0 deletions lib/eway_rapid/models/internal_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,117 @@ def self.from_hash(hash)
verification
end
end

class SettlementSummary
attr_accessor :settlement_id
attr_accessor :currency
attr_accessor :currency_code
attr_accessor :total_credit
attr_accessor :total_debit
attr_accessor :total_balance
attr_accessor :balance_per_card_type

def self.from_json(json)
hash = JSON.parse(json)
from_hash(hash)
end

def self.from_hash(hash)
settlement_summary = SettlementSummary.new
settlement_summary.settlement_id = hash[Constants::SETTLEMENT_ID]
settlement_summary.currency = hash[Constants::CURRENCY]
settlement_summary.currency_code = hash[Constants::CURRENCY_CODE]
settlement_summary.total_credit = hash[Constants::TOTAL_CREDIT]
settlement_summary.total_debit = hash[Constants::TOTAL_DEBIT]
settlement_summary.total_balance = hash[Constants::TOTAL_BALANCE]
settlement_summary.balance_per_card_type = BalancePerCardType.from_array(hash[Constants::BALANCE_PER_CARD_TYPE])
settlement_summary
end

def self.from_array(array)
summaries = []
array.each {|summary_hash|
obj = from_hash(summary_hash)
summaries.push(obj)
}
summaries
end
end

class BalancePerCardType
attr_accessor :card_type
attr_accessor :number_of_transactions
attr_accessor :credit
attr_accessor :debit
attr_accessor :balance

def self.from_json(json)
hash = JSON.parse(json)
from_hash(hash)
end

def self.from_hash(hash)
balance = BalancePerCardType.new
balance.card_type = hash[Constants::CARD_TYPE]
balance.number_of_transactions = hash[Constants::NUMBER_OF_TRANSACTIONS]
balance.credit = hash[Constants::CREDIT]
balance.debit = hash[Constants::DEBIT]
balance.balance = hash[Constants::BALANCE]
balance
end

def self.from_array(array)
balances = []
array.each {|balance_hash|
obj = from_hash(balance_hash)
balances.push(obj)
}
balances
end
end

class SettlementTransaction
attr_accessor :settlement_id
attr_accessor :eway_customer_id
attr_accessor :currency
attr_accessor :currency_code
attr_accessor :transaction_id
attr_accessor :txn_reference
attr_accessor :card_type
attr_accessor :amount
attr_accessor :transaction_type
attr_accessor :transaction_date
attr_accessor :settlement_date

def self.from_json(json)
hash = JSON.parse(json)
from_hash(hash)
end

def self.from_hash(hash)
transaction = SettlementTransaction.new
transaction.settlement_id = hash[Constants::SETTLEMENT_ID]
transaction.eway_customer_id = hash[Constants::EWAY_CUSTOMER_ID]
transaction.currency = hash[Constants::CURRENCY]
transaction.currency_code = hash[Constants::CURRENCY_CODE]
transaction.transaction_id = hash[Constants::TRANSACTION_ID]
transaction.txn_reference = hash[Constants::TXN_REFERENCE]
transaction.card_type = hash[Constants::CARD_TYPE]
transaction.amount = hash[Constants::AMOUNT]
transaction.transaction_type = hash[Constants::TRANSACTION_TYPE]
transaction.transaction_date = hash[Constants::TRANSACTION_DATE]
transaction.settlement_date = hash[Constants::SETTLEMENT_DATE]
transaction
end

def self.from_array(array)
transactions = []
array.each {|transaction_hash|
obj = from_hash(transaction_hash)
transactions.push(obj)
}
transactions
end
end
end
end
Loading

0 comments on commit 9347d43

Please sign in to comment.