Class: AlipayModel

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/models/alipay.rb

Overview

-- coding: utf-8 --

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AlipayModel) initialize(attributes = {})

A new instance of AlipayModel



56
57
58
59
60
61
# File 'lib/models/alipay.rb', line 56

def initialize(attributes = {})
  @attributes = attributes
  attributes.each do |name, value|
    send("#{name}=", value) if respond_to? name
  end
end

Instance Attribute Details

- (Object) _input_charset

Returns the value of attribute _input_charset



5
6
7
# File 'lib/models/alipay.rb', line 5

def _input_charset
  @_input_charset
end

- (Object) body

Returns the value of attribute body



5
6
7
# File 'lib/models/alipay.rb', line 5

def body
  @body
end

- (Object) notify_url

Returns the value of attribute notify_url



5
6
7
# File 'lib/models/alipay.rb', line 5

def notify_url
  @notify_url
end

- (Object) out_trade_no

Returns the value of attribute out_trade_no



5
6
7
# File 'lib/models/alipay.rb', line 5

def out_trade_no
  @out_trade_no
end

- (Object) partner

Returns the value of attribute partner



5
6
7
# File 'lib/models/alipay.rb', line 5

def partner
  @partner
end

- (Object) payment_type

Returns the value of attribute payment_type



5
6
7
# File 'lib/models/alipay.rb', line 5

def payment_type
  @payment_type
end

- (Object) price

Returns the value of attribute price



5
6
7
# File 'lib/models/alipay.rb', line 5

def price
  @price
end

- (Object) quantity

Returns the value of attribute quantity



5
6
7
# File 'lib/models/alipay.rb', line 5

def quantity
  @quantity
end

- (Object) return_url

Returns the value of attribute return_url



5
6
7
# File 'lib/models/alipay.rb', line 5

def return_url
  @return_url
end

- (Object) seller_email

Returns the value of attribute seller_email



5
6
7
# File 'lib/models/alipay.rb', line 5

def seller_email
  @seller_email
end

- (Object) seller_id

Returns the value of attribute seller_id



5
6
7
# File 'lib/models/alipay.rb', line 5

def seller_id
  @seller_id
end

- (Object) service

Returns the value of attribute service



5
6
7
# File 'lib/models/alipay.rb', line 5

def service
  @service
end

- (Object) show_url

Returns the value of attribute show_url



5
6
7
# File 'lib/models/alipay.rb', line 5

def show_url
  @show_url
end

- (Object) sign

Returns the value of attribute sign



5
6
7
# File 'lib/models/alipay.rb', line 5

def sign
  @sign
end

- (Object) sign_type

Returns the value of attribute sign_type



5
6
7
# File 'lib/models/alipay.rb', line 5

def sign_type
  @sign_type
end

- (Object) subject

Returns the value of attribute subject



5
6
7
# File 'lib/models/alipay.rb', line 5

def subject
  @subject
end

- (Object) total_fee

Returns the value of attribute total_fee



5
6
7
# File 'lib/models/alipay.rb', line 5

def total_fee
  @total_fee
end

Class Method Details

+ (Object) accounts



101
102
103
104
# File 'lib/models/alipay.rb', line 101

def self.accounts
  @accounts ||= YAML.load_file('test/partner.yml')['alipay'] if ENV['magpie'] == 'test'
  @accounts ||= Magpie.yml_db['alipay']
end

Instance Method Details

- (Object) account



92
93
94
95
# File 'lib/models/alipay.rb', line 92

def 
  @account ||= self.class.accounts.assoc self.partner
  @account ||= []
end

- (Boolean) invalid_sign?

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# File 'lib/models/alipay.rb', line 84

def invalid_sign?
  attrs = @attributes.dup
  attrs.delete("sign")
  attrs.delete("sign_type")
  text = attrs.delete_if{ |k, v| v.to_s.length == 0 }.sort.collect{ |s| s[0] + "=" + URI.decode(s[1]) }.join("&") + self.key
  self.sign == Digest::MD5.hexdigest(text) ? false : true
end

- (Object) key



97
98
99
# File 'lib/models/alipay.rb', line 97

def key
  self.[1].to_s
end

- (Boolean) missing_partner?

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/models/alipay.rb', line 71

def missing_partner?
  return if self.partner.to_s.length == 0
  self. == [] ? true : false
end

- (Boolean) money_blank?

Returns:

  • (Boolean)


80
81
82
# File 'lib/models/alipay.rb', line 80

def money_blank?
  self.price.to_s.length == 0 and self.total_fee.to_s.length == 0
end

- (Object) notify



107
108
109
110
111
112
# File 'lib/models/alipay.rb', line 107

def notify
  @notify ||= notify_attrs.inject({ }){ |notify, attr|
    notify[attr] = self.send(attr)
    notify
  }.merge("sign_type" => sign_type, "sign" => notify_sign)
end

- (Boolean) price_missing_quantity?

Returns:

  • (Boolean)


67
68
69
# File 'lib/models/alipay.rb', line 67

def price_missing_quantity?
  self.price.to_s.length > 0 and self.quantity.to_s.length == 0
end

- (Boolean) repeat_money?

Returns:

  • (Boolean)


63
64
65
# File 'lib/models/alipay.rb', line 63

def repeat_money?
  self.price.to_s.length > 0 and self.total_fee.to_s.length > 0
end

- (Boolean) seller_blank?

Returns:

  • (Boolean)


76
77
78
# File 'lib/models/alipay.rb', line 76

def seller_blank?
  self.seller_id.to_s.length == 0 and self.seller_email.to_s.length == 0
end

- (Object) send_notify



114
115
116
117
118
# File 'lib/models/alipay.rb', line 114

def send_notify
  url = URI.parse notify_url
  res = Net::HTTP.post_form url, self.notify
  res.body
end