diff --git a/lib/customer_finacials.rb b/lib/customer_finacials.rb index e2353be9c9d8051f1c77f3a6ed46f6ce29d86ba6..07c33eacc86bb502a7dda6ceac52c645fc3bb377 100644 --- a/lib/customer_finacials.rb +++ b/lib/customer_finacials.rb @@ -11,11 +11,8 @@ class CustomerFinancials .customer .find(@customer_id) .catch { OpenStruct.new(payment_methods: []) }, - REDIS.smembers("block_credit_cards"), - three_d_secure - ]).then do |(braintree, badcards, three_d)| - PaymentMethods.for(braintree, badcards, three_d) - end + REDIS.smembers("block_credit_cards") + ]).then { |(braintree, badcards)| PaymentMethods.for(braintree, badcards) } end def btc_addresses @@ -45,12 +42,6 @@ class CustomerFinancials end end - def three_d_secure - REDIS.hgetall( - "jmp_customer_three_d_secure_authentication_id-#{@customer_id}" - ).then { |all| Hash[*all] } - end - class TransactionInfo value_semantics do transaction_id String diff --git a/lib/payment_method.rb b/lib/payment_method.rb deleted file mode 100644 index fea213335263fb86f83570b188702dfc13e7d4b6..0000000000000000000000000000000000000000 --- a/lib/payment_method.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require "delegate" - -class PaymentMethod < SimpleDelegator - def self.for(method, three_d_secure={}) - three_d = three_d_secure[method.token] - return ThreeDSecure.new(method, three_d) if three_d - - new(method) - end - - def transaction_details - { - payment_method_token: token - } - end - - class ThreeDSecure < PaymentMethod - def initialize(method, three_d) - super(method) - @three_d = three_d - end - - def transaction_details - super.merge(three_d_secure_authentication_id: @three_d) - end - end -end diff --git a/lib/payment_methods.rb b/lib/payment_methods.rb index 8ea008f5d787dcc6b0f7dc6858fe07a05fb44555..2bbf08a392b6d6bdabb4b8833fe40b8b78e65f71 100644 --- a/lib/payment_methods.rb +++ b/lib/payment_methods.rb @@ -1,16 +1,14 @@ # frozen_string_literal: true -require_relative "payment_method" - class PaymentMethods - def self.for(braintree_customer, badcards, three_d_secure) + def self.for(braintree_customer, badcards) methods = braintree_customer.payment_methods.reject { |m| badcards.include?(m.unique_number_identifier) } if methods.empty? Empty.new else - new(methods.map { |m| PaymentMethod.for(m, three_d_secure) }) + new(methods) end end diff --git a/lib/transaction.rb b/lib/transaction.rb index 9bf759e01641578973fcdb75f3e3d6017ce1c5ee..83e8e158ce158eaa3ccae3fb1dddf0a6de113290 100644 --- a/lib/transaction.rb +++ b/lib/transaction.rb @@ -5,11 +5,12 @@ require "bigdecimal" class Transaction def self.sale(customer, amount:, payment_method: nil) resolve_payment_method(customer, payment_method).then do |selected_method| - BRAINTREE.transaction.sale(selected_method.transaction_details.merge( + BRAINTREE.transaction.sale( amount: amount, merchant_account_id: customer.merchant_account, - options: { submit_for_settlement: true } - )).then do |response| + options: { submit_for_settlement: true }, + payment_method_token: selected_method.token + ).then do |response| new(decline_guard(customer, response)) end end diff --git a/test/test_buy_account_credit_form.rb b/test/test_buy_account_credit_form.rb index fbcdd51ca14f8510c31851c49ce77dc2a3589ec9..4b052ef82ff048e995cff3b254a6da54a613cd12 100644 --- a/test/test_buy_account_credit_form.rb +++ b/test/test_buy_account_credit_form.rb @@ -20,9 +20,6 @@ class BuyAccountCreditFormTest < Minitest::Test braintree_customer = Minitest::Mock.new CustomerFinancials::BRAINTREE.expect(:customer, braintree_customer) CustomerFinancials::REDIS.expect(:smembers, [], ["block_credit_cards"]) - CustomerFinancials::REDIS.expect( - :hgetall, [], ["jmp_customer_three_d_secure_authentication_id-test"] - ) braintree_customer.expect( :find, EMPromise.resolve(OpenStruct.new(payment_methods: [])), diff --git a/test/test_payment_methods.rb b/test/test_payment_methods.rb index f5d79e1f4e6d89b898319eb334f0e6e665819384..0971e7b91d56188366b89157eb1d9758b3399875 100644 --- a/test/test_payment_methods.rb +++ b/test/test_payment_methods.rb @@ -7,16 +7,12 @@ class PaymentMethodsTest < Minitest::Test def test_for braintree_customer = Minitest::Mock.new braintree_customer.expect(:payment_methods, [ - OpenStruct.new(card_type: "Test", last_4: "1234", token: "wut") + OpenStruct.new(card_type: "Test", last_4: "1234") ]) - methods = PaymentMethods.for(braintree_customer, [], {}) + methods = PaymentMethods.for(braintree_customer, []) assert_kind_of PaymentMethods, methods assert_equal 1, methods.to_a.length refute methods.empty? - assert_equal( - { payment_method_token: "wut" }, - methods.fetch(0).transaction_details - ) end def test_for_badcards @@ -28,33 +24,16 @@ class PaymentMethodsTest < Minitest::Test unique_number_identifier: "wut" ) ]) - methods = PaymentMethods.for(braintree_customer, ["wut"], {}) + methods = PaymentMethods.for(braintree_customer, ["wut"]) assert_kind_of PaymentMethods, methods assert_equal 0, methods.to_a.length assert methods.empty? end - def test_for_three_d_secure - braintree_customer = Minitest::Mock.new - braintree_customer.expect(:payment_methods, [ - OpenStruct.new( - card_type: "Test", - last_4: "1234", - token: "wut" - ) - ]) - methods = PaymentMethods.for(braintree_customer, [], { "wut" => "hai" }) - assert_kind_of PaymentMethods, methods - assert_equal( - { payment_method_token: "wut", three_d_secure_authentication_id: "hai" }, - methods.fetch(0).transaction_details - ) - end - def test_for_no_methods braintree_customer = Minitest::Mock.new braintree_customer.expect(:payment_methods, []) - methods = PaymentMethods.for(braintree_customer, [], {}) + methods = PaymentMethods.for(braintree_customer, []) assert_kind_of PaymentMethods, methods assert_raises do methods.to_list_single diff --git a/test/test_registration.rb b/test/test_registration.rb index ff19b6741cb22afb065946c590d9b829c998e858..fb681541c55ee661e2031bae998773d5167c1567 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -267,9 +267,6 @@ class RegistrationTest < Minitest::Test braintree_customer ) CustomerFinancials::REDIS.expect(:smembers, [], ["block_credit_cards"]) - CustomerFinancials::REDIS.expect( - :hgetall, [], ["jmp_customer_three_d_secure_authentication_id-test"] - ) braintree_customer.expect( :find, EMPromise.resolve(OpenStruct.new(payment_methods: [])), diff --git a/test/test_transaction.rb b/test/test_transaction.rb index 6a0d10f6c23cbd5038d020ef434a42ea1a18a5e7..5bb348dd711ad245fa489364f3e3caad42535ab9 100644 --- a/test/test_transaction.rb +++ b/test/test_transaction.rb @@ -3,7 +3,6 @@ require "test_helper" require "customer" require "transaction" -require "payment_method" Transaction::DB = Minitest::Mock.new Transaction::BRAINTREE = Minitest::Mock.new @@ -47,7 +46,7 @@ class TransactionTest < Minitest::Test Transaction.sale( customer(plan_name: "test_usd"), amount: 123, - payment_method: PaymentMethod.for(OpenStruct.new(token: "token")) + payment_method: OpenStruct.new(token: "token") ).sync end assert_mock CustomerFinancials::REDIS @@ -80,7 +79,7 @@ class TransactionTest < Minitest::Test result = Transaction.sale( customer(plan_name: "test_usd"), amount: 123, - payment_method: PaymentMethod.for(OpenStruct.new(token: "token")) + payment_method: OpenStruct.new(token: "token") ).sync assert_kind_of Transaction, result assert_mock CustomerFinancials::REDIS