diff --git a/core/app/models/spree/store_credit.rb b/core/app/models/spree/store_credit.rb index d85946a8d46..b13fee90dbe 100644 --- a/core/app/models/spree/store_credit.rb +++ b/core/app/models/spree/store_credit.rb @@ -150,7 +150,12 @@ def can_void?(payment) end def generate_authorization_code - "#{id}-SC-#{Time.current.utc.strftime('%Y%m%d%H%M%S%6N')}" + [ + id, + 'SC', + Time.current.utc.strftime('%Y%m%d%H%M%S%6N'), + SecureRandom.uuid + ].join('-') end def editable? diff --git a/core/spec/models/spree/store_credit_spec.rb b/core/spec/models/spree/store_credit_spec.rb index badc26750b6..3d2653b8114 100644 --- a/core/spec/models/spree/store_credit_spec.rb +++ b/core/spec/models/spree/store_credit_spec.rb @@ -897,4 +897,12 @@ end end end + + describe "#generate_authorization_code" do + it "doesn't rely on time for uniqueness" do + freeze_time do + expect(subject.generate_authorization_code).not_to eq(subject.generate_authorization_code) + end + end + end end