-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from railslove/foreign-currency-credits
[AZV] enable foreign currency transfers
- Loading branch information
Showing
16 changed files
with
486 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require 'king_dtaus' | ||
require_relative '../errors/business_process_failure' | ||
|
||
module Box | ||
class ForeignCredit | ||
class Payload < OpenStruct | ||
def sender | ||
KingDta::Account.new({ | ||
owner_name: account.name, | ||
bank_number: account.bank_number, | ||
owner_country_code: account.bank_country_code, | ||
bank_account_number: account.bank_account_number | ||
}) | ||
end | ||
|
||
def receiver | ||
KingDta::Account.new({ | ||
bank_bic: params[:bic], | ||
owner_name: params[:name], | ||
owner_country_code: params[:country_code], | ||
** account_number | ||
}) | ||
end | ||
|
||
def account_number | ||
if params[:iban] =~ /[A-Z]{2}/ | ||
{ bank_iban: params[:iban] } | ||
else | ||
{ bank_account_number: params[:iban] } | ||
end | ||
end | ||
|
||
def amount | ||
params[:amount] / 100.0 | ||
end | ||
|
||
def fee_handling | ||
{ | ||
split: '00', | ||
sender: '01', | ||
receiver: '02', | ||
}[params[:fee_handling]] | ||
end | ||
|
||
def booking | ||
KingDta::Booking.new(receiver, amount, params[:eref], nil, params[:currency]).tap do |booking| | ||
booking.payment_type = '00' | ||
booking.charge_bearer_code = fee_handling | ||
end | ||
end | ||
|
||
def create | ||
azv = KingDta::Dtazv.new(params[:execution_date]) | ||
azv.account = sender | ||
azv.add(booking) | ||
|
||
azv.create | ||
end | ||
end | ||
|
||
def self.v2_create!(user, account, params) | ||
params[:requested_date] = params[:execution_date].to_time.to_i | ||
|
||
# Transform a few params | ||
params[:amount] = params[:amount_in_cents] | ||
params[:eref] = params[:end_to_end_reference] | ||
params[:remittance_information] = params[:reference] | ||
|
||
payload = Payload.new(account: account, params: params) | ||
|
||
Queue.execute_credit( | ||
account_id: account.id, | ||
user_id: user.id, | ||
payload: Base64.strict_encode64(payload.create), | ||
eref: params[:eref], | ||
currency: params[:currency], | ||
amount: params[:amount], | ||
metadata: params.slice(:name, :iban, :bic, :execution_date, :reference, :country_code, :fee_handling) | ||
) | ||
rescue ArgumentError => e | ||
# TODO: Will be fixed upstream in the sepa_king gem by us | ||
fail Box::BusinessProcessFailure.new({ base: e.message }, 'Invalid data') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.