cheddargetter_client_ruby 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cheddargetter_client_ruby.gemspec +8 -5
- data/lib/cheddar_getter/client.rb +60 -1
- data/lib/cheddar_getter/response.rb +30 -0
- data/test/helper.rb +8 -4
- data/test/test_cheddargetter_client_ruby.rb +253 -5
- data/test/working_tests.rb +81 -0
- metadata +22 -20
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cheddargetter_client_ruby}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Expected Behavior"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-16}
|
13
13
|
s.description = %q{A CheddarGetter API wrapper for Ruby}
|
14
14
|
s.email = %q{support@expectedbehavior.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,19 +33,22 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/cheddar_getter/response_exception.rb",
|
34
34
|
"lib/cheddargetter_client_ruby.rb",
|
35
35
|
"test/helper.rb",
|
36
|
-
"test/test_cheddargetter_client_ruby.rb"
|
36
|
+
"test/test_cheddargetter_client_ruby.rb",
|
37
|
+
"test/working_tests.rb"
|
37
38
|
]
|
38
39
|
s.homepage = %q{http://github.com/expectedbehavior/cheddargetter_client_ruby}
|
39
40
|
s.licenses = ["MIT"]
|
40
41
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
42
43
|
s.summary = %q{A CheddarGetter API wrapper for Ruby}
|
43
44
|
s.test_files = [
|
44
45
|
"test/helper.rb",
|
45
|
-
"test/test_cheddargetter_client_ruby.rb"
|
46
|
+
"test/test_cheddargetter_client_ruby.rb",
|
47
|
+
"test/working_tests.rb"
|
46
48
|
]
|
47
49
|
|
48
50
|
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
52
|
s.specification_version = 3
|
50
53
|
|
51
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -57,8 +57,31 @@ module CheddarGetter
|
|
57
57
|
# :search => Tcustomer name, company, email address and last four digits of credit card.
|
58
58
|
#}
|
59
59
|
def get_customers(data = nil)
|
60
|
+
warn 'Deprecation Warning: get_customers method is deprecated. Use get_customer_list instead'
|
60
61
|
do_request(:item => :customers, :action => :get, :data => data)
|
61
62
|
end
|
63
|
+
|
64
|
+
#https://cheddargetter.com/developers#all-customers
|
65
|
+
#
|
66
|
+
#Any, all, or none of this data hash can be given.
|
67
|
+
#It just filters the returned customers
|
68
|
+
#
|
69
|
+
#data:
|
70
|
+
#
|
71
|
+
#{
|
72
|
+
# :subscriptionStatus => "activeOnly" or "canceledOnly",
|
73
|
+
# :planCode => plan_code, #can take an array of plan codes
|
74
|
+
# :createdAfterDate => date,
|
75
|
+
# :createdBeforeDate => date,
|
76
|
+
# :canceledAfterDate => date,
|
77
|
+
# :canceledBeforeDate => date,
|
78
|
+
# :orderBy => "name" (default), "company", "plan", "billingDatetime" or "createdDatetime"
|
79
|
+
# :orderByDirection => "asc" (default) or "desc"
|
80
|
+
# :search => Tcustomer name, company, email address and last four digits of credit card.
|
81
|
+
#}
|
82
|
+
def get_customer_list(data = nil)
|
83
|
+
do_request(:item => :customers, :action => :list, :data => data)
|
84
|
+
end
|
62
85
|
|
63
86
|
#https://cheddargetter.com/developers#single-customer
|
64
87
|
#
|
@@ -322,7 +345,43 @@ module CheddarGetter
|
|
322
345
|
def add_charge(id_hash = { }, data = { })
|
323
346
|
do_request(:item => :customers, :action => "add-charge", :id_hash => id_hash, :data => data)
|
324
347
|
end
|
325
|
-
|
348
|
+
|
349
|
+
#https://cheddargetter.com/developers#delete-charge
|
350
|
+
#
|
351
|
+
#id_hash: {:code => customer_code} OR {:id => customer_id}
|
352
|
+
#
|
353
|
+
#data:
|
354
|
+
#
|
355
|
+
#{
|
356
|
+
# :chargeId => required,
|
357
|
+
#}
|
358
|
+
def delete_charge(id_hash = { }, data = { })
|
359
|
+
do_request(:item => :customers, :action => "delete-charge", :id_hash => id_hash, :data => data)
|
360
|
+
end
|
361
|
+
|
362
|
+
# https://cheddargetter.com/developers#one-time-invoice
|
363
|
+
#
|
364
|
+
# id_hash: {:code => customer_code} OR {:id => customer_id}
|
365
|
+
#
|
366
|
+
# data:
|
367
|
+
# :charges =>
|
368
|
+
# {"0" => {
|
369
|
+
# :chargeCode,
|
370
|
+
# :quantity,
|
371
|
+
# :eachAmount
|
372
|
+
# :description
|
373
|
+
# },
|
374
|
+
# {"1" => {
|
375
|
+
# :chargeCode,
|
376
|
+
# :quantity,
|
377
|
+
# :eachAmount
|
378
|
+
# :description
|
379
|
+
# }
|
380
|
+
# etc
|
381
|
+
def add_one_time_invoice(id_hash = {}, data = {})
|
382
|
+
do_request(:item => :invoices, :action => 'new', :id_hash => id_hash, :data => data)
|
383
|
+
end
|
384
|
+
|
326
385
|
#http://support.cheddargetter.com/faqs/marketing-metrics/marketing-metrics
|
327
386
|
#
|
328
387
|
#Convenience wrapper of setcookie() for setting a persistent cookie
|
@@ -109,6 +109,10 @@ module CheddarGetter
|
|
109
109
|
(customer_subscriptions(code) || []).first
|
110
110
|
end
|
111
111
|
|
112
|
+
def customer_paypal_preapproval_url(code = nil)
|
113
|
+
customer_subscription[:redirectUrl] || ""
|
114
|
+
end
|
115
|
+
|
112
116
|
#Returns all the subscriptions for the given customer.
|
113
117
|
#Only the first one is active, the rest is historical.
|
114
118
|
#
|
@@ -157,6 +161,9 @@ module CheddarGetter
|
|
157
161
|
customer_invoices(code).map{ |s| s[:transactions] || [] }.flatten
|
158
162
|
end
|
159
163
|
|
164
|
+
def customer_one_time_invoices(code = nil)
|
165
|
+
customer_invoices(code).select{ |s| s[:type] == 'one-time' }
|
166
|
+
end
|
160
167
|
#Returns the last transaction for the given customer.
|
161
168
|
#
|
162
169
|
#nil if there are no transactions.
|
@@ -233,6 +240,29 @@ module CheddarGetter
|
|
233
240
|
sub ? !!sub[:canceledDatetime] : nil
|
234
241
|
end
|
235
242
|
|
243
|
+
# Get an array representation of a single customer's current subscription
|
244
|
+
# @throws CheddarGetter_Response_Exception if the response type is incompatible or if a $code
|
245
|
+
# is not provided and the response contains more than one customer
|
246
|
+
# @return array
|
247
|
+
def customer_active?(code = nil)
|
248
|
+
subscription = customer_subscription(code)
|
249
|
+
if subscription[:canceledDatetime] && subscription[:canceledDatetime] <= Time.now
|
250
|
+
false
|
251
|
+
else
|
252
|
+
true
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# Is this customer's account pending paypal preapproval confirmation?
|
257
|
+
def customer_waiting_for_paypal?(code = nil)
|
258
|
+
subscription = customer_subscription(code)
|
259
|
+
if subscription[:canceledDatetime] && subscription[:canceledDatetime] <= Time.now && subscription[:cancelType] == 'paypal-wait'
|
260
|
+
true
|
261
|
+
else
|
262
|
+
false
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
236
266
|
#access the root keys of the response directly, such as
|
237
267
|
#:customers, :plans, or :errors
|
238
268
|
def [](value)
|
data/test/helper.rb
CHANGED
@@ -18,7 +18,11 @@ require 'cheddargetter_client_ruby'
|
|
18
18
|
class Test::Unit::TestCase
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
CGEmail = "michael@expectedbehavior.com"
|
22
|
+
CGProductCode = 'GEM_TEST'
|
23
|
+
CGPassword = 'DROlOAeQpWey6J2cqTyEzH'
|
24
|
+
CGFreePlanId = "fe96b9e6-53a2-102e-b098-40402145ee8b"
|
25
|
+
|
26
|
+
CG = CheddarGetter::Client.new(:product_code => CGProductCode,
|
27
|
+
:username => CGEmail,
|
28
|
+
:password => CGPassword)
|
@@ -53,6 +53,24 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
56
|
+
def paypal_new_user_hash(id, cc_error = nil)
|
57
|
+
{
|
58
|
+
:code => id,
|
59
|
+
:firstName => "First",
|
60
|
+
:lastName => "Last",
|
61
|
+
:email => "buyer_1304894377_per@gmail.com",
|
62
|
+
:firstContactDatetime => Time.now,
|
63
|
+
:subscription => {
|
64
|
+
:planCode => "TEST_PLAN_2",
|
65
|
+
:ccFirstName => "ccFirst",
|
66
|
+
:ccLastName => "ccLast",
|
67
|
+
:method => 'paypal',
|
68
|
+
:returnUrl => 'http://mywebapp.com/login?paypalAccepted',
|
69
|
+
:cancelUrl => 'http://mywebapp.com/login?paypalCanceled'
|
70
|
+
},
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
56
74
|
should "check various client init exceptions" do
|
57
75
|
assert_raises(CheddarGetter::ClientException) do
|
58
76
|
CheddarGetter::Client.new(:product_code => "code", :password => "password")
|
@@ -82,7 +100,7 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
82
100
|
cg.password = CG.password
|
83
101
|
result = cg.get_plans
|
84
102
|
assert_equal false, result.valid?
|
85
|
-
assert_equal ["User
|
103
|
+
assert_equal ["User #{CGEmail} does not have access to productCode=code"],
|
86
104
|
result.error_messages
|
87
105
|
|
88
106
|
cg.product_code = ""
|
@@ -131,14 +149,14 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
131
149
|
assert_raises(CheddarGetter::ResponseException){ result.customer }
|
132
150
|
assert_equal true, result.valid?
|
133
151
|
|
134
|
-
result = CG.get_plan(:id =>
|
152
|
+
result = CG.get_plan(:id => CGFreePlanId)
|
135
153
|
assert_equal 1, result.plans.size
|
136
154
|
assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
|
137
155
|
assert_equal true, result.valid?
|
138
156
|
|
139
157
|
result = CG.get_plan(:code => "NOT_A_PLAN")
|
140
158
|
assert_equal false, result.valid?
|
141
|
-
assert_equal ["Plan not found for code=NOT_A_PLAN within productCode
|
159
|
+
assert_equal ["Plan not found for code=NOT_A_PLAN within productCode=#{CGProductCode}"], result.error_messages
|
142
160
|
end
|
143
161
|
|
144
162
|
should "create a single free customer at cheddar getter" do
|
@@ -160,6 +178,23 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
160
178
|
assert_equal 20, result.customer_invoice[:charges].first[:eachAmount]
|
161
179
|
end
|
162
180
|
|
181
|
+
should 'create single paypal user' do
|
182
|
+
result = CG.delete_all_customers
|
183
|
+
assert_equal true, result.valid?
|
184
|
+
|
185
|
+
result = CG.new_customer(paypal_new_user_hash(1))
|
186
|
+
assert_equal true, result.valid?
|
187
|
+
assert_equal 1, result.customers.size
|
188
|
+
assert_equal "1", result.customer[:code]
|
189
|
+
assert_equal "Test Plan 2", result.customer_plan[:name]
|
190
|
+
assert_equal 20, result.customer_invoice[:charges].first[:eachAmount]
|
191
|
+
#paypal customer should be in cancelled in paypal-wait status
|
192
|
+
assert_equal true, result.customer_waiting_for_paypal?
|
193
|
+
#paypal customer subscription should include an approve paypal preapproval url
|
194
|
+
assert_equal true, result.customer_paypal_preapproval_url != nil
|
195
|
+
assert_equal true, result.customer_paypal_preapproval_url != ""
|
196
|
+
end
|
197
|
+
|
163
198
|
should "try to create a customer with various errors" do
|
164
199
|
result = CG.delete_all_customers
|
165
200
|
assert_equal true, result.valid?
|
@@ -332,6 +367,28 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
332
367
|
assert_raises(CheddarGetter::ResponseException){ result.customer_item_quantity_overage_cost }
|
333
368
|
end
|
334
369
|
|
370
|
+
should "get customer list from cheddargetter" do
|
371
|
+
result = CG.delete_all_customers
|
372
|
+
assert_equal true, result.valid?
|
373
|
+
|
374
|
+
result = CG.new_customer(paid_new_user_hash(1))
|
375
|
+
assert_equal true, result.valid?
|
376
|
+
|
377
|
+
result = CG.new_customer(paid_new_user_hash(2))
|
378
|
+
assert_equal true, result.valid?
|
379
|
+
|
380
|
+
result = CG.new_customer(free_new_user_hash(3))
|
381
|
+
assert_equal true, result.valid?
|
382
|
+
|
383
|
+
result = CG.get_customer_list
|
384
|
+
assert_equal true, result.valid?
|
385
|
+
assert_equal 3, result.customers.count
|
386
|
+
assert_equal "1", result.customer(1)[:code]
|
387
|
+
assert_equal "2", result.customer(2)[:code]
|
388
|
+
assert_equal "3", result.customer(3)[:code]
|
389
|
+
assert_equal nil, result.customer(4)
|
390
|
+
end
|
391
|
+
|
335
392
|
should "get a customer from cheddargetter" do
|
336
393
|
result = CG.delete_all_customers
|
337
394
|
assert_equal true, result.valid?
|
@@ -426,18 +483,44 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
426
483
|
customer = CG.new_customer(paid_new_user_hash(1))
|
427
484
|
assert_equal true, customer.valid?
|
428
485
|
assert_equal false, customer.customer_canceled?
|
486
|
+
assert_equal true, customer.customer_active?
|
429
487
|
|
430
488
|
result = CG.cancel_subscription(:code => customer.customer[:code])
|
431
489
|
assert_equal true, result.valid?
|
432
490
|
assert_equal true, result.customer_canceled?
|
491
|
+
assert_equal false, result.customer_active?
|
433
492
|
|
434
493
|
customer = CG.new_customer(paid_new_user_hash(2))
|
435
494
|
assert_equal true, customer.valid?
|
436
495
|
assert_equal false, customer.customer_canceled?
|
496
|
+
assert_equal true, customer.customer_active?
|
437
497
|
|
438
498
|
result = CG.cancel_subscription(:id => customer.customer[:id])
|
439
499
|
assert_equal true, result.valid?
|
440
500
|
assert_equal true, result.customer_canceled?
|
501
|
+
assert_equal false, result.customer_active?
|
502
|
+
end
|
503
|
+
|
504
|
+
should 'check waiting on paypal status' do
|
505
|
+
result = CG.delete_all_customers
|
506
|
+
assert_equal true, result.valid?
|
507
|
+
|
508
|
+
|
509
|
+
customer = CG.new_customer(paid_new_user_hash(1))
|
510
|
+
assert_equal true, customer.valid?
|
511
|
+
assert_equal false, customer.customer_canceled?
|
512
|
+
assert_equal true, customer.customer_active?
|
513
|
+
assert_equal false, customer.customer_waiting_for_paypal?
|
514
|
+
|
515
|
+
result = CG.cancel_subscription(:code => customer.customer[:code])
|
516
|
+
assert_equal true, result.valid?
|
517
|
+
assert_equal true, result.customer_canceled?
|
518
|
+
assert_equal false, result.customer_active?
|
519
|
+
assert_equal false, result.customer_waiting_for_paypal?
|
520
|
+
|
521
|
+
#formatting response to simulate paypal wait status
|
522
|
+
result[:customers]["1"][:subscriptions][0][:cancelType] = "paypal-wait"
|
523
|
+
assert_equal true, result.customer_waiting_for_paypal?
|
441
524
|
end
|
442
525
|
|
443
526
|
should "edit customer and subscription" do
|
@@ -460,10 +543,17 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
460
543
|
|
461
544
|
result = CG.edit_customer(:code => customer[:code])
|
462
545
|
assert_equal true, result.valid?
|
546
|
+
|
547
|
+
customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
548
|
+
customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
549
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
550
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
463
551
|
assert_equal customer, result.customer
|
464
552
|
|
465
553
|
result = CG.edit_customer(:id => customer[:id])
|
466
554
|
assert_equal true, result.valid?
|
555
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
556
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
467
557
|
assert_equal customer, result.customer
|
468
558
|
|
469
559
|
result = CG.edit_customer({:code => customer[:code]}, {:firstName => "New",
|
@@ -477,6 +567,8 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
477
567
|
result.customer[:subscriptions][0][:ccZip] = customer[:subscriptions][0][:ccZip]
|
478
568
|
result.customer[:subscriptions][0][:invoices][0][:vatRate] = nil #not sure why this changes from nil to 0
|
479
569
|
result.customer[:modifiedDatetime] = customer[:modifiedDatetime]
|
570
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
571
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
480
572
|
assert_equal customer, result.customer
|
481
573
|
|
482
574
|
result = CG.edit_customer({:code => customer[:code]},
|
@@ -507,11 +599,17 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
507
599
|
assert_equal true, result.valid?
|
508
600
|
|
509
601
|
result = CG.edit_customer_only(:code => customer[:code])
|
602
|
+
customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
603
|
+
customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
604
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
605
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
510
606
|
assert_equal true, result.valid?
|
511
607
|
assert_equal customer, result.customer
|
512
608
|
|
513
609
|
result = CG.edit_customer_only(:id => customer[:id])
|
514
610
|
assert_equal true, result.valid?
|
611
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
612
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
515
613
|
assert_equal customer, result.customer
|
516
614
|
|
517
615
|
result = CG.edit_customer({:code => customer[:code]}, {
|
@@ -526,6 +624,8 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
526
624
|
result.customer[:company] = customer[:company]
|
527
625
|
result.customer[:modifiedDatetime] = customer[:modifiedDatetime]
|
528
626
|
result.customer[:subscriptions][0][:invoices][0][:vatRate] = nil #not sure why this changes from nil to 0
|
627
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
628
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
529
629
|
assert_equal customer, result.customer
|
530
630
|
end
|
531
631
|
|
@@ -545,14 +645,20 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
545
645
|
|
546
646
|
result = CG.new_customer(free_new_user_hash(1))
|
547
647
|
customer = result.customer
|
648
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
649
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
548
650
|
assert_equal true, result.valid?
|
549
651
|
|
550
652
|
result = CG.edit_subscription(:code => customer[:code])
|
551
653
|
assert_equal true, result.valid?
|
654
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
655
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
552
656
|
assert_equal customer, result.customer
|
553
657
|
|
554
658
|
result = CG.edit_subscription(:id => customer[:id])
|
555
659
|
assert_equal true, result.valid?
|
660
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
661
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
556
662
|
assert_equal customer, result.customer
|
557
663
|
|
558
664
|
result = CG.edit_subscription({:code => customer[:code]}, { :ccZip => "46268" })
|
@@ -563,6 +669,8 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
563
669
|
result.customer[:subscriptions][0][:ccZip] = customer[:subscriptions][0][:ccZip]
|
564
670
|
result.customer[:subscriptions][0][:invoices][0][:vatRate] = nil #not sure why this changes from nil to 0
|
565
671
|
result.customer[:modifiedDatetime] = customer[:modifiedDatetime]
|
672
|
+
result.customer[:subscriptions].first[:plan].delete(:initialInvoiceBillingDatetime)
|
673
|
+
result.customer[:subscriptions].first[:plan].delete(:nextInvoiceBillingDatetime)
|
566
674
|
assert_equal customer, result.customer
|
567
675
|
|
568
676
|
result = CG.edit_subscription({:code => customer[:code]}, paid_new_user_hash(1)[:subscription] )
|
@@ -731,10 +839,25 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
731
839
|
charge = result.customer_invoice[:charges].detect{ |c| c[:code] == "MY_CREDIT" }
|
732
840
|
assert_equal 1, charge[:quantity]
|
733
841
|
assert_equal -2, charge[:eachAmount]
|
734
|
-
assert_equal "Whoops", charge[:description]
|
735
|
-
|
842
|
+
assert_equal "Whoops", charge[:description]
|
736
843
|
end
|
737
844
|
|
845
|
+
should 'delete charge' do
|
846
|
+
result = CG.delete_all_customers
|
847
|
+
assert_equal true, result.valid?
|
848
|
+
|
849
|
+
result = CG.new_customer(paid_new_user_hash(1))
|
850
|
+
assert_equal true, result.valid?
|
851
|
+
|
852
|
+
result = CG.add_charge({:code => 1}, { :chargeCode => "MY_CHARGE", :quantity => 1, :eachAmount => 2 })
|
853
|
+
assert_equal true, result.valid?
|
854
|
+
charge = result.customer_invoice[:charges].detect{ |c| c[:code] == "MY_CHARGE" }
|
855
|
+
|
856
|
+
result = CG.delete_charge({:code => 1}, { :chargeId => charge[:id] })
|
857
|
+
charge = result.customer_invoice[:charges].detect{ |c| c[:code] == "MY_CHARGE" }
|
858
|
+
assert_equal nil, charge
|
859
|
+
end
|
860
|
+
|
738
861
|
should "resubscribe after canceling" do
|
739
862
|
result = CG.delete_all_customers
|
740
863
|
assert_equal true, result.valid?
|
@@ -833,6 +956,86 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
833
956
|
assert_equal ["No customers found."], result.error_messages
|
834
957
|
end
|
835
958
|
|
959
|
+
should "test customer list get filtering" do
|
960
|
+
result = CG.delete_all_customers
|
961
|
+
assert_equal true, result.valid?
|
962
|
+
|
963
|
+
result = CG.new_customer(free_new_user_hash(1))
|
964
|
+
assert_equal true, result.valid?
|
965
|
+
|
966
|
+
result = CG.new_customer(free_new_user_hash(2))
|
967
|
+
assert_equal true, result.valid?
|
968
|
+
result = CG.cancel_subscription(:code => 2)
|
969
|
+
assert_equal true, result.valid?
|
970
|
+
assert_equal true, result.customer_canceled?
|
971
|
+
|
972
|
+
|
973
|
+
result = CG.new_customer(paid_new_user_hash(3))
|
974
|
+
assert_equal true, result.valid?
|
975
|
+
|
976
|
+
result = CG.new_customer(paid_new_user_hash(4))
|
977
|
+
assert_equal true, result.valid?
|
978
|
+
result = CG.cancel_subscription(:code => 4)
|
979
|
+
assert_equal true, result.valid?
|
980
|
+
assert_equal true, result.customer_canceled?
|
981
|
+
|
982
|
+
result = CG.get_customer_list
|
983
|
+
assert_equal true, result.valid?
|
984
|
+
assert_equal 4, result.customers.count
|
985
|
+
assert_equal "1", result.customer(1)[:code]
|
986
|
+
assert_equal "2", result.customer(2)[:code]
|
987
|
+
assert_equal "3", result.customer(3)[:code]
|
988
|
+
assert_equal "4", result.customer(4)[:code]
|
989
|
+
|
990
|
+
result = CG.get_customer_list(:subscriptionStatus => "activeOnly")
|
991
|
+
assert_equal true, result.valid?
|
992
|
+
assert_equal 2, result.customers.count
|
993
|
+
assert_equal "1", result.customer(1)[:code]
|
994
|
+
assert_equal nil, result.customer(2)
|
995
|
+
assert_equal "3", result.customer(3)[:code]
|
996
|
+
assert_equal nil, result.customer(4)
|
997
|
+
|
998
|
+
result = CG.get_customer_list(:subscriptionStatus => "canceledOnly")
|
999
|
+
assert_equal true, result.valid?
|
1000
|
+
assert_equal 2, result.customers.count
|
1001
|
+
assert_equal nil, result.customer(1)
|
1002
|
+
assert_equal "2", result.customer(2)[:code]
|
1003
|
+
assert_equal nil, result.customer(3)
|
1004
|
+
assert_equal "4", result.customer(4)[:code]
|
1005
|
+
|
1006
|
+
result = CG.get_customer_list(:planCode => "TEST_PLAN_1")
|
1007
|
+
assert_equal false, result.valid?
|
1008
|
+
assert_equal ["No customers found."], result.error_messages
|
1009
|
+
|
1010
|
+
result = CG.get_customer_list(:planCode => ["TEST_PLAN_1", "TEST_PLAN_2", "FREE_PLAN_TEST"])
|
1011
|
+
assert_equal true, result.valid?
|
1012
|
+
assert_equal 4, result.customers.count
|
1013
|
+
|
1014
|
+
result = CG.get_customer_list(:planCode => "FREE_PLAN_TEST")
|
1015
|
+
assert_equal true, result.valid?
|
1016
|
+
assert_equal 2, result.customers.count
|
1017
|
+
|
1018
|
+
result = CG.get_customer_list(:planCode => "FREE_PLAN_TEST", :subscriptionStatus => "canceledOnly")
|
1019
|
+
assert_equal true, result.valid?
|
1020
|
+
assert_equal 1, result.customers.count
|
1021
|
+
|
1022
|
+
result = CG.get_customer_list(:canceledAfterDate => Date.today)
|
1023
|
+
assert_equal true, result.valid?
|
1024
|
+
assert_equal 2, result.customers.count
|
1025
|
+
|
1026
|
+
result = CG.get_customer_list(:createdAfterDate => Date.today)
|
1027
|
+
assert_equal true, result.valid?
|
1028
|
+
assert_equal 4, result.customers.count
|
1029
|
+
|
1030
|
+
result = CG.get_customer_list(:search => "First")
|
1031
|
+
assert_equal true, result.valid?
|
1032
|
+
assert_equal 4, result.customers.count
|
1033
|
+
|
1034
|
+
result = CG.get_customer_list(:search => "NotFirst")
|
1035
|
+
assert_equal false, result.valid?
|
1036
|
+
assert_equal ["No customers found."], result.error_messages
|
1037
|
+
end
|
1038
|
+
|
836
1039
|
should "get 100% code coverage :)" do
|
837
1040
|
result = CG.delete_all_customers
|
838
1041
|
assert_equal true, result.valid?
|
@@ -979,4 +1182,49 @@ class TestCheddargetterClientRuby < Test::Unit::TestCase
|
|
979
1182
|
assert_equal 'correct', result.customer[:campaignTerm]
|
980
1183
|
end
|
981
1184
|
|
1185
|
+
should "create one-time-invoices" do
|
1186
|
+
result = CG.delete_all_customers
|
1187
|
+
assert_equal true, result.valid?
|
1188
|
+
|
1189
|
+
assert_raises(CheddarGetter::ClientException){ CG.add_charge }
|
1190
|
+
|
1191
|
+
result = CG.add_one_time_invoice(:code => 1)
|
1192
|
+
assert_equal false, result.valid?
|
1193
|
+
assert_equal ["Customer not found"], result.error_messages
|
1194
|
+
|
1195
|
+
result = CG.add_one_time_invoice(:id => "not_a_valid_id")
|
1196
|
+
assert_equal false, result.valid?
|
1197
|
+
assert_equal ["Customer not found"], result.error_messages
|
1198
|
+
|
1199
|
+
result = CG.new_customer(paid_new_user_hash(1))
|
1200
|
+
assert_equal true, result.valid?
|
1201
|
+
|
1202
|
+
result = CG.add_one_time_invoice(:code => 1)
|
1203
|
+
assert_equal false, result.valid?
|
1204
|
+
assert_equal ["A value is required: charges[0][chargeCode]"], result.error_messages
|
1205
|
+
|
1206
|
+
result = CG.add_one_time_invoice({:code => 1}, :charges => {"0" => { :chargeCode => "MY_CHARGE" }})
|
1207
|
+
assert_equal false, result.valid?
|
1208
|
+
assert_equal ["A value is required: charges[0][quantity]"], result.error_messages
|
1209
|
+
|
1210
|
+
result = CG.add_one_time_invoice({:code => 1}, :charges => {"0" => { :chargeCode => "MY_CHARGE", :quantity => 1 }})
|
1211
|
+
assert_equal false, result.valid?
|
1212
|
+
assert_equal ["A value is required: charges[0][eachAmount]"], result.error_messages
|
1213
|
+
|
1214
|
+
result = CG.add_one_time_invoice({:code => 1}, :charges => {"0" => { :chargeCode => "MY_CHARGE", :quantity => 1, :eachAmount => 2 }})
|
1215
|
+
assert_equal true, result.valid?
|
1216
|
+
charge = result.customer_one_time_invoices.first[:charges].detect{ |c| c[:code] == "MY_CHARGE" }
|
1217
|
+
assert_equal 1, charge[:quantity]
|
1218
|
+
assert_equal 2, charge[:eachAmount]
|
1219
|
+
assert_equal nil, charge[:description]
|
1220
|
+
|
1221
|
+
result = CG.add_one_time_invoice({:code => 1}, :charges => { "0" =>
|
1222
|
+
{ :chargeCode => "MY_CREDIT", :quantity => 1,
|
1223
|
+
:eachAmount => -2, :description => "Whoops" }})
|
1224
|
+
assert_equal true, result.valid?
|
1225
|
+
charge = result.customer_one_time_invoices.first[:charges].detect{ |c| c[:code] == "MY_CREDIT" }
|
1226
|
+
assert_equal 1, charge[:quantity]
|
1227
|
+
assert_equal -2, charge[:eachAmount]
|
1228
|
+
assert_equal "Whoops", charge[:description]
|
1229
|
+
end
|
982
1230
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# This file used to copy whatever test you are working on into
|
2
|
+
# to run individually. This is to make up for test unit's lack
|
3
|
+
# of ability to run individual tests!
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
6
|
+
|
7
|
+
class TestCheddargetterClientRuby < Test::Unit::TestCase
|
8
|
+
ERROR_CODES = {
|
9
|
+
1000 => "An unexpected error occured. Please try again later.",
|
10
|
+
1001 => "The record already exists",
|
11
|
+
1002 => "An unexpected error occured. Please try again later.",
|
12
|
+
1003 => "An unexpected error occured. Please try again later.",
|
13
|
+
2000 => "The local gateway configuration is incompatible",
|
14
|
+
2001 => "The configuration at the gateway is incompatible",
|
15
|
+
2002 => "Authentication to the gateway failed",
|
16
|
+
2003 => "The gateway has denied access",
|
17
|
+
3000 => "The response from the gateway was not recognized",
|
18
|
+
4000 => "The connection to the gateway failed. Please try again later.",
|
19
|
+
5000 => "There was an error processing the transaction",
|
20
|
+
5001 => "Credit card number is invalid",
|
21
|
+
5002 => "Expiration date is invalid",
|
22
|
+
5003 => "Credit card type is not accepted",
|
23
|
+
6000 => "The transaction was declined",
|
24
|
+
6001 => "The transaction was declined due to AVS mismatch",
|
25
|
+
6002 => "The transaction was declined due to card code verification failure",
|
26
|
+
7000 => "The transaction failed for an unknown reason"
|
27
|
+
}
|
28
|
+
|
29
|
+
def free_new_user_hash(id)
|
30
|
+
{
|
31
|
+
:code => id,
|
32
|
+
:firstName => "First",
|
33
|
+
:lastName => "Last",
|
34
|
+
:email => "email@example.com",
|
35
|
+
:subscription => {
|
36
|
+
:planCode => "FREE_PLAN_TEST",
|
37
|
+
},
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def paid_new_user_hash(id, cc_error = nil)
|
42
|
+
{
|
43
|
+
:code => id,
|
44
|
+
:firstName => "First",
|
45
|
+
:lastName => "Last",
|
46
|
+
:email => "email@example.com",
|
47
|
+
:firstContactDatetime => Time.now,
|
48
|
+
:subscription => {
|
49
|
+
:planCode => "TEST_PLAN_2",
|
50
|
+
:ccNumber => "4111111111111111",
|
51
|
+
:ccExpiration => Date.parse("08/2012"),
|
52
|
+
:ccCardCode => "123",
|
53
|
+
:ccFirstName => "ccFirst",
|
54
|
+
:ccLastName => "ccLast",
|
55
|
+
:ccZip => cc_error ? cc_error : "11361"
|
56
|
+
},
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def paypal_new_user_hash(id, cc_error = nil)
|
61
|
+
{
|
62
|
+
:code => id,
|
63
|
+
:firstName => "First",
|
64
|
+
:lastName => "Last",
|
65
|
+
:email => "buyer_1304894377_per@gmail.com",
|
66
|
+
:firstContactDatetime => Time.now,
|
67
|
+
:subscription => {
|
68
|
+
:planCode => "TEST_PLAN_2",
|
69
|
+
:ccFirstName => "ccFirst",
|
70
|
+
:ccLastName => "ccLast",
|
71
|
+
:method => 'paypal',
|
72
|
+
:returnUrl => 'http://mywebapp.com/login?paypalAccepted',
|
73
|
+
:cancelUrl => 'http://mywebapp.com/login?paypalCanceled'
|
74
|
+
},
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
should '' do
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheddargetter_client_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Expected Behavior
|
@@ -15,12 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-16 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
+
name: httparty
|
24
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
26
|
none: false
|
26
27
|
requirements:
|
@@ -32,11 +33,11 @@ dependencies:
|
|
32
33
|
- 4
|
33
34
|
- 3
|
34
35
|
version: 0.4.3
|
35
|
-
type: :runtime
|
36
36
|
requirement: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
|
+
name: shoulda
|
40
41
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
@@ -46,11 +47,11 @@ dependencies:
|
|
46
47
|
segments:
|
47
48
|
- 0
|
48
49
|
version: "0"
|
49
|
-
type: :development
|
50
50
|
requirement: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
52
|
+
type: :development
|
53
53
|
prerelease: false
|
54
|
+
name: bundler
|
54
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
56
57
|
requirements:
|
@@ -62,11 +63,11 @@ dependencies:
|
|
62
63
|
- 0
|
63
64
|
- 0
|
64
65
|
version: 1.0.0
|
65
|
-
type: :development
|
66
66
|
requirement: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
|
68
|
+
type: :development
|
69
69
|
prerelease: false
|
70
|
+
name: jeweler
|
70
71
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
72
|
none: false
|
72
73
|
requirements:
|
@@ -78,11 +79,11 @@ dependencies:
|
|
78
79
|
- 5
|
79
80
|
- 1
|
80
81
|
version: 1.5.1
|
81
|
-
type: :development
|
82
82
|
requirement: *id004
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
|
84
|
+
type: :development
|
85
85
|
prerelease: false
|
86
|
+
name: rcov
|
86
87
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
88
|
none: false
|
88
89
|
requirements:
|
@@ -92,11 +93,11 @@ dependencies:
|
|
92
93
|
segments:
|
93
94
|
- 0
|
94
95
|
version: "0"
|
95
|
-
type: :development
|
96
96
|
requirement: *id005
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
|
98
|
+
type: :development
|
99
99
|
prerelease: false
|
100
|
+
name: ruby-debug
|
100
101
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
101
102
|
none: false
|
102
103
|
requirements:
|
@@ -106,11 +107,11 @@ dependencies:
|
|
106
107
|
segments:
|
107
108
|
- 0
|
108
109
|
version: "0"
|
109
|
-
type: :development
|
110
110
|
requirement: *id006
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
|
112
|
+
type: :runtime
|
113
113
|
prerelease: false
|
114
|
+
name: httparty
|
114
115
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
115
116
|
none: false
|
116
117
|
requirements:
|
@@ -122,7 +123,6 @@ dependencies:
|
|
122
123
|
- 4
|
123
124
|
- 3
|
124
125
|
version: 0.4.3
|
125
|
-
type: :runtime
|
126
126
|
requirement: *id007
|
127
127
|
description: A CheddarGetter API wrapper for Ruby
|
128
128
|
email: support@expectedbehavior.com
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/cheddargetter_client_ruby.rb
|
152
152
|
- test/helper.rb
|
153
153
|
- test/test_cheddargetter_client_ruby.rb
|
154
|
+
- test/working_tests.rb
|
154
155
|
has_rdoc: true
|
155
156
|
homepage: http://github.com/expectedbehavior/cheddargetter_client_ruby
|
156
157
|
licenses:
|
@@ -181,10 +182,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
requirements: []
|
182
183
|
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 1.
|
185
|
+
rubygems_version: 1.3.7
|
185
186
|
signing_key:
|
186
187
|
specification_version: 3
|
187
188
|
summary: A CheddarGetter API wrapper for Ruby
|
188
189
|
test_files:
|
189
190
|
- test/helper.rb
|
190
191
|
- test/test_cheddargetter_client_ruby.rb
|
192
|
+
- test/working_tests.rb
|