Perform gateway operations like purchase, authorize, and capture
masterActive Merchant uses subclasses of ActiveMerchant::Billing::Gateway to interface with payment gateways. You can perform three primary operations on a gateway instance:
#authorize: Reserves the required amount on the card holder's credit card.#capture: Collects the previously authorized funds.#purchase: Combines authorization and capture into a single operation.
All three methods return an ActiveMerchant::Billing::Response object. Use response.success? to check if the operation worked and response.message to retrieve error details if it failed.
gateway = SomeGateway.new
# Amounts are always specified in cents, so $10.00 is 1000 cents
response = gateway.purchase(1000, credit_card)
if response.success?
puts "Payment complete!"
else
puts "Payment failed: #{response.message}"
end