Class: PaySimple::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/paysimple/paysimple.rb

Class Method Summary collapse

Class Method Details

.charge(customer_number, options, command = "", payment_method_id = 0) ⇒ Object

# Process one-time sale against existing subscription begin

customer_number = 12345
response = PaySimple::Subscription.charge(customer_number, :Amount => 34.56)

if response["Response"] == "Approved"
  puts "One-time charge successful."
else
  puts "An error occurred: #{response["Error"]}"
end

rescue Exception => e

puts "An error occurred: #{e.message}"

end



203
204
205
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 203

def charge(customer_number, options, command = "", payment_method_id = 0)
  PaySimple.send_request(:runCustomerTransaction, customer_number, options, command, payment_method_id)
end

.create(options) ⇒ Object

# Bill Jennifer $12.00 monthly begin

customer_number = PaySimple::Subscription.create(
  :CustomerID => 12345,
  :BillingAddress => {
    :FirstName => "Jennifer",
    :LastName => "Smith"
  },
  :CreditCardData => {
    :CardNumber => "4444555566667779",
    :CardExpiration => "0908"
  },
  :Schedule => :monthly,
  :Next => "2008-09-05",
  :Amount => 12.00
)

puts "Subscription created with Customer Number: #{customer_number}"

rescue Exception => e

puts "An error occurred: #{e.message}"

end



65
66
67
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 65

def create(options)
  PaySimple.send_request(:addCustomer, { :Source => PaySimple.source, :NumLeft => 0, :Enabled => true }.merge(options))
end

.delete(customer_number) ⇒ Object

# Delete subscription begin

customer_number = 12345
response = PaySimple::Subscription.delete(customer_number)

puts "Subscription removed from active use."

rescue Exception => e

puts "An error occurred: #{e.message}"

end



173
174
175
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 173

def delete(customer_number)
  PaySimple.send_request(:deleteCustomer, customer_number)
end

.find(customer_number) ⇒ Object

# Find an existing subscription begin

customer_number = 12345
customer = PaySimple::Subscription.find(customer_number)

puts "Found subscription for #{customer["BillingAddress"]["FirstName"], customer["BillingAddress"]["LastName"]].join(" ")}"

rescue Exception => e

puts "An error occurred: #{e.message}"

end



186
187
188
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 186

def find(customer_number)
  PaySimple.send_request(:getCustomer, customer_number)
end

.query(options) ⇒ Object

# Search for transactions begin

response = PaySimple::Subscription.query(
  [ 
    { :Field => "amount", :Type => "gt", :Value => "5.0" }
  ]
)

response.transactions.each do |transaction|
  puts "CustomerID = #{transaction["CustomerID"]}, Amount = #{transaction["Details"]["Amount"]}"
end

rescue Exception => e

puts "An error occurred: #{e.message}"

end



221
222
223
224
225
226
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 221

def query(options)
  match_all = options.delete(:match_all)
  start = options.delete(:start) || 0
  limit = options.delete(:limit) || 100
  PaySimple.send_request(:searchTransactions, options, match_all, start, limit)
end

.update(customer_number, options) ⇒ Object

# Update subscription to use new credit card begin

customer_number = 12345
response = PaySimple::Subscription.update(
  customer_number,
  :CreditCardData => {
    :CardNumber => "4444555566667779",
    :CardExpiration => "0908"
  }
)

puts "Subscription updated"

rescue Exception => e

puts "An error occurred: #{e.message}"

end



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/active_merchant/billing/gateways/paysimple/paysimple.rb', line 84

def update(customer_number, options)
  customer = find(customer_number)
  options = PaySimple.symbolize_hash(options)
  
  # Add the existing customer properties to the options hash unless they already exist
  [
    :CustomerID,
    :SendReceipt, 
    :ReceiptNote, 
    :Notes, 
    :User, 
    :Source, 
    :Schedule, 
    :Next,
    :NumLeft, 
    :Amount, 
    :Enabled, 
    :CustomData, 
    :Description, 
    :OrderID
  ].each do |property|
    options[property] = customer[property.to_s] unless options.has_key?(property)
  end
  
  # Add the existing customer address properties to the options hash unless they already exist
  options[:BillingAddress] ||= {}
  [
    :FirstName,
    :LastName,
    :Company,
    :Street,
    :Street2,
    :City,
    :State,
    :Zip,
    :Country,
    :Phone,
    :Fax,
    :Email
  ].each do |property|
    options[:BillingAddress][property] = customer["BillingAddress"][property.to_s] unless options[:BillingAddress].has_key?(property)
  end
  
  # Add the existing customer credit card properties to the options hash unless they already exist
  options[:CreditCardData] ||= {}
  [
    :CardNumber,
    :CardExpiration,
    :CardCode,
    :AvsStreet,
    :AvsZip,
    :CardPresent,
    :MagStripe,
    :TermType,
    :MagSupport,
    :XID,
    :CAVV,
    :ECI,
    :InternalCardAuth,
    :Pares
  ].each do |property|
    options[:CreditCardData][property] = customer["CreditCardData"][property.to_s] unless options[:CreditCardData].has_key?(property)
  end
  
  # Add the existing customer check properties to the options hash unless they already exist
  options[:CheckData] ||= {}
  [
    :CheckNumber,
    :Routing,
    :Account,
    :SSN,
    :DriversLicense,
    :DriversLicenseState
  ].each do |property|
    options[:CheckData][property] = customer["CheckData"][property.to_s] unless options[:CheckData].has_key?(property)
  end
  
  PaySimple.send_request(:updateCustomer, customer_number, { :Source => PaySimple.source, :NumLeft => 0 }.merge(options))
end