Guest User

Untitled

a guest
Feb 19th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. def run_transaction_paypal_wpp(remote_ip)
  2. ba = self.billing_address
  3. logger.info ("\n\n\n\n Before credit_card:#{self.account.cc_type} \n\n\n\n")
  4. credit_card = ActiveMerchant::Billing::CreditCard.new(
  5. :type => self.account.cc_type.to_s,
  6. :number => self.account.cc_number,
  7. :month => self.account.expiration_month,
  8. :year => self.account.expiration_year,
  9. :first_name => ba.first_name,
  10. :last_name => ba.last_name
  11. )
  12. logger.info ("\n\n\n\n before gateway:#{self.account.cc_type} \n\n\n\n")
  13. if credit_card.valid?
  14. # Create a gateway object to the Authorize.net service
  15. gateway = ActiveMerchant::Billing::PaypalGateway.new(
  16. :login => Preference.find_by_name('cc_login').value,
  17. :password => Preference.find_by_name('cc_pass').value,
  18. :ssl_strict => true,
  19. :test => Preference.find_by_name('store_test_transactions').is_true?
  20. )
  21. logger.info ("\n\n\n\n Before billing_address:#{self.account.cc_type} \n\n\n\n")
  22. billing_address = {
  23. :address1 => ba.address,
  24. :address2 => '',
  25. :city => ba.city,
  26. :state => ba.state,
  27. :zip => ba.zip,
  28. :country => ba.country.fedex_code,
  29. :phone => ba.telephone
  30. }
  31. logger.info ("\n\n\n\n Before response:#{self.account.cc_type} \n\n\n\n")
  32. # AM requires it's purchaes in CENTS, so adjust accordingly.
  33. response = gateway.purchase(self.total.to_f*100, credit_card, :ip => remote_ip, :billing_address => billing_address)
  34. logger.info ("\n\n\n\n Before auth_transaction_id:#{self.account.cc_type} \n\n\n\n")
  35. # Save transaction id for later
  36. self.auth_transaction_id = response.params[:transaction_id]
  37. logger.info ("\n\n\n\n Before response.success?:#{self.account.cc_type} \n\n\n\n")
  38. # Handle the response
  39. if response.success?
  40. logger.info("\n\nORDER TRANSACTION ID - #{self.auth_transaction_id}\n\n")
  41. # Set completed
  42. self.cleanup_successful
  43. # Send success message
  44. begin
  45. self.deliver_receipt
  46. rescue => e
  47. logger.error("FAILED TO SEND THE CONFIRM EMAIL: #{e}")
  48. end
  49. return true
  50. else
  51. # Log errors
  52. logger.error("\n\n[ERROR] FAILED ORDER \n")
  53. logger.error(response.inspect)
  54. logger.error(response.message)
  55. logger.error("\n\n")
  56. # Order failed - store transaction id
  57. self.cleanup_failed(response.message)
  58. # Send failed message
  59. begin
  60. self.deliver_failed
  61. rescue => e
  62. logger.error("FAILED TO SEND THE CONFIRM EMAIL: #{e}")
  63. end
  64.  
  65. return response.message
  66. end
  67.  
  68. return false
  69. end
  70. end
Add Comment
Please, Sign In to add comment