paypal-sdk-rest 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/paypal-sdk/rest.rb +1 -0
- data/lib/paypal-sdk/rest/api.rb +0 -1
- data/lib/paypal-sdk/rest/data_types.rb +722 -793
- data/lib/paypal-sdk/rest/extended_data_types.rb +1 -3
- data/lib/paypal-sdk/rest/request_data_type.rb +0 -3
- data/lib/paypal-sdk/rest/version.rb +1 -1
- data/spec/log/http.log +32 -1161
- data/spec/subscription_examples_spec.rb +227 -0
- metadata +4 -2
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Subscription" do
|
4
|
+
|
5
|
+
PlanAttributes = {
|
6
|
+
"name" => "T-Shirt of the Month Club Plan",
|
7
|
+
"description" => "Template creation.",
|
8
|
+
"type" => "fixed",
|
9
|
+
"payment_definitions" => [
|
10
|
+
{
|
11
|
+
"name" => "Regular Payments",
|
12
|
+
"type" => "REGULAR",
|
13
|
+
"frequency" => "MONTH",
|
14
|
+
"frequency_interval" => "2",
|
15
|
+
"amount" => {
|
16
|
+
"value" => "100",
|
17
|
+
"currency" => "USD"
|
18
|
+
},
|
19
|
+
"cycles" => "12",
|
20
|
+
"charge_models" => [
|
21
|
+
{
|
22
|
+
"type" => "SHIPPING",
|
23
|
+
"amount" => {
|
24
|
+
"value" => "10",
|
25
|
+
"currency" => "USD"
|
26
|
+
}
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"type" => "TAX",
|
30
|
+
"amount" => {
|
31
|
+
"value" => "12",
|
32
|
+
"currency" => "USD"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"merchant_preferences" => {
|
39
|
+
"setup_fee" => {
|
40
|
+
"value" => "1",
|
41
|
+
"currency" => "USD"
|
42
|
+
},
|
43
|
+
"return_url" => "http://www.return.com",
|
44
|
+
"cancel_url" => "http://www.cancel.com",
|
45
|
+
"auto_bill_amount" => "YES",
|
46
|
+
"initial_fail_amount_action" => "CONTINUE",
|
47
|
+
"max_fail_attempts" => "0"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
AgreementAttributes = {
|
52
|
+
"name" => "T-Shirt of the Month Club Agreement",
|
53
|
+
"description" => "Agreement for T-Shirt of the Month Club Plan",
|
54
|
+
"start_date" => "2015-02-19T00:37:04Z",
|
55
|
+
"payer" => {
|
56
|
+
"payment_method" => "paypal"
|
57
|
+
},
|
58
|
+
"shipping_address" => {
|
59
|
+
"line1" => "111 First Street",
|
60
|
+
"city" => "Saratoga",
|
61
|
+
"state" => "CA",
|
62
|
+
"postal_code" => "95070",
|
63
|
+
"country_code" => "US"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
describe "BillingPlan", :integration => true do
|
68
|
+
it "Create" do
|
69
|
+
# create access token and then create a plan
|
70
|
+
$api = API.new
|
71
|
+
plan = Plan.new(PlanAttributes.merge( :token => $api.token ))
|
72
|
+
Plan.api.should_not eql plan.api
|
73
|
+
plan.create
|
74
|
+
|
75
|
+
# make sure the transaction was successful
|
76
|
+
$plan_id = plan.id
|
77
|
+
plan.error.should be_nil
|
78
|
+
plan.id.should_not be_nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "Update" do
|
82
|
+
# create a new plan to update
|
83
|
+
plan = Plan.new(PlanAttributes)
|
84
|
+
expect(plan.create).to be_truthy
|
85
|
+
|
86
|
+
# set up a patch request
|
87
|
+
patch = Patch.new
|
88
|
+
patch.op = "replace"
|
89
|
+
patch.path = "/";
|
90
|
+
patch.value = { :state => "ACTIVE" }
|
91
|
+
|
92
|
+
# the patch request should be successful
|
93
|
+
expect(plan.update( patch )).to be_truthy
|
94
|
+
end
|
95
|
+
|
96
|
+
it "List" do
|
97
|
+
# list all billing plans
|
98
|
+
plan_list = Plan.all
|
99
|
+
plan_list.error.should be_nil
|
100
|
+
plan_list.plans.count.should > 1
|
101
|
+
end
|
102
|
+
|
103
|
+
it "Delete" do
|
104
|
+
# create a plan to delete
|
105
|
+
plan = Plan.new(PlanAttributes.merge( :token => $api.token ))
|
106
|
+
plan.create
|
107
|
+
plan_id = plan.id
|
108
|
+
|
109
|
+
# construct a patch object that will be used for deletion
|
110
|
+
patch = Patch.new
|
111
|
+
patch.op = "replace"
|
112
|
+
patch.path = "/"
|
113
|
+
patch.value = { "state" => "DELETED" }
|
114
|
+
|
115
|
+
# send delete request
|
116
|
+
plan.update(patch)
|
117
|
+
|
118
|
+
# make sure the plan has been deleted
|
119
|
+
plan = Plan.find(plan_id)
|
120
|
+
plan.id.should_not eq plan_id
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "BillingAgreement", :integration => true do
|
125
|
+
|
126
|
+
it "Create" do
|
127
|
+
# first, create an active plan to be added to agreement
|
128
|
+
api = API.new
|
129
|
+
plan = Plan.new(PlanAttributes)
|
130
|
+
expect(plan.create).to be_truthy
|
131
|
+
|
132
|
+
# first, create an agreement
|
133
|
+
$agreement = Agreement.new(AgreementAttributes)
|
134
|
+
$agreement.plan = Plan.new( :id => "P-1K47639161110773GYDKTWIA" )
|
135
|
+
$agreement.shipping_address = nil
|
136
|
+
|
137
|
+
# verify newly created agreement
|
138
|
+
expect($agreement.create).to be_truthy
|
139
|
+
expect($agreement.id).to be_nil
|
140
|
+
expect($agreement.token).not_to be_nil
|
141
|
+
expect($agreement.name).to eq("T-Shirt of the Month Club Agreement")
|
142
|
+
end
|
143
|
+
|
144
|
+
#####################################
|
145
|
+
# The following tests are disabled due to them requiring an active billing agreement or buyer's approval.
|
146
|
+
# Most of them require an agreement ID, which is returned after executing agreement.
|
147
|
+
# And agreement execution requires buyer's approval.
|
148
|
+
#####################################
|
149
|
+
|
150
|
+
xit "Execute" do
|
151
|
+
# Use this call to execute an agreement after the buyer approves it.
|
152
|
+
expect($agreement.execute).to be_truthy
|
153
|
+
end
|
154
|
+
|
155
|
+
xit "Get" do
|
156
|
+
# this call needs an agreement ID of the agreement to be retrieved
|
157
|
+
agreement = Agreement.find($agreement.id)
|
158
|
+
expect(agreement.id).to eq($agreement.id)
|
159
|
+
expect(agreement.description).to eq("Agreement for T-Shirt of the Month Club Plan")
|
160
|
+
expect(agreement.start_date).to eq("2015-02-19T00:37:04Z")
|
161
|
+
expect(agreement.plan).not_to be_nil
|
162
|
+
end
|
163
|
+
|
164
|
+
xit "Update" do
|
165
|
+
# get the agreement to update
|
166
|
+
api = API.new
|
167
|
+
plan = Plan.new(PlanAttributes)
|
168
|
+
expect(plan.create).to be_truthy
|
169
|
+
|
170
|
+
# first, create an agreement
|
171
|
+
agreement = Agreement.new(AgreementAttributes)
|
172
|
+
agreement.plan = Plan.new( :id => "P-1K47639161110773GYDKTWIA" )
|
173
|
+
expect(agreement.create).to be_truthy
|
174
|
+
|
175
|
+
|
176
|
+
# create an update for the agreement
|
177
|
+
random_string = (0...8).map { (65 + rand(26)).chr }.join
|
178
|
+
patch = Patch.new
|
179
|
+
patch.op = "replace"
|
180
|
+
patch.path = "/"
|
181
|
+
patch.value = { "description" => random_string }
|
182
|
+
|
183
|
+
# send update request
|
184
|
+
response = agreement.update(patch)
|
185
|
+
|
186
|
+
# verify the agreement update was successful
|
187
|
+
expect(response).to be_truthy
|
188
|
+
updated_agreement = Agreement.get($agreement.id)
|
189
|
+
expect(updated_agreement.id).to eq($agreement.id)
|
190
|
+
expect(random_string).to eq(updated_agreement.description)
|
191
|
+
end
|
192
|
+
|
193
|
+
xit "Suspend" do
|
194
|
+
# set the id of an active agreement here
|
195
|
+
agreement_id = ""
|
196
|
+
agreement = Agreement.find(agreement_id)
|
197
|
+
|
198
|
+
state_descriptor = AgreementStateDescriptor.new( :note => "Suspending the agreement" )
|
199
|
+
expect( agreement.suspend(state_descriptor) ).to be_truthy
|
200
|
+
end
|
201
|
+
|
202
|
+
xit "Reactivate" do
|
203
|
+
# set the id of a suspended agreement here
|
204
|
+
agreement_id = ""
|
205
|
+
agreement = Agreement.find(agreement_id)
|
206
|
+
|
207
|
+
state_descriptor = AgreementStateDescriptor.new( :note => "Re-activating the agreement" )
|
208
|
+
expect( agreement.re_activate(state_descriptor) ).to be_truthy
|
209
|
+
end
|
210
|
+
|
211
|
+
xit "Search" do
|
212
|
+
transactions = Agreement.transactions($agreement.id, "2015-01-01", "2015-01-10")
|
213
|
+
expect(transactions).not_to be_nil
|
214
|
+
expect(transactions.agreement_transaction_list).not_to be_empty
|
215
|
+
end
|
216
|
+
|
217
|
+
xit "Cancel" do
|
218
|
+
# set the id of an agreement here
|
219
|
+
agreement_id = ""
|
220
|
+
agreement = Agreement.find(agreement_id)
|
221
|
+
|
222
|
+
state_descriptor = AgreementStateDescriptor.new( :note => "Cancelling the agreement" )
|
223
|
+
expect( agreement.cancel(state_descriptor) ).to be_truthy
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal-sdk-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PayPal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paypal-sdk-core
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- spec/log/http.log
|
68
68
|
- spec/payments_examples_spec.rb
|
69
69
|
- spec/spec_helper.rb
|
70
|
+
- spec/subscription_examples_spec.rb
|
70
71
|
- spec/web_profile_examples_spec.rb
|
71
72
|
homepage: https://developer.paypal.com
|
72
73
|
licenses:
|
@@ -101,4 +102,5 @@ test_files:
|
|
101
102
|
- spec/log/http.log
|
102
103
|
- spec/payments_examples_spec.rb
|
103
104
|
- spec/spec_helper.rb
|
105
|
+
- spec/subscription_examples_spec.rb
|
104
106
|
- spec/web_profile_examples_spec.rb
|