Recharge 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ # Examples for the Recharge API Gem
2
+ # Charge Resource
3
+
4
+ # Only 2 lines are required to get started:
5
+ # Require the recharge.rb file
6
+ require '../lib/recharge'
7
+
8
+ # Set your API key here, found in Recharge Settings > API Settings > API Private Key
9
+ # If incorrect or blank, any calls will raise a Response::NotAuthorized
10
+ Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ # Find an individual charge by the charge ID
20
+ puts "", "Find Individual Charge"
21
+
22
+ begin
23
+ # Records are fetched by their unique identifiers.
24
+ charge = Recharge::Charge.find('ch4f3af9b81df18')
25
+
26
+ # attributes can be accessed individually like this
27
+ puts ">> charge id: #{charge.id}"
28
+ puts ">> payment plan: #{charge.price} charged every #{charge.intervalValue} #{charge.intervalUnit}", ''
29
+
30
+ # or you may inspect the whole record and get a list of all keys/values like this
31
+ p charge
32
+ rescue Exception => e
33
+ # If the record doesn't exist, a Response::NotFound exception will
34
+ # be raised.
35
+ puts ">> error #{e.message}"
36
+ end
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ # create a new charge for a customer
46
+ puts "", "Create New Charge"
47
+
48
+ begin
49
+ # charges can be created in one fell swoop
50
+ charge = Recharge::Charge.create(
51
+ :customer => "cu4f3782bf374a7",
52
+ :payMethod => "pm4f3b214680f5f",
53
+ :billingStartDate => "5/21/2012",
54
+ :product => "pr4f379194192df"
55
+ )
56
+ # after the charge is saved, all attributes are available for you individually or by inspecting
57
+ chargeID = charge.id
58
+ p charge
59
+ rescue Exception => e
60
+ # if a required field is missing or invalid, a Response::BadRequest error will be raised
61
+ # e.message will give more info why the record creation failed
62
+ puts ">> error #{e.message}"
63
+ end
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ # Update an existing charge (change billing amount, card number, etc)
74
+ puts "", "Update Charge"
75
+
76
+ begin
77
+ # you must find the charge id first
78
+ charge = Recharge::Charge.find(chargeID)
79
+ # then call update on it
80
+ # you only need to pass the attributes you want to update
81
+ charge.update(
82
+ :product => "pr4f3b29e2b5813"
83
+ )
84
+ # all updated information about the charge is now available
85
+ p charge
86
+ rescue Exception => e
87
+ # errors here can be
88
+ # Response::NotFound if the charge ID does not exist
89
+ # Response::BadRequest if there was something wrong with the request
90
+ puts ">> error #{e.message}"
91
+ end
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ # deletes an existing charge
103
+ # deletes the charge, cancels all future transactions that were scheduled for this charge
104
+ puts "", "Delete Charges"
105
+
106
+ begin
107
+ # find the charge first
108
+ charge = Recharge::Charge.find(chargeID)
109
+ # call destroy on it to delete it
110
+ charge.destroy
111
+ rescue Exception => e
112
+ puts ">> error #{e.message}"
113
+ end
@@ -0,0 +1,166 @@
1
+ # Examples for the Recharge API Gem
2
+ # Charge Resource
3
+
4
+ # Only 2 lines are required to get started:
5
+ # Require the recharge.rb file
6
+ require '../lib/recharge'
7
+
8
+ # Set your API key here, found in Recharge Settings > API Settings > API Private Key
9
+ # If incorrect or blank, any calls will raise a Response::NotAuthorized
10
+ Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ # Get a list of all active customers
20
+ puts "Find All Customers",''
21
+
22
+ begin
23
+ # call find_all to get a list of all customers
24
+ Recharge::Customer.find_all.each do |customer|
25
+
26
+ # attributes can be accessed individually like this
27
+ puts "id: #{customer.id}"
28
+ puts "name: #{customer.firstName} #{customer.lastName}"
29
+ puts "email: #{customer.email}"
30
+
31
+ # or you may inspect the whole record and get a list of all keys/values like this
32
+ p customer
33
+
34
+ customerID = customer.id
35
+
36
+ # each customer record has many payMethods (stored card numbers or bank accounts), so make sure you loop through these
37
+ customer.payMethods.each do |paymethod|
38
+ puts ">> paymethod id: #{paymethod.id}"
39
+ puts ">> card number: #{paymethod.cardType} ****#{paymethod.last4}"
40
+ end
41
+
42
+ # each customer record has many charges, same as payMethods
43
+ customer.charges.each do |charge|
44
+ puts ">> charge id: #{charge.id}"
45
+ puts ">> payment plan: #{charge.price} charged every #{charge.intervalValue} #{charge.intervalUnit}", ''
46
+ end
47
+ end
48
+ rescue Exception => e
49
+ puts ">> error #{e.message}"
50
+ end
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ # Find an individual customer by the customer ID
65
+ puts "", "Find Individual Customers"
66
+
67
+ begin
68
+ # Records are fetched by their unique identifiers.
69
+ customer = Recharge::Customer.find(customerID)
70
+
71
+ puts "id: #{customer.id}"
72
+ puts "name: #{customer.firstName} #{customer.lastName}"
73
+ puts "email: #{customer.email}"
74
+
75
+ customer.payMethods.each do |paymethod|
76
+ puts ">> paymethod id: #{paymethod.id}"
77
+ puts ">> card number: #{paymethod.cardType} ****#{paymethod.last4}"
78
+ end
79
+ customer.charges.each do |charge|
80
+ puts ">> charge id: #{charge.id}"
81
+ puts ">> payment plan: #{charge.price} charged every #{charge.intervalValue} #{charge.intervalUnit}"
82
+ end
83
+ rescue Exception => e
84
+ puts ">> error #{e.message}"
85
+ end
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ # create a new customer
97
+ puts "", "Create New Customer"
98
+
99
+ begin
100
+ # customers can be created in one fell swoop
101
+ customer = Recharge::Customer.create(
102
+ :firstName => "Eric",
103
+ :lastName=> "Cardin",
104
+ :email=> "email@rechargebilling.com"
105
+ )
106
+
107
+ # after the customer is saved, all attributes are available for you individually or by inspecting
108
+ customerID = customer.id
109
+ p customer
110
+ rescue Exception => e
111
+ puts ">> error #{e.message}"
112
+ end
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+ # Update an existing customer (change email address, phone number, etc)
127
+ puts "", "Update Customer"
128
+
129
+ begin
130
+ # you must find the charge id first
131
+ customer = Recharge::Customer.find(customerID)
132
+
133
+ # then call update on it
134
+ # you only need to pass the attributes you want to update
135
+ customer.update(
136
+ :refID=> Time.now.to_i
137
+ )
138
+
139
+ # all updated information about the charge is now available
140
+ p customer
141
+ rescue Exception => e
142
+ puts ">> error #{e.message}"
143
+ end
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+ # deletes an existing customer
158
+ # deletes the customer, payment methods, cancels all future transactions that were scheduled for this charge
159
+ puts "", "Delete Customer"
160
+
161
+ begin
162
+ customer = Recharge::Customer.find(customerID)
163
+ customer.destroy
164
+ rescue Exception => e
165
+ puts ">> error #{e.message}"
166
+ end
@@ -0,0 +1,30 @@
1
+ require '../lib/recharge'
2
+
3
+ Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
4
+
5
+ puts "", "Create New PayMethod"
6
+
7
+ begin
8
+ paymethod = Recharge::PayMethod.create(
9
+ :customer => "cu4f3782bf374a7",
10
+ :nameOnCard => "test jones",
11
+ :cardNumber => "4242424242424242",
12
+ :expDate => "1212"
13
+ )
14
+ paymethodID = paymethod.id
15
+ puts ">> paymethod id: #{paymethod.id}"
16
+ puts ">> card number: #{paymethod.cardType} ****#{paymethod.last4}"
17
+ p paymethod
18
+ rescue Exception => e
19
+ puts ">> error #{e.message}"
20
+ end
21
+
22
+
23
+
24
+ puts "", "Delete PayMethod"
25
+
26
+ begin
27
+ Recharge::PayMethod.destroy(paymethodID)
28
+ rescue Exception => e
29
+ puts ">> error #{e.message}"
30
+ end
@@ -0,0 +1,74 @@
1
+ require '../lib/recharge'
2
+
3
+ Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
4
+
5
+ productID = ""
6
+
7
+ puts "Find All Products",''
8
+
9
+ begin
10
+ Recharge::Product.find_all.each do |product|
11
+ puts "id: #{product.id}"
12
+ puts "name: #{product.name}"
13
+ puts "price: #{product.price}"
14
+
15
+ productID = product.id
16
+ end
17
+ rescue Exception => e
18
+ puts ">> error #{e.message}"
19
+ end
20
+
21
+ puts "", "Find Individual Products"
22
+
23
+ begin
24
+ product = Recharge::Product.find(productID)
25
+
26
+ puts "id: #{product.id}"
27
+ puts "name: #{product.name}"
28
+ puts "price: #{product.price}"
29
+
30
+ rescue Exception => e
31
+ puts ">> error #{e.message}"
32
+ end
33
+
34
+
35
+
36
+ puts "", "Create New Product"
37
+
38
+ begin
39
+ product = Recharge::Product.create(
40
+ :name => "HeyHey",
41
+ :price => "100",
42
+ :intervalValue => 1,
43
+ :intervalUnit => 'm'
44
+ )
45
+ productID = product.id
46
+ p product
47
+ rescue Exception => e
48
+ puts ">> error #{e.message}"
49
+ end
50
+
51
+
52
+
53
+ puts "", "Update Product"
54
+
55
+ begin
56
+ product = Recharge::Product.find(productID)
57
+ product.update(
58
+ :price=> "101"
59
+ )
60
+ p product
61
+ rescue Exception => e
62
+ puts ">> error #{e.message}"
63
+ end
64
+
65
+
66
+
67
+ puts "", "Delete Product"
68
+
69
+ begin
70
+ product = Recharge::Product.find(productID)
71
+ product.destroy
72
+ rescue Exception => e
73
+ puts ">> error #{e.message}"
74
+ end
@@ -0,0 +1,76 @@
1
+ require '../lib/recharge'
2
+
3
+ Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
4
+
5
+ puts "", "Credit Card Purchase"
6
+
7
+ begin
8
+ transaction = Recharge::Transaction.purchase(
9
+ :Amount => "#{rand(100)}.#{rand(100)}",
10
+ :AcctNum => "4242424242424242",
11
+ :ExpDate => "1212"
12
+ )
13
+ puts transaction.responseDescription, transaction.amount, transaction.approvalCode
14
+ p transaction
15
+
16
+ transactionID = transaction.transactionID
17
+ rescue Exception => e
18
+ puts ">> error #{e.message}"
19
+ end
20
+
21
+
22
+
23
+
24
+
25
+
26
+ puts "", "Credit Card Refund (with card number)"
27
+
28
+ begin
29
+ transaction = Recharge::Transaction.refund(
30
+ :Amount => "#{rand(100)}.#{rand(100)}",
31
+ :AcctNum => "4111111111111111",
32
+ :ExpDate => "1212"
33
+ )
34
+ puts transaction.responseDescription, transaction.amount, transaction.approvalCode
35
+ p transaction
36
+ rescue Exception => e
37
+ puts ">> error #{e.message}"
38
+ end
39
+
40
+
41
+
42
+
43
+
44
+
45
+ puts "", "Credit Card Refund (without card number)"
46
+
47
+ begin
48
+ transaction = Recharge::Transaction.refund(
49
+ :TransactionID => transactionID,
50
+ :Amount => "0.#{rand(100)}"
51
+ )
52
+ puts transaction.responseDescription, transaction.amount, transaction.approvalCode
53
+ p transaction
54
+
55
+ transactionID = transaction.transactionID
56
+ rescue Exception => e
57
+ puts ">> error #{e.message}"
58
+ end
59
+
60
+
61
+
62
+
63
+
64
+
65
+ puts "", "Credit Card Void"
66
+
67
+ begin
68
+ transaction = Recharge::Transaction.void(
69
+ :TransactionID => transactionID
70
+ )
71
+ puts transaction.responseDescription, transaction.amount, transaction.approvalCode
72
+ p transaction
73
+ rescue Exception => e
74
+ puts ">> error #{e.message}"
75
+ end
76
+
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Recharge
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 21
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Recharge
@@ -14,8 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2012-02-15 00:00:00 -08:00
18
- default_executable:
18
+ date: 2012-02-15 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: An API client library for Recharge http://rechargebilling.com
@@ -41,8 +41,11 @@ files:
41
41
  - lib/recharge/response.rb
