Class: AlipayModel
- Inherits:
-
Object
- Object
- AlipayModel
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/models/alipay.rb
Instance Attribute Summary collapse
-
#_input_charset ⇒ Object
Returns the value of attribute _input_charset.
-
#body ⇒ Object
Returns the value of attribute body.
-
#notify_url ⇒ Object
Returns the value of attribute notify_url.
-
#out_trade_no ⇒ Object
Returns the value of attribute out_trade_no.
-
#partner ⇒ Object
Returns the value of attribute partner.
-
#payment_type ⇒ Object
Returns the value of attribute payment_type.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#seller_email ⇒ Object
Returns the value of attribute seller_email.
-
#seller_id ⇒ Object
Returns the value of attribute seller_id.
-
#service ⇒ Object
Returns the value of attribute service.
-
#show_url ⇒ Object
Returns the value of attribute show_url.
-
#sign ⇒ Object
Returns the value of attribute sign.
-
#sign_type ⇒ Object
Returns the value of attribute sign_type.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#total_fee ⇒ Object
Returns the value of attribute total_fee.
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
-
#initialize(attributes = {}) ⇒ AlipayModel
constructor
A new instance of AlipayModel.
- #invalid_sign? ⇒ Boolean
- #key ⇒ Object
- #missing_partner? ⇒ Boolean
- #money_blank? ⇒ Boolean
- #notify ⇒ Object
- #price_missing_quantity? ⇒ Boolean
- #repeat_money? ⇒ Boolean
- #seller_blank? ⇒ Boolean
- #send_notify ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ AlipayModel
Returns 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
#_input_charset ⇒ Object
Returns the value of attribute _input_charset.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def _input_charset @_input_charset end |
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def body @body end |
#notify_url ⇒ Object
Returns the value of attribute notify_url.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def notify_url @notify_url end |
#out_trade_no ⇒ Object
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 |
#partner ⇒ Object
Returns the value of attribute partner.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def partner @partner end |
#payment_type ⇒ Object
Returns the value of attribute payment_type.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def payment_type @payment_type end |
#price ⇒ Object
Returns the value of attribute price.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def quantity @quantity end |
#return_url ⇒ Object
Returns the value of attribute return_url.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def return_url @return_url end |
#seller_email ⇒ Object
Returns the value of attribute seller_email.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def seller_email @seller_email end |
#seller_id ⇒ Object
Returns the value of attribute seller_id.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def seller_id @seller_id end |
#service ⇒ Object
Returns the value of attribute service.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def service @service end |
#show_url ⇒ Object
Returns the value of attribute show_url.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def show_url @show_url end |
#sign ⇒ Object
Returns the value of attribute sign.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def sign @sign end |
#sign_type ⇒ Object
Returns the value of attribute sign_type.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def sign_type @sign_type end |
#subject ⇒ Object
Returns the value of attribute subject.
5 6 7 |
# File 'lib/models/alipay.rb', line 5 def subject @subject end |
#total_fee ⇒ Object
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
.accounts ⇒ Object
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
#account ⇒ Object
92 93 94 95 |
# File 'lib/models/alipay.rb', line 92 def account @account ||= self.class.accounts.assoc self.partner @account ||= [] end |
#invalid_sign? ⇒ 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 |
#key ⇒ Object
97 98 99 |
# File 'lib/models/alipay.rb', line 97 def key self.account[1].to_s end |
#missing_partner? ⇒ Boolean
71 72 73 74 |
# File 'lib/models/alipay.rb', line 71 def missing_partner? return if self.partner.to_s.length == 0 self.account == [] ? true : false end |
#money_blank? ⇒ 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 |
#notify ⇒ Object
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 |
#price_missing_quantity? ⇒ 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 |
#repeat_money? ⇒ 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 |
#seller_blank? ⇒ 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 |
#send_notify ⇒ Object
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 |