module UnlockPaypal::Models::Contribution

Public Instance Methods

gateway_identifier() click to toggle source
# File lib/unlock_paypal/models/contribution.rb, line 7
def gateway_identifier
  self.gateway_data && self.gateway_data["profile_id"]
end
paypal_auth() click to toggle source
# File lib/unlock_paypal/models/contribution.rb, line 31
def paypal_auth
  return {} unless self.gateway && self.gateway.settings
  {
    username: self.gateway.settings["username"],
    password: self.gateway.settings["password"],
    signature: self.gateway.settings["signature"],
    sandbox: self.gateway.sandbox?
  }
end
state_on_gateway() click to toggle source
# File lib/unlock_paypal/models/contribution.rb, line 11
def state_on_gateway
  profile = PayPal::Recurring.new({profile_id: self.gateway_identifier}.merge(self.paypal_auth)).profile
  if profile.valid? && profile.active?
    :active
  else
    :suspended
  end
end
update_state_on_gateway!(state) click to toggle source
# File lib/unlock_paypal/models/contribution.rb, line 20
def update_state_on_gateway!(state)
  profile = PayPal::Recurring.new({profile_id: self.gateway_identifier}.merge(self.paypal_auth))
  case state
    when :active
      response = profile.reactivate
    when :suspended
      response = profile.suspend
  end
  response.valid?
end