42
42
  - lib/recharge/transaction.rb
43
43
  - lib/recharge.rb
44
- - lib/test.rb
45
- has_rdoc: true
44
+ - examples/charge.rb
45
+ - examples/customer.rb
46
+ - examples/paymethod.rb
47
+ - examples/product.rb
48
+ - examples/transaction.rb
46
49
  homepage: http://rechargebilling.com/api
47
50
  licenses: []
48
51
 
@@ -52,23 +55,27 @@ rdoc_options: []
52
55
  require_paths:
53
56
  - lib
54
57
  required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
55
59
  requirements:
56
60
  - - ">="
57
61
  - !ruby/object:Gem::Version
62
+ hash: 3
58
63
  segments:
59
64
  - 0
60
65
  version: "0"
61
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
62
68
  requirements:
63
69
  - - ">="
64
70
  - !ruby/object:Gem::Version
71
+ hash: 3
65
72
  segments:
66
73
  - 0
67
74
  version: "0"
68
75
  requirements: []
69
76
 
70
77
  rubyforge_project:
71
- rubygems_version: 1.3.6
78
+ rubygems_version: 1.8.16
72
79
  signing_key:
73
80
  specification_version: 3
74
81
  summary: Recharge API Client
data/lib/test.rb DELETED
@@ -1,520 +0,0 @@
1
- module Recharge
2
- require 'happymapper'
3
-
4
- class << self
5
- def api_key
6
- defined? @api_key and @api_key
7
- end
8
- attr_writer :api_key
9
- end
10
-
11
- class PayMethod
12
- include HappyMapper
13
-
14
- tag 'payMethod'
15
-
16
- element :id, String
17
- element :alias, String
18
- element :cardType, String
19
- element :last4, String
20
- element :expDate, String
21
- element :nameOnCard, String
22
- end
23
-
24
- class Customer
25
- include HappyMapper
26
-
27
- tag 'customer'
28
-
29
- element :id, String
30
- element :refID, String
31
- element :firstName, String
32
- element :lastName, String
33
- element :email, String
34
- element :company, String
35
- element :phone, String
36
- element :billingAddress1, String
37
- element :billingAddress2, String
38
- element :billingCity, String
39
- element :billingState, String
40
- element :billingZIP, String
41
- element :shippingAddress1, String
42
- element :shippingAddress2, String
43
- element :shippingCity, String
44
- element :shippingState, String
45
- element :shippingZIP, String
46
- element :emailOption, String
47
- element :signupDate, String
48
-
49
- has_many :payMethods, PayMethod
50
-
51
- def initialize(id='')
52
- @id = id
53
- end
54
- def self.find_all
55
- responseXML = get('customers')
56
- parse(responseXML.to_s)
57
- end
58
- def self.find (id)
59
- responseXML = get('customers/'+id)
60
- parse(responseXML.to_s)
61
- end
62
- def self.create (attributes = {})
63
- responseXML = post('customers', attributes)
64
- parse(responseXML.to_s)
65
- end
66
- def update (attributes = {})
67
- responseXML = post('customers/'+self.id, attributes)
68
- Customer.parse(responseXML.to_s)
69
- end
70
- def destroy (attributes = {})
71
- responseXML = delete('customers/'+self.id)
72
- end
73
- end
74
-
75
- class Product
76
- include HappyMapper
77
-
78
- tag 'product'
79
-
80
- element :id, String
81
- element :name, String
82
- element :setupFee, String
83
- element :price, String
84
- element :intervalValue, String
85
- element :intervalUnit, String
86
-
87
- def initialize(id='')
88
- @id = id
89
- end
90
- def self.find_all
91
- responseXML = get('products')
92
- parse(responseXML.to_s)
93
- end
94
- def self.find (id)
95
- responseXML = get('products/'+id)
96
- parse(responseXML.to_s)
97
- end
98
- def self.create (attributes = {})
99
- responseXML = post('products', attributes)
100
- parse(responseXML.to_s)
101
- end
102
- def update (attributes = {})
103
- responseXML = post('products/'+self.id, attributes)
104
- Product.parse(responseXML.to_s)
105
- end
106
- def destroy (attributes = {})
107
- responseXML = delete('products/'+self.id)
108
- end
109
- end
110
-
111
- end
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
- def get(uri)
153
- client = Client.new()
154
- return client.request('GET', uri)
155
- end
156
-
157
- def post(uri, data=nil)
158
- client = Client.new()
159
- return client.request('POST', uri, data)
160
- end
161
-
162
- def delete(uri)
163
- client = Client.new()
164
- return client.request('DELETE', uri)
165
- end
166
-
167
- def returnImportantXML(data)
168
- require "rexml/document"
169
- doc = REXML::Document.new(data)
170
-
171
- if doc.elements[1].elements[3].length == 1
172
- return doc.elements[1].elements[3].elements[1]
173
- else
174
- return doc.elements[1].elements[3]
175
- end
176
- end
177
-
178
- def returnErrorXML(data)
179
- require "rexml/document"
180
- doc = REXML::Document.new(data)
181
-
182
- doc.elements["/response/result/resultDescription"].text
183
- end
184
-
185
- def returnStatusXML(data)
186
- require "rexml/document"
187
- doc = REXML::Document.new(data)
188
-
189
- doc.elements["/response/result/resultDescription"]
190
- end
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
- class Client
231
-
232
- def baseURL
233
- "https://www.rechargebilling.com/API/v2/"
234
- end
235
-
236
- def request(method, uri, data=nil)
237
- response = sendRequest(method, uri, data)
238
- response.assertValidResponse
239
- if response.code.to_i == 200
240
- if method != "DELETE"
241
- returnImportantXML(response.body)
242
- else
243
- returnStatusXML(response.body)
244
- end
245
- else
246
- returnErrorXML(response.body)
247
- end
248
-
249
- end
250
-
251
- def sendRequest(method, uri, data=nil)
252
- require "net/https"
253
- require "uri"
254
-
255
- if !Recharge.api_key
256
- puts "no api key"
257
- return
258
- end
259
-
260
- uri = baseURL+uri
261
- uri = URI.parse(uri)
262
-
263
- if method == "GET"
264
- request = Net::HTTP::Get.new(uri.request_uri)
265
- end
266
-
267
- if method == "POST"
268
- request = Net::HTTP::Post.new(uri.request_uri)
269
- request.set_form_data(data)
270
- end
271
-
272
- if method == "DELETE"
273
- request = Net::HTTP::Delete.new(uri.request_uri)
274
- end
275
-
276
- request.basic_auth(Recharge.api_key, "")
277
-
278
- http = Net::HTTP.new(uri.host, uri.port)
279
- http.use_ssl = true
280
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
281
-
282
- response = http.request(request)
283
-
284
- return Response.new(response.code, response.body)
285
-
286
- end
287
- end
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
- class Response
329
- def initialize(code, body)
330
- @code = code
331
- @body = body
332
- end
333
- def code
334
- @code
335
- end
336
- def body
337
- @body
338
- end
339
-
340
- class NotFound < StandardError
341
- end
342
-
343
- class BadRequest < StandardError
344
- end
345
-
346
- def assertValidResponse
347
- case @code.to_i
348
- when 200
349
- return
350
- when 400
351
- raise NotFound, returnErrorXML(@body)
352
- when 404
353
- raise NotFound, returnErrorXML(@body)
354
- end
355
- end
356
- end
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
- Recharge.api_key = "92ec3e4d8b623dd9baaaf1575b7c557cd113e3e8"
439
-
440
- customerID = ""
441
-
442
- puts "Find All Customers"
443
-
444
- begin
445
- Recharge::Customer.find_all.each do |customer|
446
- puts "id: #{customer.id}"
447
- puts "name: #{customer.firstName} #{customer.lastName}"
448
- puts "email: #{customer.email}"
449
-
450
- customerID = customer.id
451
-
452
- customer.payMethods.each do |paymethod|
453
- puts ">> paymethod id: #{paymethod.id}"
454
- puts ">> card number: #{paymethod.cardType} ****#{paymethod.last4}"
455
- end
456
- end
457
- rescue Exception => e
458
- puts ">> error #{e.message}"
459
- end
460
-
461
-
462
-
463
- puts "", "Find Individual Customers"
464
-
465
- begin
466
- customer = Recharge::Customer.find(customerID)
467
-
468
- puts "id: #{customer.id}"
469
- puts "name: #{customer.firstName} #{customer.lastName}"
470
- puts "email: #{customer.email}"
471
-
472
- customer.payMethods.each do |paymethod|
473
- puts ">> paymethod id: #{paymethod.id}"
474
- puts ">> card number: #{paymethod.cardType} ****#{paymethod.last4}"
475
- end
476
- rescue Exception => e
477
- puts ">> error #{e.message}"
478
- end
479
-
480
-
481
-
482
- puts "", "Create New Customer"
483
-
484
- begin
485
- customer = Recharge::Customer.create(
486
- :firstName => "Eric",
487
- :lastName=> "Cardin",
488
- :email=> "email@rechargebilling.com",
489
- :bad=> "bad"
490
- )
491
- customerID = customer.id
492
- p customer
493
- rescue Exception => e
494
- puts ">> error #{e.message}"
495
- end
496
-
497
-
498
-
499
- puts "", "Update Customer"
500
-
501
- begin
502
- customer = Recharge::Customer.find(customerID)
503
- customer.update(
504
- :refID=> Time.now.to_i
505
- )
506
- p customer
507
- rescue Exception => e
508
- puts ">> error #{e.message}"
509
- end
510
-
511
-
512
-
513
- puts "", "Delete Customer"
514
-
515
- begin
516
- customer = Recharge::Customer.find(customerID)
517
- customer.destroy
518
- rescue Exception => e
519
- puts ">> error #{e.message}"
520
- end