From 61c7c01600df15ca4e67e44f7e919e37dd619a26 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 6 Mar 2023 15:10:55 -0500 Subject: [PATCH] Factor out with_antifraud helper --- config.ru | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/config.ru b/config.ru index f2cc88287bfb7cefd0486356e4ac96cbc49a0f48..e7d18cacff7120239c99a7fbf86427cdc5dd1246 100644 --- a/config.ru +++ b/config.ru @@ -117,31 +117,29 @@ class CreditCardGateway ) end - def incr_antifraud! + def with_antifraud + result = antifraud || yield + return result if result.success? + @antifraud.each do |k| REDIS.incr("jmp_antifraud-#{k}") REDIS.expire("jmp_antifraud-#{k}", 60 * 60 * 24) end - end - def payment_method_create_options - options = { verify_card: true, make_default: true } - if merchant_account - options[:verification_merchant_account_id] = merchant_account.to_s - end - options + raise ErrorResult.for(result) end - def default_method(nonce) - result = antifraud || @gateway.payment_method.create( - customer_id: customer_id, payment_method_nonce: nonce, - options: payment_method_create_options - ) - return result if result.success? - - incr_antifraud! - raise ErrorResult.for(result) + def default_method(nonce) + with_antifraud do + @gateway.payment_method.create( + customer_id: customer_id, payment_method_nonce: nonce, + options: { + verify_card: true, make_default: true, + verification_merchant_account_id: merchant_account.to_s + } + ) + end end def remove_method(token)