Class: Paygate::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/paygate/transaction.rb

Constant Summary collapse

FULL_AMOUNT_IDENTIFIER =
'F'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tid) ⇒ Transaction

Returns a new instance of Transaction.



14
15
16
# File 'lib/paygate/transaction.rb', line 14

def initialize(tid)
  @tid = tid
end

Instance Attribute Details

#memberObject

Returns the value of attribute member.



12
13
14
# File 'lib/paygate/transaction.rb', line 12

def member
  @member
end

#tidObject (readonly)

Returns the value of attribute tid.



11
12
13
# File 'lib/paygate/transaction.rb', line 11

def tid
  @tid
end

Class Method Details

.refund_api_urlObject



52
53
54
55
56
57
58
# File 'lib/paygate/transaction.rb', line 52

def self.refund_api_url
  if Paygate.configuration.mode == :live
    'https://service.paygate.net/service/cancelAPI.json'
  else
    'https://stgsvc.paygate.net/service/cancelAPI.json'
  end
end

Instance Method Details

#refund(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/paygate/transaction.rb', line 18

def refund(options = {})
  # Encrypt data
  api_key256 = ::Digest::SHA256.hexdigest(member.secret)
  aes_ctr = AesCtr.encrypt(tid, api_key256, 256)
  tid_enc = "AES256#{aes_ctr}"

  # Prepare params
  params = { callback: 'callback', mid: member.mid, tid: tid_enc }
  params.merge!(options.slice(:amount))
  params[:amount] ||= FULL_AMOUNT_IDENTIFIER
  params[:mb_serial_no] = options[:order_id]
  params.compact!

  # Make request
  uri = URI(self.class.refund_api_url)
  uri.query = ::URI.encode_www_form(params)
  response = ::Net::HTTP.get_response(uri)

  r = Response.build_from_net_http_response(:refund, response)
  r.raw_info = OpenStruct.new(tid: tid, tid_enc: tid_enc, request_url: uri.to_s) # rubocop:disable Style/OpenStructUse
  r
end

#verifyObject



42
43
44
45
46
47
48
49
50
# File 'lib/paygate/transaction.rb', line 42

def verify
  params = { tid: tid, verifyNum: 100 }

  uri = URI('https://service.paygate.net/djemals/settle/verifyReceived.jsp')
  uri.query = ::URI.encode_www_form(params)
  response = ::Net::HTTP.get_response(uri)

  Response.build_from_net_http_response(:verify, response)
end