Module: UnlockMoip::Models::Contribution
- Includes:
- UnlockGateway::Models::Contribution
- Defined in:
- lib/unlock_moip/models/contribution.rb
Instance Method Summary collapse
- #customer_code ⇒ Object
- #gateway_identifier ⇒ Object
- #moip_auth ⇒ Object
- #plan_code ⇒ Object
- #plan_name ⇒ Object
- #state_on_gateway ⇒ Object
- #subscription_code ⇒ Object
- #update_state_on_gateway!(state) ⇒ Object
Instance Method Details
#customer_code ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/unlock_moip/models/contribution.rb', line 26 def customer_code if self.gateway_data && self.gateway_data["customer_code"] self.gateway_data["customer_code"] else Digest::MD5.new.update("#{self.initiative.permalink[0..29]}#{self.user.id}#{'sandbox' if self.gateway.sandbox?}").to_s end end |
#gateway_identifier ⇒ Object
42 43 44 |
# File 'lib/unlock_moip/models/contribution.rb', line 42 def gateway_identifier self.gateway_data && self.gateway_data["subscription_code"] end |
#moip_auth ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/unlock_moip/models/contribution.rb', line 7 def moip_auth return {} unless self.gateway && self.gateway.settings { moip_auth: { token: self.gateway.settings["token"], key: self.gateway.settings["key"], sandbox: self.gateway.sandbox? } } end |
#plan_code ⇒ Object
18 19 20 |
# File 'lib/unlock_moip/models/contribution.rb', line 18 def plan_code "#{self.initiative.permalink[0..29]}#{self.value.to_i}#{'sandbox' if self.gateway.sandbox?}" end |
#plan_name ⇒ Object
22 23 24 |
# File 'lib/unlock_moip/models/contribution.rb', line 22 def plan_name "#{self.initiative.name[0..29]} #{self.value.to_i}#{' (Sandbox)' if self.gateway.sandbox?}" end |
#state_on_gateway ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/unlock_moip/models/contribution.rb', line 46 def state_on_gateway begin response = Moip::Assinaturas::Subscription.details(self.subscription_code, self.moip_auth) rescue return nil end if response && response[:success] status = (response[:subscription]["status"].upcase rescue nil) case status when 'ACTIVE', 'OVERDUE' :active when 'SUSPENDED', 'EXPIRED', 'CANCELED' :suspended end end end |
#subscription_code ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/unlock_moip/models/contribution.rb', line 34 def subscription_code if self.gateway_data && self.gateway_data["subscription_code"] self.gateway_data["subscription_code"] else Digest::MD5.new.update("#{self.initiative.permalink[0..29]}#{self.id}#{'sandbox' if self.gateway.sandbox?}").to_s end end |
#update_state_on_gateway!(state) ⇒ Object
63 64 65 66 67 |
# File 'lib/unlock_moip/models/contribution.rb', line 63 def update_state_on_gateway!(state) transition = self.transition_by_state(state) response = Moip::Assinaturas::Subscription.send(transition, self.subscription_code, self.moip_auth) response[:success] end |