diff --git a/lib/pay_zen/helper.rb b/lib/pay_zen/helper.rb index 047980920..ea98c972b 100644 --- a/lib/pay_zen/helper.rb +++ b/lib/pay_zen/helper.rb @@ -19,10 +19,10 @@ class PayZen::Helper end ## generate an unique string reference for the content of a cart - def generate_ref(cart_items, customer, date = DateTime.current) + def generate_ref(cart_items, customer) require 'sha3' - content = { cart_items: cart_items, customer: customer }.to_json + date.to_s + content = { cart_items: cart_items, customer: customer }.to_json + DateTime.current.to_s # It's safe to truncate a hash. See https://crypto.stackexchange.com/questions/74646/sha3-255-one-bit-less SHA3::Digest.hexdigest(:sha224, content)[0...24] end diff --git a/test/integration/payzen_test.rb b/test/integration/payzen_test.rb index 83c1ac81d..42b529b1c 100644 --- a/test/integration/payzen_test.rb +++ b/test/integration/payzen_test.rb @@ -93,7 +93,7 @@ class PayzenTest < ActionDispatch::IntegrationTest cs = CartService.new(@user) cart = cs.from_hash(cart_items) amount = cart.total[:total] - id = PayZen::Helper.generate_ref(cart_items, @user.id, DateTime.new(1970, 1, 1, 0, 0, 0)) + id = 'dffd53627a4901e986862674' VCR.use_cassette('confirm_payzen_payment_success') do client = PayZen::PCI::Charge.new