-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathsample_code_spec.rb
More file actions
320 lines (223 loc) · 9.16 KB
/
sample_code_spec.rb
File metadata and controls
320 lines (223 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
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
cwd = Dir.pwd
if cwd.include? "sample-code-ruby"
puts "String includes sample-code-ruby"
specpath = "./spec/"
dirpath = "./"
else
specpath = "./sample-code-ruby/spec/"
dirpath = "./sample-code-ruby/"
end
require specpath + "spec_helper"
include AuthorizeNet::API
describe "SampleCode Testing" do
before :all do
begin
Dir.glob(dirpath + "**/*.rb") do |item| # note one extra "*"
next if item == '.' or item == '..'
item = item[0..-4]
if item != specpath + 'sample_code_spec'
puts "working on: #{item}"
require item
end
end
# Dir.glob("./sample-code-ruby/RecurringBilling/*") do |item| # note one extra "*"
# next if item == '.' or item == '..'
# item = item[0..-4]
# puts "working on: #{item}"
# require item
# end
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
@api_key = creds['api_transaction_key']
@api_login = creds['api_login_id']
@gateway = :sandbox
rescue Errno::ENOENT => e
@api_key = "TEST"
@api_login = "TEST"
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
end
end
def validate_response(response= nil)
expect(response).not_to eq(nil)
expect(response.messages).not_to eq(nil)
expect(response.messages.resultCode).not_to eq(nil)
expect(response.messages.resultCode).to eq(MessageTypeEnum::Ok)
end
it "should be able to run all Customer Profile sample code" do
puts "START - Customer Profiles"
response = create_customer_profile()
validate_response(response)
customerProfileId = response.customerProfileId
response = create_customer_payment_profile(customerProfileId)
validate_response(response)
customerPaymentProfileId = response.customerPaymentProfileId
response = create_customer_shipping_address(customerProfileId)
validate_response(response)
customerAddressId = response.customerAddressId
response = validate_customer_payment_profile(customerProfileId, customerPaymentProfileId)
validate_response(response)
create_transaction_for_profile = authorize_credit_card()
validate_response(response)
response = create_customer_profile_from_a_transaction(create_transaction_for_profile.transactionResponse.transId)
validate_response(response)
response = get_customer_payment_profile(customerProfileId, customerPaymentProfileId)
validate_response(response)
response = get_customer_payment_profile_list()
validate_response(response)
response = get_customer_profile(customerProfileId)
validate_response(response)
response = get_customer_profile_ids()
validate_response(response)
response = get_customer_shipping_address(customerProfileId, customerAddressId)
validate_response(response)
response = get_accept_customer_profile_page(customerProfileId)
validate_response(response)
response = update_customer_payment_profile(customerProfileId, customerPaymentProfileId)
validate_response(response)
response = update_customer_profile(customerProfileId)
validate_response(response)
response = update_customer_shipping_address(customerProfileId, customerAddressId)
validate_response(response)
response = delete_customer_shipping_address(customerProfileId, customerAddressId)
validate_response(response)
response = delete_customer_payment_profile(customerProfileId, customerPaymentProfileId)
validate_response(response)
response = delete_customer_profile(customerProfileId)
validate_response(response)
end
it "should be able to run all Recurring Billing sample code" do
puts "START - Recurring Billing"
response = create_Subscription()
validate_response(response)
subscriptionId = response.subscriptionId
# Create subscription from customer profile
profile_response = create_customer_profile()
payment_response = create_customer_payment_profile(profile_response.customerProfileId)
shipping_response = create_customer_shipping_address(profile_response.customerProfileId)
# waiting for creating customer profile.
puts "Waiting for creation of customer profile..."
sleep 50
puts "Proceeding"
response = create_subscription_from_customer_profile(profile_response.customerProfileId, payment_response.customerPaymentProfileId, shipping_response.customerAddressId)
validate_response(response)
cancel_subscription(response.subscriptionId)
delete_customer_profile(profile_response.customerProfileId)
# End of create subscription from customer profile
response = get_subscription(subscriptionId)
validate_response(response)
response = get_list_of_subscriptions()
validate_response(response)
response = get_subscription_status(subscriptionId)
validate_response(response)
response = update_subscription(subscriptionId)
validate_response(response)
response = cancel_subscription(subscriptionId)
validate_response(response)
end
it "should be able to run all Payment Transaction sample code" do
puts "START - Payment Transactions"
response = authorize_credit_card()
validate_response(response)
response = capture_funds_authorized_through_another_channel()
validate_response(response)
# response = capture_only()
# validate_response(response)
response = capture_funds_authorized_through_another_channel()
validate_response(response)
response = capture_previously_authorized_amount()
validate_response(response)
response = charge_credit_card()
validate_response(response)
# create customer profile
response = create_customer_profile()
validate_response(response)
customerProfileId = response.customerProfileId
# create customer payment profile
response = create_customer_payment_profile(customerProfileId)
validate_response(response)
customerPaymentProfileId = response.customerPaymentProfileId
response = charge_customer_profile(customerProfileId, customerPaymentProfileId)
validate_response(response)
response = charge_tokenized_credit_card()
validate_response(response)
response = credit_bank_account()
validate_response(response)
response = debit_bank_account()
validate_response(response)
# response = refund_transaction()
# validate_response(response)
response = update_split_tender_group()
validate_response(response)
response = void_transaction()
validate_response(response)
end
it "should be able to run all PayPal Express Checkout sample code" do
puts "START - PayPal Express Checkout"
puts "TEST - authorization and capture"
response = authorization_and_capture()
validate_response(response)
# response = authorization_and_capture_continued()
# validate_response(response)
puts "TEST - authorization only"
response = authorization_only()
validate_response(response)
authTransId = response.transactionResponse.transId
puts "TransId to be used for AuthOnlyContinued, GetDetails & Void : #{authTransId}"
puts "TEST - authorization only continued"
response = authorization_only_continued(authTransId)
validate_response(response)
# response = credit()
# validate_response(response)
puts "TEST - Get Details"
response = get_details(authTransId)
validate_response(response)
puts "TEST - prior authorization and capture"
response = prior_authorization_capture()
validate_response(response)
# puts "TEST - Void"
# authTransId = get_transId()
# response = void(authTransId)
# validate_response(response)
end
it "should be able to run all Transaction Reporting sample code" do
puts "START - Transaction Reporting"
response = get_settled_batch_List()
validate_response(response)
# Start Get Batch Statistics
batchId = response.batchList.batch[0].batchId
response = get_batch_Statistics(batchId)
validate_response(response)
# End Get Batch Statistics
response = get_transaction_Details()
validate_response(response)
response = get_transaction_List()
validate_response(response)
response = get_unsettled_transaction_List()
validate_response(response)
response = get_Transaction_List_For_Customer()
validate_response(response)
end
it "should be able to run Merchant Details sample code" do
puts "START - Transaction Reporting / Merchant Details"
response = get_merchant_details()
validate_response(response)
end
it "should be able to run all Visa Checkout sample code" do
puts "START - Visa Checkout"
# response = create_visa_src_transaction()
# validate_response(response)
# response = decrypt_visa_src_data()
# validate_response(response)
end
it "should be able to run all Apple Pay sample code" do
# response = create_an_apple_pay_transaction()
# validate_response(response)
end
it "should be able to run Update Held Transaction sample code" do
# response = update_held_transaction("12345")
# validate_response(response)
end
it "should be able to run Get Accept Payment Page sample code" do
response = get_an_accept_payment_page()
validate_response(response)
end
end