From 0db41928fe720a6ba5a593ea6636c7302a6b9c42 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 26 Apr 2022 14:37:37 -0500 Subject: [PATCH] Revert "Merge branch 'three_d_secure'" This reverts commit 36f441c031a5318385ec78d7d2e021a8e2fab186, reversing changes made to 3b0ae3c9387d3be41b30bd6dd4552ff0a841d8ed. --- lib/customer_finacials.rb | 13 ++----------- lib/payment_method.rb | 29 ---------------------------- lib/payment_methods.rb | 6 ++---- lib/transaction.rb | 7 ++++--- test/test_buy_account_credit_form.rb | 3 --- test/test_payment_methods.rb | 29 ++++------------------------ test/test_registration.rb | 3 --- test/test_transaction.rb | 5 ++--- 8 files changed, 14 insertions(+), 81 deletions(-) delete mode 100644 lib/payment_method.rb diff --git a/lib/customer_finacials.rb b/lib/customer_finacials.rb index e2353be..07c33ea 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 fea2133..0000000 --- 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 8ea008f..2bbf08a 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 9bf759e..83e8e15 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 fbcdd51..4b052ef 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 f5d79e1..0971e7b 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 ff19b67..fb68154 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 6a0d10f..5bb348d 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 -- 2.38.5