test_paratika.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. require "test_helper"
  3. require 'bigdecimal'
  4. class TestParatika < Minitest::Test
  5. def setup
  6. Paratika.configure do |config|
  7. config.merchant_id = '10000000'
  8. config.merchant_user = 'apiuser@testmerchant.com'
  9. config.merchant_password = 'Pluto321`'
  10. config.url = 'https://test.paratika.com.tr'
  11. end
  12. @@customer = { id: 'c1', name: 'John Doe', email: 'test@example.com', phone: '905531781020', ip: '7.11.7.11' }
  13. @@card = { name: 'John Doe', number: '4355084355084358', expiry: '12/2030', ccv: '000', save: 'yes' }
  14. @@pid = -> { { id: SecureRandom.hex(16), amount: BigDecimal('1.00'), currency: 'TRY' } }
  15. @@refundable, @@payment = @@pid.call, @@pid.call
  16. @@token = Paratika::Sale.new(@@refundable, @@customer, @@card).send.data[:card_token]
  17. end
  18. def test_version_number
  19. refute_nil ::Paratika::VERSION
  20. end
  21. def test_currency_exchange
  22. result = Paratika::CurrencyExchange.new('USD', 'TRY', BigDecimal('1.00')).send
  23. assert result.data[:success]
  24. end
  25. def test_sale_with_new_card
  26. result = Paratika::Sale.new(@@payment, @@customer, @@card).send
  27. assert result.data[:success]
  28. end
  29. def test_pre_auth_with_new_card
  30. result = Paratika::PreAuth.new(@@payment, @@customer, @@card).send
  31. assert result.data[:success]
  32. end
  33. def test_sale_with_saved_card
  34. result = Paratika::Sale.new(@@payment, @@customer, { token: @@token }).send
  35. assert result.data[:success]
  36. end
  37. def test_pre_auth_with_saved_card
  38. result = Paratika::PreAuth.new(@@payment, @@customer, { token: @@token }).send
  39. assert result.data[:success]
  40. end
  41. def test_cancel_transaction
  42. result = Paratika::Void.new(@@refundable).send
  43. assert result.data[:success]
  44. end
  45. def test_refund_money
  46. result = Paratika::Refund.new(@@refundable).send
  47. assert result.data[:success]
  48. end
  49. def test_query_saved_cards
  50. result = Paratika::QueryCard.new(@@customer[:id]).send
  51. assert result.data[:success]
  52. end
  53. def test_delete_card
  54. result = Paratika::EWalletDeleteCard.new(@@token).send
  55. assert result.data[:success]
  56. end
  57. end