lib/fawry/requests/charge_request.rb in fawry-0.1.0 vs lib/fawry/requests/charge_request.rb in fawry-0.2.0
- old
+ new
@@ -5,11 +5,11 @@
module Fawry
module Requests
module ChargeRequest
DEFAULTS = { payment_method: 'PAYATFAWRY', currency_code: 'EGP' }.freeze
- def fire
+ def fire_charge_request
fawry_api_response = Connection.post(request[:path], request[:params], request[:body], request[:options])
response_body = JSON.parse(fawry_api_response.body)
FawryResponse.new(response_body)
end
@@ -27,10 +27,12 @@
def request_params
@request_params ||= DEFAULTS.merge(params)
end
+ # rubocop:disable Metrics/AbcSize
+ # rubocop:disable Metrics/MethodLength
def charge_request_transformed_params
{
merchantCode: request_params[:merchant_code],
merchantRefNum: request_params[:merchant_ref_num],
customerProfileId: request_params[:customer_profile_id],
@@ -44,24 +46,28 @@
chargeItems: charge_items,
currencyCode: request_params[:currency_code],
signature: charge_request_signature
}.compact
end
+ # rubocop:enable Metrics/MethodLength
+ # rubocop:enable Metrics/AbcSize
def validate_charge_params!
contract = Contracts::ChargeRequestContract.new.call(request_params)
raise InvalidFawryRequest, contract.errors.to_h if contract.failure?
end
def charge_items
request_params[:charge_items].each { |hash| hash[:itemId] = hash.delete(:item_id) }
end
+ # rubocop:disable Metrics/AbcSize
def charge_request_signature
Digest::SHA256.hexdigest("#{request_params[:merchant_code]}#{request_params[:merchant_ref_num]}"\
"#{request_params[:customer_profile_id]}#{request_params[:payment_method]}"\
"#{format('%<amount>.2f', amount: request_params[:amount])}"\
"#{request_params[:card_token]}#{request_params[:fawry_secure_key]}")
end
+ # rubocop:enable Metrics/AbcSize
end
end
end