Advertisement
Guest User

refactoring

a guest
Sep 23rd, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def process
  2.   !!if valid_card
  3.     gateway :authorize, credit_card do |auth|
  4.       gateway :capture, auth do |auth|
  5.         update_columns(authorization_code: auth, success: true)
  6.       end
  7.     end
  8.   end
  9. end
  10.  
  11. def gateway(method, subject)
  12.   response = GATEWAY.public_send(method, amount * 100, subject)
  13.  
  14.   if response.success?
  15.     yield response.authorization
  16.   else
  17.     errors.add(:base, "The credit card you provided was declined.  Please double check your information and try again.") and return
  18.   end
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement