test_paratika.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = '10002036'
  8. config.merchant_user = 'paytentest@akillibulut.net'
  9. config.merchant_password = '3mzVyRKuwnttqRC.'
  10. config.url = 'https://entegrasyon.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. puts result.to_json + __method__.to_s
  24. assert result.data[:success]
  25. end
  26. def test_sale_with_new_card
  27. result = Paratika::Sale.new(@@payment, @@customer, @@card).send
  28. puts result.to_json + __method__.to_s
  29. assert result.data[:success]
  30. end
  31. def test_pre_auth_with_new_card
  32. result = Paratika::PreAuth.new(@@payment, @@customer, @@card).send
  33. puts result.to_json + __method__.to_s
  34. assert result.data[:success]
  35. end
  36. def test_sale_with_saved_card
  37. result = Paratika::Sale.new(@@payment, @@customer, { token: @@token }).send
  38. puts result.to_json + __method__.to_s
  39. assert result.data[:success]
  40. end
  41. def test_pre_auth_with_saved_card
  42. result = Paratika::PreAuth.new(@@payment, @@customer, { token: @@token }).send
  43. puts result.to_json + __method__.to_s
  44. assert result.data[:success]
  45. end
  46. def test_cancel_transaction
  47. result = Paratika::Void.new(@@refundable).send
  48. puts result.to_json + __method__.to_s
  49. assert result.data[:success]
  50. end
  51. def test_refund_money
  52. result = Paratika::Refund.new(@@refundable).send
  53. puts result.to_json + __method__.to_s
  54. assert result.data[:success]
  55. end
  56. def test_query_saved_cards
  57. result = Paratika::QueryCard.new(@@customer[:id]).send
  58. puts result.to_json + __method__.to_s
  59. assert result.data[:success]
  60. end
  61. def test_delete_card
  62. result = Paratika::EWalletDeleteCard.new(@@token).send
  63. puts result.to_json + __method__.to_s
  64. assert result.data[:success]
  65. end
  66. end