Class: IAPServer::Refund

Inherits:
Object
  • Object
show all
Defined in:
lib/iap/refund.rb

Instance Method Summary collapse

Instance Method Details

#get_inputs(options, args) ⇒ Object



19
20
21
22
# File 'lib/iap/refund.rb', line 19

def get_inputs(options, args)
    transaction_id = args.first || self.input('put transaction id: ')
    return transaction_id
end

#input(message) ⇒ Object



24
25
26
27
# File 'lib/iap/refund.rb', line 24

def input(message)
    print "#{message}".red
    STDIN.gets.chomp.strip
end

#run(options, args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/iap/refund.rb', line 7

def run(options, args)
    # get the command line inputs and parse those into the vars we need...
    transaction_id = get_inputs(options, args)
    if transaction_id.nil? || transaction_id.empty?
      raise "必须有transaction id。".red
    end

    req = IAPServer::StoreRequest.new :sandbox => options.sandbox
      resp = req.request("/inApps/v1/refund/lookup/#{transaction_id}", IAPServer::JWTTools.generate)
      validation_jwt(resp)
end

#validation_jwt(resp) ⇒ Object

验证jwt



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/iap/refund.rb', line 30

def validation_jwt(resp)
  puts 'Code = ' + resp.code    ##请求状态码
  puts 'Message = ' + resp.message
  if resp.code == '200'
    body = JSON.parse(resp.body)

    jwt_list = body["signedTransactions"]
    if !jwt_list.nil? && jwt_list.count > 0
      jwt_token = jwt_list[0]

      if IAPServer::JWTTools.good_signature(jwt_token)
        payload = IAPServer::JWTTools.payload(jwt_token)
        puts "Payload:" + payload
      else
        puts "JWT 验证失败"
      end
    else
      puts '没有查询到退款信息'
    end
  end
end