~singpolyma/jmp-pay

61c7c01600df15ca4e67e44f7e919e37dd619a26 — Stephen Paul Weber 1 year, 4 months ago dd0f2f2
Factor out with_antifraud helper
1 files changed, 15 insertions(+), 17 deletions(-)

M config.ru
M config.ru => config.ru +15 -17
@@ 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)