app/models/opay/payment.rb in opay-1.0.6 vs app/models/opay/payment.rb in opay-1.0.7

- old
+ new

@@ -1,7 +1,20 @@ module Opay class Payment < ActiveRecord::Base belongs_to :payable, polymorphic: true - attr_accessible :provider, :amount, :finished, :session_id - validates :payable, :provider, :amount, :session_id, presence: true + attr_accessible :provider, :amount, :finished, :session_id, :status + validates :payable, :provider, :amount, presence: true + + before_create do |p| + p.session_id = Payment.generate_session_id + end + + def self.generate_session_id + # Generate a token by looping and ensuring does not already exist. + loop do + token = SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz') + break token unless Payment.where(session_id: token).first + end + end + end end