Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickberkeley/7245 to your computer and use it in GitHub Desktop.
Save patrickberkeley/7245 to your computer and use it in GitHub Desktop.
def run_transaction_paypal_wpp(remote_ip)
ba = self.billing_address
logger.info ("\n\n\n\n Before credit_card:#{self.account.cc_type} \n\n\n\n")
credit_card = ActiveMerchant::Billing::CreditCard.new(
:type => self.account.cc_type.to_s,
:number => self.account.cc_number,
:month => self.account.expiration_month,
:year => self.account.expiration_year,
:first_name => ba.first_name,
:last_name => ba.last_name
)
logger.info ("\n\n\n\n before gateway:#{self.account.cc_type} \n\n\n\n")
if credit_card.valid?
# Create a gateway object to the Authorize.net service
gateway = ActiveMerchant::Billing::PaypalGateway.new(
:login => Preference.find_by_name('cc_login').value,
:password => Preference.find_by_name('cc_pass').value,
:ssl_strict => true,
:test => Preference.find_by_name('store_test_transactions').is_true?
)
logger.info ("\n\n\n\n Before billing_address:#{self.account.cc_type} \n\n\n\n")
billing_address = {
:address1 => ba.address,
:address2 => '',
:city => ba.city,
:state => ba.state,
:zip => ba.zip,
:country => ba.country.fedex_code,
:phone => ba.telephone
}
logger.info ("\n\n\n\n Before response:#{self.account.cc_type} \n\n\n\n")
# AM requires it's purchaes in CENTS, so adjust accordingly.
response = gateway.purchase(self.total.to_f*100, credit_card, :ip => remote_ip, :billing_address => billing_address)
logger.info ("\n\n\n\n Before auth_transaction_id:#{self.account.cc_type} \n\n\n\n")
# Save transaction id for later
self.auth_transaction_id = response.params[:transaction_id]
logger.info ("\n\n\n\n Before response.success?:#{self.account.cc_type} \n\n\n\n")
# Handle the response
if response.success?
logger.info("\n\nORDER TRANSACTION ID - #{self.auth_transaction_id}\n\n")
# Set completed
self.cleanup_successful
# Send success message
begin
self.deliver_receipt
rescue => e
logger.error("FAILED TO SEND THE CONFIRM EMAIL: #{e}")
end
return true
else
# Log errors
logger.error("\n\n[ERROR] FAILED ORDER \n")
logger.error(response.inspect)
logger.error(response.message)
logger.error("\n\n")
# Order failed - store transaction id
self.cleanup_failed(response.message)
# Send failed message
begin
self.deliver_failed
rescue => e
logger.error("FAILED TO SEND THE CONFIRM EMAIL: #{e}")
end
return response.message
end
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment