A RubyGem for integrating Payload.
To install using Bundler:
gem 'payload-api', '~> 0.2.4'
To install using gem:
gem install payload
Once Payload has been added to your Gemfile and installed, use require
as shown below to import it into your project.
require 'payload'
To authenticate with the Payload API, you'll need a live or test API key. API keys are accessible from within the Payload dashboard.
require 'payload'
Payload.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE'
Interfacing with the Payload API is done primarily through Payload Objects. Below is an example of
creating a customer using the Payload::Customer
object.
# Create a Customer
customer = Payload::Customer.create(
email: '[email protected]',
name: 'Matt Perez'
)
# Create a Payment
payment = Payload::Payment.create(
amount: 100.0,
payment_method: Payload::Card(
card_number: '4242 4242 4242 4242'
)
)
Object attributes are accessible through both dot and bracket notation.
customer.name
customer['name']
Updating an object is a simple call to the update
object method.
# Updating a customer's email
customer.update( email: '[email protected]' )
Objects can be selected using any of their attributes.
# Select a customer by email
customers = Payload::Customer.filter_by(
email: '[email protected]'
)
To get further information on Payload's RubyGem and API capabilities, visit the unabridged Payload Documentation.