Class: Vpago::PaywayV2::PreAuthCompleter
- Inherits:
-
Base
- Object
- Base
- Vpago::PaywayV2::PreAuthCompleter
show all
- Defined in:
- lib/vpago/payway_v2/pre_auth_completer.rb
Instance Method Summary
collapse
Methods inherited from Base
#amount, #api_key, #continue_success_url, #email, #first_name, #hash_hmac, #host, #initialize, #last_name, #merchant_id, #order_jwt_token, #payment_option, #payout, #phone, #public_key, #req_time, #return_deeplink, #return_deeplink_url, #return_params, #return_url, #transaction_fee, #transaction_fee_fix, #transaction_fee_percentage, #transaction_id, #type, #view_type
Instance Method Details
#call ⇒ Object
6
7
8
9
10
11
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 6
def call
return if completed? || cancelled?
@response = pre_auth_response
save_response if success?
end
|
#cancelled? ⇒ Boolean
14
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 14
def cancelled? = @payment.pre_auth_response['transaction_status'] == 'CANCELLED'
|
#complete_url ⇒ Object
60
61
62
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 60
def complete_url
"#{host}#{ENV.fetch('PAYWAY_V2_PRE_AUTH_COMPLETE_PATH')}"
end
|
#completed? ⇒ Boolean
13
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 13
def completed? = @payment.pre_auth_response['transaction_status'] == 'COMPLETED'
|
#hash_data ⇒ Object
37
38
39
40
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 37
def hash_data
data = "#{merchant_auth_encryption}#{req_time}#{merchant_id}"
Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), api_key, data))
end
|
#json_response ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 68
def json_response
return @payment.pre_auth_response if @payment.pre_auth_response.present?
@json_response ||= begin
JSON.parse(@response.body)
rescue JSON::ParserError
{}
end
end
|
#merchant_auth ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 42
def merchant_auth
merchant_auth = {
'mc_id' => merchant_id,
'tran_id' => transaction_id,
'complete_amount' => amount.to_s
}
merchant_auth['payout'] = payout unless payout.nil?
merchant_auth.to_json
end
|
#merchant_auth_encryption ⇒ Object
53
54
55
56
57
58
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 53
def merchant_auth_encryption
@merchant_auth_encryption ||= Vpago::PayoutProfiles::Payway::OpenSslEncrypter.new(
content: merchant_auth,
rsa_public_key: public_key
).call
end
|
#pre_auth_response ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 20
def pre_auth_response
conn = Faraday::Connection.new do |faraday|
faraday.request :url_encoded
end
conn.post(complete_url, request_data)
end
|
#request_data ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 28
def request_data
{
request_time: req_time,
merchant_id: merchant_id,
merchant_auth: merchant_auth_encryption,
hash: hash_data
}
end
|
#save_response ⇒ Object
16
17
18
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 16
def save_response
@payment.update(pre_auth_response: json_response)
end
|
#success? ⇒ Boolean
64
65
66
|
# File 'lib/vpago/payway_v2/pre_auth_completer.rb', line 64
def success?
json_response['status']['code'] == '00'
end
|