Skip to content

Instantly share code, notes, and snippets.

@frojasg
Created June 22, 2017 21:10
Show Gist options
  • Save frojasg/3ad77cb2baa2fecaa56b4d0b759240d2 to your computer and use it in GitHub Desktop.
Save frojasg/3ad77cb2baa2fecaa56b4d0b759240d2 to your computer and use it in GitHub Desktop.
ActiveMerchantSquare
require 'active_merchant_square'
# Get your login and password by going to: https://connect.squareup.com/apps
credentials = {
login: 'APPLICATION_ID',
password: 'APPLICATION_SECRET',
# How to get your location ID, see: https://docs.connect.squareup.com/articles/faq-lookup-my-location-id
location_id: 'LOCATION_ID',
}
amount_cents = 1000 # $10.00
gateway = ActiveMerchant::Billing::SquareGateway.new(credentials)
response = gateway.purchase(amount_cents, card_nonce, {
:description => 'Store Purchase Note'})
if response.success?
puts "Successfully charged $#{sprintf("%.2f", amount_cents / 100)}"
else
raise StandardError, response.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment