Skip to content

Instantly share code, notes, and snippets.

@johnpitchko
Last active June 3, 2024 17:45
Show Gist options
  • Save johnpitchko/08b8bc2e544a4dd099f4df40e65143a8 to your computer and use it in GitHub Desktop.
Save johnpitchko/08b8bc2e544a4dd099f4df40e65143a8 to your computer and use it in GitHub Desktop.
Cancel Braintree authorizations
# Retrieve/display the credentials
# Create a new Braintree gateway instance using the credentials from Solidus
# Note credentials below are for sandbox
store = Spree::Store.default
environment = store.fetch('BRAINTREE_ENVIRONMENT')
merchant_id = store.fetch('BRAINTREE_MERCHANT_ID')
public_key = store.fetch('BRAINTREE_PUBLIC_KEY')
private_key = store.fetch('BRAINTREE_PRIVATE_KEY')
gateway = gateway = Braintree::Gateway.new(environment: environment, merchant_id: merchant_id, public_key: public_key, private_key: private_key)
# Execute a complex search by stacking query methods on the `search` object defined in the block.
transactions = gateway.transaction.search do |search|
search.status.in(
Braintree::Transaction::Status::Authorized
)
search.customer_email.is 'bryan@chord.co'
end
# The returned transactions that meet the specified criteria can be interated using #each.
transactions.each do |txn|
puts "#{txn.created_at} #{txn.status}"
end
# Search for custoemrs by email. # Returns a list of IDs that can be used to retrieve the customer.
customers = gateway.customer.search do |search|
search.email.is 'email@hotmail.com'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment