paypkg 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +222 -0
- data/config/paypkg.yml +18 -0
- data/lib/paypkg/accept-pp-payment.rb +77 -0
- data/lib/paypkg/accept-stored-cc-payment.rb +43 -0
- data/lib/paypkg/accept-tendered-cc-payment.rb +50 -0
- data/lib/paypkg/delete-credit-card.rb +13 -0
- data/lib/paypkg/nil-empty?.rb +12 -0
- data/lib/paypkg/paypal-countries.rb +233 -0
- data/lib/paypkg/paypal-currencies.rb +32 -0
- data/lib/paypkg/paypal-languages.rb +35 -0
- data/lib/paypkg/refund-sale.rb +26 -0
- data/lib/paypkg/retrieve-credit-card.rb +18 -0
- data/lib/paypkg/retrieve-refund-transaction.rb +14 -0
- data/lib/paypkg/retrieve-sale-transaction.rb +14 -0
- data/lib/paypkg/store-credit-card.rb +48 -0
- data/lib/paypkg/validate-credit-card.rb +71 -0
- data/lib/paypkg/version.rb +3 -0
- data/lib/paypkg.rb +73 -545
- data/test/paypkg_test/approved.html.erb +10 -0
- data/test/paypkg_test/cancelled.html.erb +2 -0
- data/test/paypkg_test/test1.html.erb +15 -0
- data/test/paypkg_test_controller.rb +229 -0
- metadata +28 -8
@@ -0,0 +1,229 @@
|
|
1
|
+
class PaypkgTestController < ApplicationController
|
2
|
+
|
3
|
+
def test1
|
4
|
+
@notes = []
|
5
|
+
|
6
|
+
card_id = nil
|
7
|
+
begin
|
8
|
+
pp = Paypkg.new(session)
|
9
|
+
|
10
|
+
@ok = pp.validate_credit_card('visa', '4417119669820331', '11', '2018', '999', \
|
11
|
+
'Betsy', 'Buyer', '111 First Street', 'Saratoga', 'CA', '95070', 'US')
|
12
|
+
if @ok then
|
13
|
+
@notes << "validate_credit_card OK"
|
14
|
+
authorization_data = pp.hash.first
|
15
|
+
void_data = pp.hash.last
|
16
|
+
auth_payment_id = authorization_data[:id]
|
17
|
+
auth_id = authorization_data[:transactions][0][:related_resources][0][:authorization][:id]
|
18
|
+
void_payment_id = void_data[:parent_payment]
|
19
|
+
void_id = void_data[:id]
|
20
|
+
if (auth_payment_id==void_payment_id) && (auth_id==void_id)
|
21
|
+
@notes << "validate_credit_card Passed"
|
22
|
+
else
|
23
|
+
@notes << "validate_credit_card Failed"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
@notes << "validate_credit_card NOT OK"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
@ok = pp.store_credit_card('visa', '4417119669820331', '11', '2018', '999', \
|
31
|
+
'Betsy', 'Buyer', '111 First Street', nil, 'Saratoga', 'CA', '95070', 'US', 'betsy')
|
32
|
+
if @ok then
|
33
|
+
@notes << "store_credit_card OK"
|
34
|
+
card_data = pp.hash.last
|
35
|
+
card_id = card_data[:id]
|
36
|
+
else
|
37
|
+
@notes << "store_credit_card NOT OK"
|
38
|
+
card_id = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
if card_id
|
43
|
+
@ok = pp.retrieve_credit_card(card_id)
|
44
|
+
if @ok then
|
45
|
+
@notes << "retrieve_credit_card OK"
|
46
|
+
if (card_data==pp.hash.last)
|
47
|
+
@notes << "retrieve_credit_card Passed"
|
48
|
+
else
|
49
|
+
@notes << "retrieve_credit_card Failed"
|
50
|
+
end
|
51
|
+
else
|
52
|
+
@notes << "retrieve_credit_card NOT OK"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
@notes << "retrieve_credit_card NOT TESTED"
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
@ok = pp.accept_tendered_cc_payment('visa', '4417119669820331', '11', '2018', '999', 'Betsy', 'Buyer', 3.0, "Tendered Payment")
|
60
|
+
if @ok then
|
61
|
+
@notes << "accept_tendered_cc_payment OK"
|
62
|
+
tendered_data = pp.hash.last
|
63
|
+
payment_id = tendered_data[:id]
|
64
|
+
sale_id = tendered_data[:transactions][0][:related_resources][0][:sale][:id]
|
65
|
+
else
|
66
|
+
@notes << "accept_tendered_cc_payment NOT OK"
|
67
|
+
payment_id = nil
|
68
|
+
sale_id = nil
|
69
|
+
end
|
70
|
+
|
71
|
+
if sale_id
|
72
|
+
@ok = pp.retrieve_sale_transaction(sale_id)
|
73
|
+
if @ok then
|
74
|
+
@notes << "retrieve_sale_transaction OK"
|
75
|
+
if (sale_id==pp.hash.last[:id]) && (payment_id==pp.hash.last[:parent_payment])
|
76
|
+
@notes << "retrieve_sale_transaction Passed"
|
77
|
+
else
|
78
|
+
@notes << "retrieve_sale_transaction Failed"
|
79
|
+
end
|
80
|
+
else
|
81
|
+
@notes << "retrieve_sale_transaction NOT OK"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
@notes << "retrieve_sale_transaction NOT TESTED"
|
85
|
+
end
|
86
|
+
|
87
|
+
if sale_id
|
88
|
+
@ok = pp.refund_sale(sale_id,2.0)
|
89
|
+
if @ok then
|
90
|
+
@notes << "refund_sale OK"
|
91
|
+
refund_data = pp.hash.last
|
92
|
+
refund_id = refund_data[:id]
|
93
|
+
if (refund_data[:sale_id]==sale_id) && (refund_data[:amount][:total]=="2.00")
|
94
|
+
@notes << "refund_sale Passed"
|
95
|
+
else
|
96
|
+
@notes << "refund_sale Failed"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
@notes << "refund_sale NOT OK"
|
100
|
+
refund_id = nil
|
101
|
+
end
|
102
|
+
else
|
103
|
+
@notes << "refund_sale NOT TESTED"
|
104
|
+
refund_id = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
if card_id
|
108
|
+
@ok = pp.accept_stored_cc_payment(card_id, 3.0, 'Test Charge', 'test@example.com', 'betsy')
|
109
|
+
if @ok then
|
110
|
+
@notes << "accept_stored_cc_payment OK"
|
111
|
+
stored_data = pp.hash.last
|
112
|
+
payment_id = stored_data[:id]
|
113
|
+
sale_id = stored_data[:transactions][0][:related_resources][0][:sale][:id]
|
114
|
+
else
|
115
|
+
@notes << "accept_stored_cc_payment NOT OK"
|
116
|
+
payment_id = nil
|
117
|
+
sale_id = nil
|
118
|
+
end
|
119
|
+
else
|
120
|
+
@notes << "accept_stored_cc_payment NOT TESTED"
|
121
|
+
payment_id = nil
|
122
|
+
sale_id = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
if sale_id
|
126
|
+
@ok = pp.retrieve_sale_transaction(sale_id)
|
127
|
+
if @ok then
|
128
|
+
@notes << "retrieve_sale_transaction OK"
|
129
|
+
if (sale_id==pp.hash.last[:id]) && (payment_id==pp.hash.last[:parent_payment])
|
130
|
+
@notes << "retrieve_sale_transaction Passed"
|
131
|
+
else
|
132
|
+
@notes << "retrieve_sale_transaction Failed"
|
133
|
+
end
|
134
|
+
else
|
135
|
+
@notes << "retrieve_sale_transaction NOT OK"
|
136
|
+
end
|
137
|
+
else
|
138
|
+
@notes << "retrieve_sale_transaction NOT OK"
|
139
|
+
end
|
140
|
+
|
141
|
+
if sale_id
|
142
|
+
@ok = pp.refund_sale(sale_id,3.0)
|
143
|
+
if @ok then
|
144
|
+
@notes << "refund_sale OK"
|
145
|
+
refund_data = pp.hash.last
|
146
|
+
refund_id = refund_data[:id]
|
147
|
+
if (refund_data[:sale_id]==sale_id) && (refund_data[:amount][:total]=="3.00")
|
148
|
+
@notes << "refund_sale Passed"
|
149
|
+
else
|
150
|
+
@notes << "refund_sale Failed"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
@notes << "refund_sale NOT OK"
|
154
|
+
refund_id = nil
|
155
|
+
end
|
156
|
+
else
|
157
|
+
@notes << "refund_sale NOT TESTED"
|
158
|
+
refund_id = nil
|
159
|
+
end
|
160
|
+
|
161
|
+
if refund_id
|
162
|
+
@ok = pp.retrieve_refund_transaction(refund_id)
|
163
|
+
if @ok then
|
164
|
+
@notes << "retrieve_refund_transaction OK"
|
165
|
+
if (sale_id==pp.hash.last[:sale_id]) && (payment_id==pp.hash.last[:parent_payment])
|
166
|
+
@notes << "retrieve_refund_transaction Passed"
|
167
|
+
else
|
168
|
+
@notes << "retrieve_refund_transaction Failed"
|
169
|
+
end
|
170
|
+
else
|
171
|
+
@notes << "retrieve_refund_transaction NOT OK"
|
172
|
+
end
|
173
|
+
else
|
174
|
+
@notes << "retrieve_refund_transaction NOT TESTED"
|
175
|
+
end
|
176
|
+
|
177
|
+
if card_id
|
178
|
+
@ok = pp.delete_credit_card(card_id)
|
179
|
+
if @ok then
|
180
|
+
@notes << "delete_credit_card OK"
|
181
|
+
else
|
182
|
+
@notes << "delete_credit_card NOT OK"
|
183
|
+
end
|
184
|
+
else
|
185
|
+
@notes << "delete_credit_card NOT OK"
|
186
|
+
end
|
187
|
+
|
188
|
+
rescue => e
|
189
|
+
@notes << "Processing NOT passed because %s"%e.to_s
|
190
|
+
|
191
|
+
ensure
|
192
|
+
if card_id
|
193
|
+
pp.delete_credit_card(card_id)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
def test2
|
201
|
+
pp = Paypkg.new(session)
|
202
|
+
@ok = pp.accept_pp_payment(3.0, 'Test Charge', 'paypkg_test/approved', 'paypkg_test/cancelled', 'betsy')
|
203
|
+
redirect_to pp.link if @ok
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
########################
|
208
|
+
### CALLBACK ACTIONS ###
|
209
|
+
########################
|
210
|
+
|
211
|
+
def approved
|
212
|
+
pp = Paypkg.new(session)
|
213
|
+
@ok = pp.execute_payment(params[:PayerID],session[:payment_id])
|
214
|
+
if @ok
|
215
|
+
payment_data = pp.hash.last
|
216
|
+
@payment_id = payment_data[:id]
|
217
|
+
@sale_id = payment_data[:transactions][0][:related_resources][0][:sale][:id]
|
218
|
+
@amount = payment_data[:transactions][0][:related_resources][0][:sale][:amount][:total]
|
219
|
+
session.delete(:payment_id)
|
220
|
+
@note = nil
|
221
|
+
else
|
222
|
+
@note = pp.hash.last.pretty_inspect
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def cancelled
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypkg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael J. Welch, Ph.D.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
no documentation yet, but I'll get around to it later.
|
17
|
-
email: paypkg@czarmail.com
|
13
|
+
description: This gem uses Net::HTTP to communicate with the PayPal servers. It has
|
14
|
+
calls for the most common PayPal functions to simplify using PayPal in a Ruby application.
|
15
|
+
email: rubygems@czarmail.com
|
18
16
|
executables: []
|
19
17
|
extensions: []
|
20
18
|
extra_rdoc_files: []
|
21
19
|
files:
|
20
|
+
- config/paypkg.yml
|
21
|
+
- CHANGELOG.md
|
22
|
+
- README.md
|
22
23
|
- lib/paypkg.rb
|
24
|
+
- lib/paypkg/delete-credit-card.rb
|
25
|
+
- lib/paypkg/refund-sale.rb
|
26
|
+
- lib/paypkg/validate-credit-card.rb
|
27
|
+
- lib/paypkg/retrieve-refund-transaction.rb
|
28
|
+
- lib/paypkg/accept-pp-payment.rb
|
29
|
+
- lib/paypkg/store-credit-card.rb
|
30
|
+
- lib/paypkg/retrieve-sale-transaction.rb
|
31
|
+
- lib/paypkg/paypal-countries.rb
|
32
|
+
- lib/paypkg/paypal-currencies.rb
|
33
|
+
- lib/paypkg/paypal-languages.rb
|
34
|
+
- lib/paypkg/version.rb
|
35
|
+
- lib/paypkg/accept-stored-cc-payment.rb
|
36
|
+
- lib/paypkg/accept-tendered-cc-payment.rb
|
37
|
+
- lib/paypkg/retrieve-credit-card.rb
|
38
|
+
- lib/paypkg/nil-empty?.rb
|
39
|
+
- test/paypkg_test_controller.rb
|
40
|
+
- test/paypkg_test/cancelled.html.erb
|
41
|
+
- test/paypkg_test/test1.html.erb
|
42
|
+
- test/paypkg_test/approved.html.erb
|
23
43
|
homepage: http://rubygems.org/gems/paypkg
|
24
44
|
licenses:
|
25
45
|
- MIT
|
@@ -43,5 +63,5 @@ rubyforge_project:
|
|
43
63
|
rubygems_version: 2.0.7
|
44
64
|
signing_key:
|
45
65
|
specification_version: 4
|
46
|
-
summary:
|
66
|
+
summary: Simple PayPal Connection for Ruby
|
47
67
|
test_files: []
|