Class: Vpago::PaywayV2::TransactionStatusV2
- Inherits:
-
Base
- Object
- Base
- Vpago::PaywayV2::TransactionStatusV2
show all
- Defined in:
- lib/vpago/payway_v2/transaction_status_v2.rb
Instance Method Summary
collapse
Methods inherited from Base
#amount, #api_key, #continue_success_url, #email, #first_name, #hash_data, #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, #skip_success_page, #transaction_fee, #transaction_fee_fix, #transaction_fee_percentage, #transaction_id, #type, #view_type
Instance Method Details
#call ⇒ Object
8
9
10
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 8
def call
@response = check_remote_status
end
|
#check_remote_status ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 52
def check_remote_status
conn = Faraday::Connection.new do |faraday|
faraday.request :url_encoded
end
data = {
req_time: req_time,
merchant_id: merchant_id,
tran_id: transaction_id,
hash: checker_hmac
}
conn.post(check_transaction_url, data)
end
|
#check_transaction_url ⇒ Object
90
91
92
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 90
def check_transaction_url
"#{host}/api/payment-gateway/v1/payments/check-transaction-2"
end
|
#checker_hmac ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 82
def checker_hmac
data = "#{req_time}#{merchant_id}#{transaction_id}"
hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), api_key, data))
hash.delete("\n")
end
|
#error_message ⇒ Object
67
68
69
70
71
72
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 67
def error_message
status_data = json_response['status']
return nil unless status_data.is_a?(Hash)
status_data['message']
end
|
#failed? ⇒ Boolean
48
49
50
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 48
def failed?
%w[5 6 8].include?(status_code) || %w[DECLINED CANCELLED].include?(payment_status)
end
|
#json_response ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 74
def json_response
@json_response ||= begin
JSON.parse(@response.body)
rescue JSON::ParserError
{}
end
end
|
#payment_status ⇒ Object
APPROVED : Transaction successfully completed with the full purchase amount. PRE-AUTH : Transaction successfully processed with a pre-authorization hold on funds pending final capture. REFUNDED : Transaction has been fully or partially refunded. PENDING : Transaction is awaiting payment completion by the payer. DECLINED : Transaction has been declined. CANCELLED : Merchant canceled the pre-authorization or closed the transaction.
31
32
33
34
35
36
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 31
def payment_status
data = json_response['data']
return nil unless data.is_a?(Hash)
data['payment_status']
end
|
#pending? ⇒ Boolean
request failed does not mean payment failed. but it failed when status is failed.
44
45
46
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 44
def pending?
%w[PENDING].include?(payment_status)
end
|
#status_code ⇒ Object
00 : Success! 5 : Invalid hash 6 : Transaction not found 8 : Invalid merchant profile 11 : Internal server error 429 : Reach request limit
18
19
20
21
22
23
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 18
def status_code
status_data = json_response['status']
return nil unless status_data.is_a?(Hash)
status_data['code']&.to_s
end
|
#success? ⇒ Boolean
38
39
40
|
# File 'lib/vpago/payway_v2/transaction_status_v2.rb', line 38
def success?
%w[APPROVED PRE-AUTH].include?(payment_status)
end
|