Class: TrustCommerce::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/trustcommerce.rb

Class Method Summary collapse

Class Method Details

.charge(options) ⇒ Object

Process one-time sale against existing subscription

response = TrustCommerce::Subscription.charge( :billingid => 'ABC123', :amount => 1995 )



133
134
135
# File 'lib/trustcommerce.rb', line 133

def self.charge(options)
  return TrustCommerce.send_request(options.merge(:action => 'sale'))
end

.create(options) ⇒ Object

Bill Jennifer $12.00 monthly

response = TrustCommerce::Subscription.create( :cc => '4111111111111111', :exp => '0412', :name => 'Jennifer Smith', :amount => 1200, :cycle => '1m' )

if response['status'] == 'approved'
puts "Subscription created with Billing ID: #{response['billingid']}"
else
puts "An error occurred: #{response['error']}"
end


94
95
96
# File 'lib/trustcommerce.rb', line 94

def self.create(options)
  return TrustCommerce.send_request(options.merge(:action => 'store'))
end

.credit(options) ⇒ Object

Process one-time credit against existing transaction

response = TrustCommerce::Subscription.credit( :transid => '001-0000111101', :amount => 1995 )



142
143
144
# File 'lib/trustcommerce.rb', line 142

def self.credit(options)
  return TrustCommerce.send_request(options.merge(:action => 'credit'))
end

.delete(options) ⇒ Object

Delete subscription

response = TrustCommerce::Subscription.delete( :billingid => 'ABC123' )

if response['status'] == 'accepted'
puts 'Subscription removed from active use.'
else
puts 'An error occurred.'
end


124
125
126
# File 'lib/trustcommerce.rb', line 124

def self.delete(options)
  return TrustCommerce.send_request(options.merge(:action => 'unstore'))
end

.query(options) ⇒ Object

Get all sale transactions for a subscription in CSV format

response = TrustCommerce::Subscription.query( :querytype => 'transaction', :action => 'sale', :billingid => 'ABC123' )



152
153
154
# File 'lib/trustcommerce.rb', line 152

def self.query(options)
  return TrustCommerce.send_query(options)
end

.update(options) ⇒ Object

Update subscription to use new credit card

response = TrustCommerce::Subscription.update( :billingid => 'ABC123', :cc => '5411111111111115', :exp => '0412' )

if response['status'] == 'accepted'
puts 'Subscription updated.'
else
puts "An error occurred: #{response['error']}"
end


110
111
112
# File 'lib/trustcommerce.rb', line 110

def self.update(options)
  return TrustCommerce.send_request(options.merge(:action => 'store'))
end