Class: Fakesite::Alipay::Base

Inherits:
Base
  • Object
show all
Includes:
WebMock::API
Defined in:
lib/fakesite/alipay/base.rb

Constant Summary collapse

@@stubbed =
false

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
# File 'lib/fakesite/alipay/base.rb', line 8

def initialize(options = {})
  unless @@stubbed
    @@stubbed = true
    stub_request(:get, 'https://' + Host + '/gateway.do')
      .with(:query => hash_including({:service => 'notify_verify'}))
      .to_return(:status => 200, :body => "true")
  end
  super(options)
end

Instance Method Details

#idObject



18
19
20
# File 'lib/fakesite/alipay/base.rb', line 18

def id
  :alipay
end

#match(external_uri) ⇒ Object



22
23
24
# File 'lib/fakesite/alipay/base.rb', line 22

def match(external_uri)
  external_uri.host == Host
end

#parameters(external_uri) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fakesite/alipay/base.rb', line 26

def parameters(external_uri)
  { 
    "trade_status" => 'TRADE_SUCCESS', 
    "trade_no" => Time.now.to_i.to_s, 
    "notify_id" => Time.now.to_i.to_s,
    "buyer_email" => "",
    "buyer_id" => "",
    "exterface" => "create_direct_pay_by_user",
    "notify_time" => (Time.now.utc + 28800).strftime("%Y-%m-%d %H:%M:%S")
  }
end

#return_parameters(params) ⇒ Object



38
39
40
41
42
43
# File 'lib/fakesite/alipay/base.rb', line 38

def return_parameters(params)
  string = params.sort.map { |item| item.join('=') }.join('&')
  params["sign"] = Digest::MD5.hexdigest("#{string}#{@options[:key]}")
  params["sign_type"] = "MD5"
  return params
end