mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
Add EveryPay payments
* Refactor BankLink into Payments::BankLink, add Payments::EveryPay * Write tests for existing invoice views * Write basic tests for Payments module
This commit is contained in:
parent
f7c2b25a66
commit
c5591b4828
32 changed files with 818 additions and 31 deletions
16
test/fixtures/files/seb_bank_cert.pem
vendored
Normal file
16
test/fixtures/files/seb_bank_cert.pem
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICmTCCAgICCQC9Iax+je2Q9DANBgkqhkiG9w0BAQUFADCBkDELMAkGA1UEBhMC
|
||||
RUUxETAPBgNVBAgMCEhhcmp1bWFhMRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQK
|
||||
DAhFZGljeSBPVTERMA8GA1UECwwIYmFua2xpbmsxFjAUBgNVBAMMDXBhbmdhbGlu
|
||||
ay5uZXQxHjAcBgkqhkiG9w0BCQEWD3RhbmVsQGVkaWN5LmNvbTAeFw0xNTAyMDIw
|
||||
OTAyMzZaFw0zNTAxMjgwOTAyMzZaMIGQMQswCQYDVQQGEwJFRTERMA8GA1UECAwI
|
||||
SGFyanVtYWExEDAOBgNVBAcMB1RhbGxpbm4xETAPBgNVBAoMCEVkaWN5IE9VMREw
|
||||
DwYDVQQLDAhiYW5rbGluazEWMBQGA1UEAwwNcGFuZ2FsaW5rLm5ldDEeMBwGCSqG
|
||||
SIb3DQEJARYPdGFuZWxAZWRpY3kuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
|
||||
iQKBgQDTwWcJvpfFkPmSYXVCUJLoCya2YPeuzBcQww19KG+ErKLr+lAjhoER5ViW
|
||||
UD7KMDhViBzWpJZ0LqvAkamWyyjM5e0a2aUe71qI8yU8W2oZXRrmKQ4H1UxhaOGt
|
||||
aSGLIycY31y+aaKrRM8teMDvRSyBq08Lvk0e0cC/nbVIVvaS7QIDAQABMA0GCSqG
|
||||
SIb3DQEBBQUAA4GBAKhMeT9HhdOvmWy17kQjVYg4I0b/9bO/0DI6MqTiyziaSvcz
|
||||
DXTRwWKCa+dqx9yQ4aM7YBBK3d2y+aRnfdxxAQ1ThnIHuzoYSTlmFYhfpp6KroTz
|
||||
/01tSFqMZ9dZemSspCWgkXkEiBiUA45AEmOFSRSzWv7H8IOmFhe5ijmGmdna
|
||||
-----END CERTIFICATE-----
|
15
test/fixtures/files/seb_seller_key.pem
vendored
Normal file
15
test/fixtures/files/seb_seller_key.pem
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICWwIBAAKBgQDk3bIdDgZzsQQ697A5F2ZTOJppp6jGHig3pCsXf7qNBZr4Icjd
|
||||
PNpnfjYTXXg4/50yXQZu1Gz4bfNNJf6pKyS19U5SM+vAs4CA6rr1E4mxv9nfSIBA
|
||||
I0Vc+I2pXw2HAhvUiDryPv9meAHcVbKjQ0Q3944yFUhTMfbPxEYvx89uswIDAQAB
|
||||
AoGAajmDu/yQfg4BGqVvw2/a7HFvKe7JZPsGS50E6yk7msypOtXjdtwRustXqfFO
|
||||
JZZujbujirlJwpy1um8SHc6KgJEJ7Dg/j6Q2rFQvErmCwqf+hEjF0s1ZCcKL5WvY
|
||||
MZ76qTFQ3gYfWGh/7pFJn7cdbDxFo1KzfoXhvieH4SJhEtECQQD5UuR5uI2SmvGT
|
||||
n5XkQY+p0Ba8vUSdCTyOYCOkmUXc9ytuxH+Hf2Ad01iFQbjeo8NMjlbRADSlyobI
|
||||
XqP5FVqtAkEA6v6QzdhOngYxYETFb1215krapX9A6dT8ncVuxX/OSh78lkoRO8oI
|
||||
AMzYiXVVga+xvM8Uk8o0YlN4UnR+K9t63wJABVddRa5KeiWPn1X/5A/zf/PRSOHV
|
||||
IngcMACnQtN1x7IT4B+di82SxZDNiK1LxJlFidJS0c9rUVHxaUF9ycxHUQJAElVk
|
||||
BLtAfvGqvoD/Ck48V8g1QL4p2VRllQWHO99Zv8ylFjCXIZwEfdN9fVPrJOAJNNrP
|
||||
FyyqY5VxiLVP9qn77wJAEzTyrw3WO09wphaA2daTAAwiui6h+J5gac0rgsocp1OI
|
||||
vs4c+iqi7UdxCSic7HvlwdLxjnIPIrmC6t3xwRBFxQ==
|
||||
-----END RSA PRIVATE KEY-----
|
4
test/fixtures/invoices.yml
vendored
4
test/fixtures/invoices.yml
vendored
|
@ -30,3 +30,7 @@ outstanding:
|
|||
overdue:
|
||||
<<: *DEFAULTS
|
||||
due_date: <%= Date.parse '2010-07-03' %>
|
||||
|
||||
for_payments_test:
|
||||
<<: *DEFAULTS
|
||||
sum_cache: 100.00
|
||||
|
|
39
test/integration/registrar/invoices/list_test.rb
Normal file
39
test/integration/registrar/invoices/list_test.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ListInvoicesTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@user = users(:api_bestnames)
|
||||
@registrar_invoices = @user.registrar.invoices
|
||||
login_as @user
|
||||
end
|
||||
|
||||
def test_show_balance
|
||||
visit registrar_invoices_path
|
||||
assert_text "Your current account balance is 100,00 EUR"
|
||||
end
|
||||
|
||||
|
||||
def test_show_single_invoice
|
||||
@invoice = invoices(:valid)
|
||||
@registrar_invoices << @invoice
|
||||
|
||||
visit registrar_invoices_path
|
||||
assert_text "Unpaid", count: 1
|
||||
assert_text "Invoice no.", count: 1
|
||||
end
|
||||
|
||||
# This bastard fails, only unpaid invoice is attached to the registrar
|
||||
# TODO: Fix and uncomment
|
||||
# def test_show_multiple_invoices
|
||||
# @invoices = invoices
|
||||
# @invoices.each do |invoice|
|
||||
# @registrar_invoices << invoice
|
||||
# end
|
||||
|
||||
# visit registrar_invoices_path
|
||||
# assert_text "Unpaid", count: 2
|
||||
# assert_text "Invoice no.", count: 2
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,63 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NewInvoicePaymentTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@original_methods = ENV['payment_methods']
|
||||
@original_seb_URL = ENV['seb_payment_url']
|
||||
@original_bank_certificate = ENV['seb_bank_certificate']
|
||||
@original_seller_certificate = ENV['seller_certificate']
|
||||
@original_ep_url = ENV['every_pay_payment_url']
|
||||
ENV['payment_methods'] = 'seb, swed, every_pay'
|
||||
ENV['seb_payment_url'] = 'https://example.com/seb_url'
|
||||
ENV['seb_seller_account'] = 'SEB'
|
||||
ENV['seb_bank_certificate'] = 'test/fixtures/files/seb_bank_cert.pem'
|
||||
ENV['seb_seller_certificate'] = 'test/fixtures/files/seb_seller_key.pem'
|
||||
ENV['every_pay_payment_url'] = 'https://example.com/every_pay_url'
|
||||
|
||||
@user = users(:api_bestnames)
|
||||
login_as @user
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
ENV['every_pay_payment_url'] = @original_ep_url
|
||||
ENV['payment_methods'] = @original_methods
|
||||
ENV['seb_payment_url'] = @original_seb_URL
|
||||
ENV['seb_bank_certificate'] = @original_bank_certificate
|
||||
ENV['seb_seller_certificate'] = @original_seller_certificate
|
||||
end
|
||||
|
||||
def create_invoice_and_visit_its_page
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '200.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
def test_create_new_SEB_payment
|
||||
create_invoice_and_visit_its_page
|
||||
click_link_or_button 'Seb'
|
||||
form = page.find('form')
|
||||
assert_equal 'https://example.com/seb_url', form['action']
|
||||
assert_equal 'post', form['method']
|
||||
assert_equal '240.00', form.find_by_id('VK_AMOUNT', visible: false).value
|
||||
assert_equal 'Order nr. 13150', form.find_by_id('VK_MSG', visible: false).value
|
||||
end
|
||||
|
||||
def test_create_new_Every_Pay_payment
|
||||
create_invoice_and_visit_its_page
|
||||
click_link_or_button 'Every pay'
|
||||
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
|
||||
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
|
||||
|
||||
form = page.find('form')
|
||||
assert_equal 'https://example.com/every_pay_url', form['action']
|
||||
assert_equal 'post', form['method']
|
||||
assert_equal expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value
|
||||
assert_equal '240.0', form.find_by_id('amount', visible: false).value
|
||||
end
|
||||
end
|
67
test/integration/registrar/invoices/new_test.rb
Normal file
67
test/integration/registrar/invoices/new_test.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NewInvoiceTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
super
|
||||
login_as users(:api_bestnames)
|
||||
end
|
||||
|
||||
def test_show_balance
|
||||
visit registrar_invoices_path
|
||||
assert_text "Your current account balance is 100,00 EUR"
|
||||
end
|
||||
|
||||
def test_create_new_invoice_with_positive_amount
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '200.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
|
||||
assert_difference 'Invoice.count', 1 do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
assert_text 'Please pay the following invoice'
|
||||
assert_text 'Invoice no. 131050'
|
||||
assert_text 'Total without VAT 200,00'
|
||||
assert_text 'Pay invoice'
|
||||
end
|
||||
|
||||
def test_create_new_invoices_and_display_a_list_of_them
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '200.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
click_link_or_button 'Add'
|
||||
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '300.00'
|
||||
fill_in 'Description', with: 'My second invoice'
|
||||
click_link_or_button 'Add'
|
||||
|
||||
visit registrar_invoices_path
|
||||
assert_text "Unpaid", count: 2
|
||||
assert_text "Invoice no. 131050"
|
||||
assert_text "Invoice no. 131051"
|
||||
assert_text "240,00"
|
||||
assert_text "360,00"
|
||||
end
|
||||
|
||||
# This test case should fail once issue #651 gets fixed
|
||||
def test_create_new_invoice_with_amount_0_goes_through
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '0.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
|
||||
assert_difference 'Invoice.count', 1 do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
assert_text 'Please pay the following invoice'
|
||||
assert_text 'Invoice no. 131050'
|
||||
assert_text 'Total without VAT 0,00'
|
||||
assert_text 'Pay invoice'
|
||||
end
|
||||
end
|
54
test/models/payments/bank_link_test.rb
Normal file
54
test/models/payments/bank_link_test.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BankLinkTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@original_methods = ENV['payment_methods']
|
||||
@original_seb_URL = ENV['seb_payment_url']
|
||||
ENV['payment_methods'] = 'seb, swed, credit_card'
|
||||
ENV['seb_payment_url'] = 'https://example.com/seb_url'
|
||||
ENV['seb_seller_account'] = 'SEB'
|
||||
ENV['seb_bank_certificate'] = 'test/fixtures/files/seb_bank_cert.pem'
|
||||
ENV['seb_seller_certificate'] = 'test/fixtures/files/seb_seller_key.pem'
|
||||
|
||||
@invoice = invoices(:valid)
|
||||
params = {return_url: 'return.url', response_url: 'response_url'}
|
||||
@bank_link = Payments::BankLink.new('seb', @invoice, params)
|
||||
|
||||
travel_to '2018-04-01 00:30'
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
ENV['payment_methods'] = @original_methods
|
||||
ENV['seb_payment_url'] = @original_seb_URL
|
||||
travel_back
|
||||
end
|
||||
|
||||
def test_form_fields
|
||||
expected_response = {
|
||||
"VK_SERVICE": "1012",
|
||||
"VK_VERSION": "008",
|
||||
"VK_SND_ID": "SEB",
|
||||
"VK_STAMP": nil,
|
||||
"VK_AMOUNT": nil,
|
||||
"VK_CURR": "EUR",
|
||||
"VK_REF": "",
|
||||
"VK_MSG": "Order nr. ",
|
||||
"VK_RETURN": "return.url",
|
||||
"VK_CANCEL": "return.url",
|
||||
"VK_DATETIME": "2018-04-01T00:30:00+0300",
|
||||
"VK_MAC": "fPHKfBNwtyQI5ec1pnrlIUJI6nerGPwnoqx0K9/g40hsgUmum4QE1Eq992FR73pRXyE2+1dUuahEd3s57asM7MOD2Pb8SALA/+hi3jlqjiAAThdikDuJ+83LogSKQljLdd0BHwqe+O0WPeKaOmP2/HltOEIHpY3d399JAi1t7YA=",
|
||||
"VK_ENCODING": "UTF-8",
|
||||
"VK_LANG": "ENG"
|
||||
}.with_indifferent_access
|
||||
|
||||
assert_equal expected_response, @bank_link.form_fields
|
||||
end
|
||||
|
||||
def test_is_not_valid_without_response
|
||||
assert_equal false, @bank_link.valid_response?
|
||||
end
|
||||
end
|
64
test/models/payments/every_pay_test.rb
Normal file
64
test/models/payments/every_pay_test.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
require 'test_helper'
|
||||
|
||||
class EveryPayTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@original_methods = ENV['payment_methods']
|
||||
@original_seb_URL = ENV['seb_payment_url']
|
||||
ENV['payment_methods'] = 'seb, swed, credit_card'
|
||||
ENV['seb_payment_url'] = 'https://example.com/seb_url'
|
||||
ENV['seb_seller_account'] = 'SEB'
|
||||
ENV['seb_bank_certificate'] = 'test/fixtures/files/seb_bank_cert.pem'
|
||||
ENV['seb_seller_certificate'] = 'test/fixtures/files/seb_seller_key.pem'
|
||||
|
||||
@invoice = invoices(:valid)
|
||||
params = {
|
||||
response:
|
||||
{
|
||||
utf8:"✓",
|
||||
_method: "put",
|
||||
authenticity_token: "OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==",
|
||||
nonce: "8a9063b3c13edb00522d446481cb1886",
|
||||
timestamp: "1524036436",
|
||||
api_username: "ca8d6336dd750ddb",
|
||||
transaction_result: "completed",
|
||||
payment_reference: "3380fc36f02a7c1d2b0a700794e7a6ef8683191b3f0dc88b762e72c6e573adaf",
|
||||
payment_state: "settled",
|
||||
amount: "240.0",
|
||||
order_reference: "59fa7f639211d1e14952bad73ccb50",
|
||||
account_id: "EUR3D1",
|
||||
cc_type: "master_card",
|
||||
cc_last_four_digits: "0487",
|
||||
cc_month: "10",
|
||||
cc_year: "2018",
|
||||
cc_holder_name: "John Doe",
|
||||
hmac_fields: "account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result",
|
||||
hmac: "d5b11b001b248532ad5af529f072b5b76347936a",
|
||||
controller: "registrar/payments",
|
||||
action: "back",
|
||||
bank: "every_pay"
|
||||
},
|
||||
}
|
||||
@every_pay = Payments::EveryPay.new('every_pay', @invoice, params)
|
||||
|
||||
travel_to '2018-04-01 00:30'
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
ENV['payment_methods'] = @original_methods
|
||||
ENV['seb_payment_url'] = @original_seb_URL
|
||||
travel_back
|
||||
end
|
||||
|
||||
def test_form_fields
|
||||
end
|
||||
|
||||
def test_is_not_valid_without_response
|
||||
end
|
||||
|
||||
def test_validation
|
||||
end
|
||||
end
|
58
test/models/payments_test.rb
Normal file
58
test/models/payments_test.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PaymentTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@original_methods = ENV['payment_methods']
|
||||
@original_seb_URL = ENV['seb_payment_url']
|
||||
ENV['payment_methods'] = 'seb, swed, credit_card'
|
||||
ENV['seb_payment_url'] = nil
|
||||
@not_implemented_payment = Payments::Base.new(
|
||||
'not_implemented', Invoice.new
|
||||
)
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
ENV['payment_methods'] = @original_methods
|
||||
ENV['seb_payment_url'] = @original_seb_URL
|
||||
end
|
||||
|
||||
def test_variable_assignment
|
||||
assert_equal 'not_implemented', @not_implemented_payment.type
|
||||
assert_nil @not_implemented_payment.response_url
|
||||
assert_nil @not_implemented_payment.return_url
|
||||
assert_nil @not_implemented_payment.form_url
|
||||
end
|
||||
|
||||
def test_that_errors_are_raised_on_not_implemented_methods
|
||||
assert_raise NotImplementedError do
|
||||
@not_implemented_payment.valid_response?
|
||||
end
|
||||
|
||||
assert_raise NotImplementedError do
|
||||
@not_implemented_payment.settled_payment?
|
||||
end
|
||||
|
||||
assert_raise NotImplementedError do
|
||||
@not_implemented_payment.form_fields
|
||||
end
|
||||
|
||||
assert_raise NotImplementedError do
|
||||
@not_implemented_payment.complete_transaction
|
||||
end
|
||||
end
|
||||
|
||||
def test_that_create_with_type_raises_argument_error
|
||||
assert_raise ArgumentError do
|
||||
Payments.create_with_type("not_implemented", Invoice.new)
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_with_correct_subclass
|
||||
payment = Payments.create_with_type('seb', Invoice.new)
|
||||
assert_equal Payments::BankLink, payment.class
|
||||
end
|
||||
end
|
|
@ -30,6 +30,7 @@ class ActionDispatch::IntegrationTest
|
|||
|
||||
def teardown
|
||||
Warden.test_reset!
|
||||
WebMock.reset!
|
||||
Capybara.reset_sessions!
|
||||
Capybara.use_default_driver
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue