test_cards.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. class Payment::TestCards
  2. attr_accessor :paratika, :test_gateway, :expired, :invalid
  3. # CCV or CVV, typo problem
  4. def join_path(*args)
  5. if defined?(Rails) && defined?(Rails.root)
  6. Rails.root.join(*args.prepend("payment"))
  7. else
  8. File.join(Dir.pwd, *args)
  9. end
  10. end
  11. def initialize
  12. paratika_csv = CSV.read(join_path("lib/payment/test_cards/paratika.csv"), headers: true)
  13. @paratika = paratika_csv.map do |row|
  14. { name: 'John Doe', number: row['Card Number'], month: row['Card Expiry'].split('/')[0], year: row['Card Expiry'].split('/')[1], ccv: row['CVV'] }
  15. end
  16. test_gateway_csv = CSV.read(join_path("lib/payment/test_cards/test_gateway.csv"), headers: true)
  17. @test_gateway = test_gateway_csv.map do |row|
  18. { name: 'John Doe', number: row['Card Number'], month: row['Card Expiry'].split('/')[0], year: row['Card Expiry'].split('/')[1], ccv: row['CVV'] }
  19. end
  20. @invalid = [
  21. { name: 'John Doe', number: '0111111111111111', month: '12', year: '2026', ccv: '000' }
  22. ]
  23. @expired = [
  24. { name: 'John Doe', number: '4546711234567894', month: '01', year: '2023', ccv: '123' }
  25. ]
  26. end
  27. def self.get(gw)
  28. new.send(gw)
  29. end
  30. end