-
Notifications
You must be signed in to change notification settings - Fork 22
CRUD
lyang edited this page Mar 16, 2013
·
2 revisions
BraintreeRails provides the same CRUD interface as ActiveRecord objects.
# create in vault
customer = BraintreeRails::Customer.create(:first_name => 'Foo')
# Initialize and save to create
customer = BraintreeRails::Customer.new(:first_name => 'Foo')
customer.save
# Find for given id
customer = BraintreeRails::Customer.find('customer_id')
# Another way to find for given id
customer = BraintreeRails::Customer.new('customer_id')
# Wrap Braintree objects
customer = BraintreeRails::Customer.new(Braintree::Customer.find('customer_id'))
# Assign new value and save
customer = BraintreeRails::Customer.find('customer_id')
customer.company = 'Foo Bar'
customer.save
# Returns true or false when validations failed. Customer#errors will be populated when failed
customer.update_attributes(:website => 'www.example.com')
# Returns true or raises BraintreeRails::RecordInvalid exception
customer.update_attributes!(:email => '[email protected]')
# Delete the customer from the Vault
customer.destroy
BraintreeRails can only support the same set of CRUD capabilities as the braintree_ruby. For example,
Plan
, AddOn
and Discount
only support GET, the same in BraintreeRails.
Transaction
doesn't support update or destroy, but you can create them and change its status afterward through specific methods.