Created
May 28, 2009 00:32
-
-
Save anonymous/119003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
User.transaction do | |
promo = user.active_promo | |
active_user_promo = user.active_user_promo | |
address = user.get_address | |
result = user.authorize_credit_card(address) | |
auth_response = result[:auth_response] | |
void_response = result[:void_response] | |
success = result[:success] | |
if success | |
# 1 / 0 may be use user.set_pnref method that updates both pnref and pnref_last_updated | |
user.pnref = auth_response.authorization | |
user.pnref_last_updated = Time.now | |
if user.save! | |
user.log_authorization_and_void_transactions(:promo => promo, :amount => LessonPlanet::Config.auth_amt_in_cents, :auth_response => auth_response, :void_response => void_response, :transaction_description => "Re-Authorization") | |
active_user_promo.reauth_retry_no = 0 | |
active_user_promo.save! | |
end | |
else | |
# if auth fails three times | |
# finally reauth_retry_no will be = 3 | |
# indicating that the user reauth halted at this point | |
# such users would need to manually update their creditcard in the future | |
active_user_promo.reauth_retry_no += 1 | |
active_user_promo.active = active_user_promo.reauth_retry_no < 3 | |
active_user_promo.save! | |
# Make sure to log the transaction after incrementing the reauth_retry_no | |
user.log_authorization_and_void_transactions(:promo => promo, :amount => LessonPlanet::Config.auth_amt_in_cents, :auth_response => auth_response, :void_response => void_response, :transaction_description => "Re-Authorization Retry #{active_user_promo.reauth_retry_no}", :retry_no => active_user_promo.reauth_retry_no) | |
end | |
end | |
rescue Exception => e | |
logger.error "Error in #{__FILE__}: #{__LINE__}" | |
logger.error( e.message ) | |
logger.error( e.backtrace.join("\n" ) ) | |
promo_id = user.active_promo.blank? ? nil : user.active_promo.id | |
user_promo_id = user.active_user_promo.blank? ? nil : user.active_user_promo.id | |
ErrorLog.create(:user_id => user.id, | |
:promotion_id => promo_id, | |
:user_promotion_id => user_promo_id, | |
:error_message => e.message, | |
:error_trace => e.backtrace.join("\n" ), | |
:line_no => __LINE__, | |
:file_name => __FILE__ | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment