paypkg 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5b0aa6a615a910d02a4c57fa7c2a70fbf95eeb3
4
- data.tar.gz: 1fd27b3481a219eb03e2c98d11e4fa1e7a24033c
3
+ metadata.gz: bcdfc3694731fcc63076418e59a20a550e820f8e
4
+ data.tar.gz: d8230d7f5f3273ea7883f8f4896e5baca0f8f0a3
5
5
  SHA512:
6
- metadata.gz: 59f31039f45400d9897354dde0e50aaa23226f1ceb623f42a8adc20fbf9d82cf170466097cbbff8a0204ce295fa95e9ea58701d1c48239c2d1fe2e150d7420e3
7
- data.tar.gz: 115c69d5783457506a674ee76505818c4ce00e648e6af3a5996b7ee94fc2386c00b061a58f13e8d239a48717f15d2bc4f553b830e68f99e457558f97928db947
6
+ metadata.gz: 0c70b9309385a07da1f8e228d1239f78bcf4e689c6c51f7597c18e3744116f4d7aba35150a0812a733badc103bb270c2bc503cd3bf11d753bed26cc550e94ce5
7
+ data.tar.gz: f4b6fb5c8285e62e3b4852a38999b2b0cd6ae0c8a0df63c833e3ebce74815a9fa2964960b4c88d2ee7924929a1c9b69eb47517536c9e21db46426a6135393710
@@ -1,3 +1,17 @@
1
+ 0.1.2
2
+ -----
3
+ * Exposed the json data (input) string as request, i.e.:
4
+ pp = Paypkg.new status
5
+ pp.some_call(...)
6
+ r = pp.request # <-- this is the json string that was passed to PayPal.
7
+ NOTE: it only has the request AFTER you call call_paypkg because
8
+ paypkg puts the string into it when it's called so you can see what
9
+ your input looked like after it was prepared to send to PayPal.
10
+ Like json and hash, request is an array.
11
+ * Added retrieve_payment_resource(payment_id) for looking up payments.
12
+ * Updated paypkg_test.rb to test the new method above.
13
+ * Added a README.html because a text file just doesn't cut it.
14
+
1
15
  0.1.1
2
16
  -----
3
17
  * Added PaypkgResponse, a class that converts a hash equivilent of the json output to an object.
@@ -0,0 +1,603 @@
1
+ <style>
2
+ pre {
3
+ background-color:black;
4
+ color:white;
5
+ margin-left: 50px;
6
+ padding:5px;
7
+ display:inline-block;
8
+ font-size: 85%;
9
+ font-family: Monospace, Serif;
10
+ }
11
+ code {
12
+ border: 1px solid silver;
13
+ font-size: 80%;
14
+ }
15
+ body {
16
+ }
17
+ </style>
18
+ <body>
19
+ <h1>Pay Package (paypkg)</h1>
20
+ <h2>A Ruby Gem designed to simplify connecting to PayPal</h2>
21
+
22
+ <!-------------------------------------------------------------------->
23
+ <h3>Copyright</h3>
24
+
25
+ <p>Copyright (&copy;) 2014, Michael J. Welch, Ph.D. and Contributors. All Rights Reserved.</p>
26
+
27
+ <p>Email: rubygems@czarmail.com</p>
28
+
29
+ <p>This project is licensed under the [MIT License] (LICENSE.md).</p>
30
+
31
+
32
+ <!-------------------------------------------------------------------->
33
+ <h3>Features:</h3>
34
+
35
+ <ul>
36
+ <li>Uses <code>Net::HTTP</code> to communicate with PayPal servers.</li>
37
+ <li>Easy to set up and use.</li>
38
+ </ul>
39
+
40
+
41
+ <!-------------------------------------------------------------------->
42
+ <h3>Install</h3>
43
+
44
+ <p>To install this gem, (and another one I recommend) use:</p>
45
+ <pre>development:~$ gem install paypkg
46
+ development:~$ gem install pretty_inspect</pre>
47
+
48
+
49
+ <!-------------------------------------------------------------------->
50
+ <h3>Want to Make a Rails Test Project?</h3>
51
+
52
+ <p>Follow the steps below. First, create a rails project. In this case, I'm using bundler. You probably are too..</p>
53
+
54
+ <pre>development:~$ rails new paypkg-test -d mysql
55
+ create
56
+ create README.rdoc
57
+ ...
58
+ create vendor/assets/stylesheets/.keep
59
+ run bundle install
60
+ Fetching gem metadata from https://rubygems.org/...........
61
+ Fetching additional metadata from https://rubygems.org/..
62
+ Resolving dependencies...
63
+ Using rake (10.3.1)
64
+ ...
65
+ Using uglifier (2.5.0)
66
+ Your bundle is complete!
67
+ Use `bundle show [gemname]` to see where a bundled gem is installed.
68
+ development:~$ </pre>
69
+
70
+ <p>Change Directory into Your Project</p>
71
+
72
+ <pre>development:~$ cd paypkg-test
73
+ development:~/paypkg-test$ </pre>
74
+
75
+ <p>If you're using bundler, you'll need to add <code>paypkg</code>, and <code>pretty-inspect</code> to your <code>Gemfile</code>.</p>
76
+
77
+ <pre>...
78
+ # Use this gem to connect to PayPal
79
+ gem 'paypkg'
80
+ gem 'pretty_inspect'
81
+ ...</pre>
82
+
83
+ <p>I had problems with the new <code>spring</code> gem. The "rails c" environment would hang, so if you have the same problem, try commenting out that gem.</p>
84
+
85
+ <pre># Spring speeds up development by keeping your application running in the background.
86
+ # gem 'spring', group: :development</pre>
87
+
88
+
89
+ <p>Then you'll have to run bundler again.</p>
90
+
91
+ <pre>development:~/paypkg-test$ bundle install
92
+ Resolving dependencies...
93
+ Using rake (10.3.1)
94
+ ...
95
+ Using paypkg (0.1.2)
96
+ Using pretty_inspect (0.9.0)
97
+ ...
98
+ Using uglifier (2.5.0)
99
+ Your bundle is complete!
100
+ Use `bundle show [gemname]` to see where a bundled gem is installed.
101
+ development:~/paypkg-test$ </pre>
102
+
103
+ <p>Edit the <code>config/routes.rb</code> file, and add the routes:</p>
104
+
105
+ <pre>Rails.application.routes.draw do
106
+ get 'paypkg_test/test1' => 'paypkg_test#test1'
107
+ get 'paypkg_test/test2' => 'paypkg_test#test2'
108
+ get 'paypkg_test/approved' => 'paypkg_test#approved'
109
+ get 'paypkg_test/cancelled' => 'paypkg_test#cancelled'
110
+ end</pre>
111
+
112
+ <p>Configure your <code>config/database.yml</code>. If you don't know how to do this, consult your Rails documentation. If you already have a working project, you can copy the <code>database.yml</code> from there. This test program does <i><b>not</b></i> access the database, but Rails won't start without one.</p>
113
+
114
+ <p>Copy the test page and view folder. Your gems might be in a different place, so beware!</p>
115
+
116
+ <pre>development:~/paypkg-test$ cp /var/lib/gems/2.0.0/gems/paypkg-0.1.2/test/paypkg_test_controller.rb app/controllers/paypkg_test_controller.rb
117
+ development:~/paypkg-test$ cp -r /var/lib/gems/2.0.0/gems/paypkg-0.1.2/test/paypkg_test app/views/paypkg_test
118
+ development:~/paypkg-test$ </pre>
119
+
120
+ <p>Configure Pay Package. Create a file named <code>config/paypkg.yml</code> and put this code in it, modified to use your own data.</p>
121
+
122
+ <pre>development:
123
+ client_id: '--------your sandbox client ID as assigned by PayPal--------'
124
+ secret: '---------your sandbox secret as assigned by PayPal----------'
125
+ uri_base: 'https://api.sandbox.paypal.com'
126
+ website: 'http://www.example.com:3000'
127
+
128
+ test:
129
+ client_id: '--------your sandbox client ID as assigned by PayPal--------'
130
+ secret: '---------your sandbox secret as assigned by PayPal----------'
131
+ uri_base: 'https://api.sandbox.paypal.com'
132
+ website: 'http://www.example.com:3000'
133
+
134
+ production:
135
+ client_id: '-------your production client ID as assigned by PayPal------'
136
+ secret: '--------your production secret as assigned by PayPal--------'
137
+ uri_base: 'https://api.paypal.com'
138
+ website: 'https://example.com'</pre>
139
+
140
+ <p>Run Webrick to test the paypkg gem.</p>
141
+
142
+ <pre>development:~/paypkg-test$ rails s
143
+ => Booting WEBrick
144
+ => Rails 4.0.4 application starting in development on http://0.0.0.0:3000
145
+ => Run `rails server -h` for more startup options
146
+ => Ctrl-C to shutdown server
147
+ [2014-04-22 03:37:14] INFO WEBrick 1.3.1
148
+ [2014-04-22 03:37:14] INFO ruby 2.0.0 (2013-08-29) [x86_64-linux-gnu]
149
+ [2014-04-22 03:37:14] INFO WEBrick::HTTPServer#start: pid=21184 port=3000</pre>
150
+
151
+ <p>In your browser, type <code>www.example.com:3000</code> and you should get:
152
+
153
+ <title>Ruby on Rails: Welcome aboard</title>
154
+ <style media="screen">
155
+ body {
156
+ margin: 0;
157
+ margin-bottom: 25px;
158
+ padding: 0;
159
+ background-color: #f0f0f0;
160
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
161
+ font-size: 13px;
162
+ color: #333;
163
+ }
164
+
165
+ h1 {
166
+ font-size: 28px;
167
+ color: #000;
168
+ }
169
+
170
+ a {color: #03c}
171
+ a:hover {
172
+ background-color: #03c;
173
+ color: white;
174
+ text-decoration: none;
175
+ }
176
+
177
+
178
+ #page {
179
+ background-color: #f0f0f0;
180
+ width: 750px;
181
+ margin: 0;
182
+ margin-left: auto;
183
+ margin-right: auto;
184
+ }
185
+
186
+ #content {
187
+ float: left;
188
+ background-color: white;
189
+ border: 3px solid #aaa;
190
+ border-top: none;
191
+ padding: 25px;
192
+ width: 500px;
193
+ }
194
+
195
+ #sidebar {
196
+ float: right;
197
+ width: 175px;
198
+ }
199
+
200
+ #footer {
201
+ clear: both;
202
+ }
203
+
204
+ #header, #about, #getting-started {
205
+ padding-left: 75px;
206
+ padding-right: 30px;
207
+ }
208
+
209
+
210
+ #header {
211
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAABACAYAAABY1SR7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAGZhJREFUeNqsWwmUXGWV/t5Sr9aurl6qO0l3Z9/DEoJh18gZQGAUxPHIyQHH7eioZ8bjnAFHZ0RndNxxRBhGcUbxoKIHBkTEcUYREIHIGpKQjUDS6U660/tSVV3Lq/fefPf/Xy2dBFGYx3npqvde/e/e/97v3u/e/8e4Lt2L8DCCAFcGwF8ZBjYbgM1rAZoO+WLwZhDMu9y4+YcOozbAqzwXNA3GdzX/5hV+KnKO2+GXFj/AvzmW8e72iG202CYiphbY403f9/k3QHZtJ9oWtyCQe7wGX79TKVb7rP9pXJPDVxf0Rz+oyxm4HNWrahFNixdk3EAJbERMWOm4ulctVODNVeEVK0DeRVDgb1wfJgcqUo6duaKnFOH7bm6JmH+5LOEgZprwRIHAV3JYfLjKM55Noz3bBqdcgt0Wg52Kq/cHHkXns0qIukKBlltk9rU2QaiouiefPQ+RdBuseAJeqYTK1CTH8mE4NsyIpRWu8nssCs+xULWpjGVwTvieKl/sV6mIXzOib/OftzuG8d6l8SiVMODyRb46oazg8YPP2Wnvy9ISNqplzsxYAW6hjGhHEmYiBoPC+hRMfFMrESgrBC5n0KS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x9262qABrfw1KaJW15YprXvsVcEG1sT5eCji40fXSURVyAvTd9TSmv6nTVifQx/uwzmHiU7kb3Clu+GC27MsY247p07+SihN0m/Kgc6EXRIjmMgDvCF9mcsXJxDgniZSnN3xFLIcc6Yormd1mhCX2QpWc7SteolNUpNUQkIUvJpDkUrsrfqy1L8ZjaFSTrJKLsCbvz6BqxaBwdBReWbJmF3kTa2NYRVYFGHEYKqqFKFXtzMg6uUhaJyzZyQ/d/FdUm8LwmAuYwO/vhQBU+m+ddmy+NpBKNWpIzF7EdRSxrOygMMl6LruUw2tQXOTy1akNFk/XtU/V70H3g6YyNNk5GtOIp/DYvlKp9LoJLWuIl2fADfJ/X71PQ8Jo2Vzbv620OAFI9jtIqCQ7tnfC/JxhNT4dShds4UKvB66s1ftPnRqOh/l13hDDqWGhxqUgTsIV1Fzg5Y7TEpKsK+B/w+sdqUWuqv1CxUN8K/MqHLMnhj/g/J/4/juDky9VSg0kh/zQj322897Pao/8nwAC+AZicLeuzngAAAABJRU5ErkJggg==);
212
+ background-repeat: no-repeat;
213
+ background-position: top left;
214
+ height: 64px;
215
+ }
216
+ #header h1, #header h2 {margin: 0}
217
+ #header h2 {
218
+ color: #888;
219
+ font-weight: normal;
220
+ font-size: 16px;
221
+ }
222
+
223
+
224
+ #about h3 {
225
+ margin: 0;
226
+ margin-bottom: 10px;
227
+ font-size: 14px;
228
+ }
229
+
230
+ #about-content {
231
+ background-color: #ffd;
232
+ border: 1px solid #fc0;
233
+ margin-left: -55px;
234
+ margin-right: -10px;
235
+ }
236
+ #about-content table {
237
+ margin-top: 10px;
238
+ margin-bottom: 10px;
239
+ font-size: 11px;
240
+ border-collapse: collapse;
241
+ }
242
+ #about-content td {
243
+ padding: 10px;
244
+ padding-top: 3px;
245
+ padding-bottom: 3px;
246
+ }
247
+ #about-content td.name {color: #555}
248
+ #about-content td.value {color: #000}
249
+
250
+ #about-content ul {
251
+ padding: 0;
252
+ list-style-type: none;
253
+ }
254
+
255
+ #about-content.failure {
256
+ background-color: #fcc;
257
+ border: 1px solid #f00;
258
+ }
259
+ #about-content.failure p {
260
+ margin: 0;
261
+ padding: 10px;
262
+ }
263
+
264
+
265
+ #getting-started {
266
+ border-top: 1px solid #ccc;
267
+ margin-top: 25px;
268
+ padding-top: 15px;
269
+ }
270
+ #getting-started h1 {
271
+ margin: 0;
272
+ font-size: 20px;
273
+ }
274
+ #getting-started h2 {
275
+ margin: 0;
276
+ font-size: 14px;
277
+ font-weight: normal;
278
+ color: #333;
279
+ margin-bottom: 25px;
280
+ }
281
+ #getting-started ol {
282
+ margin-left: 0;
283
+ padding-left: 0;
284
+ }
285
+ #getting-started li {
286
+ font-size: 18px;
287
+ color: #888;
288
+ margin-bottom: 25px;
289
+ }
290
+ #getting-started li h2 {
291
+ margin: 0;
292
+ font-weight: normal;
293
+ font-size: 18px;
294
+ color: #333;
295
+ }
296
+ #getting-started li p {
297
+ color: #555;
298
+ font-size: 13px;
299
+ }
300
+
301
+
302
+ #sidebar ul {
303
+ margin-left: 0;
304
+ padding-left: 0;
305
+ }
306
+ #sidebar ul h3 {
307
+ margin-top: 25px;
308
+ font-size: 16px;
309
+ padding-bottom: 10px;
310
+ border-bottom: 1px solid #ccc;
311
+ }
312
+ #sidebar li {
313
+ list-style-type: none;
314
+ }
315
+ #sidebar ul.links li {
316
+ margin-bottom: 5px;
317
+ }
318
+
319
+ .filename {
320
+ font-style: italic;
321
+ }
322
+ </style>
323
+ <script>
324
+ function about() {
325
+ var info = document.getElementById('about-content'),
326
+ xhr;
327
+
328
+ if (info.innerHTML === '') {
329
+ xhr = new XMLHttpRequest();
330
+ xhr.open("GET", "/rails/info/properties", false);
331
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
332
+ xhr.send("");
333
+ info.innerHTML = xhr.responseText;
334
+ }
335
+
336
+ info.style.display = info.style.display === 'none' ? 'block' : 'none';
337
+ }
338
+ </script>
339
+ </head>
340
+ <body>
341
+ <div id="page">
342
+ <div id="sidebar">
343
+ <ul id="sidebar-items">
344
+ <li>
345
+ <h3>Browse the documentation</h3>
346
+ <ul class="links">
347
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
348
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
349
+ <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
350
+ <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
351
+ </ul>
352
+ </li>
353
+ </ul>
354
+ </div>
355
+
356
+ <div id="content">
357
+ <div id="header">
358
+ <h1>Welcome aboard</h1>
359
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
360
+ </div>
361
+
362
+ <div id="about">
363
+ <h3><a href="/rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
364
+ <div id="about-content" style="display: none"></div>
365
+ </div>
366
+
367
+ <div id="getting-started">
368
+ <h1>Getting started</h1>
369
+ <h2>Here&rsquo;s how to get rolling:</h2>
370
+
371
+ <ol>
372
+ <li>
373
+ <h2>Use <code>rails generate</code> to create your models and controllers</h2>
374
+ <p>To see all available options, run it without parameters.</p>
375
+ </li>
376
+
377
+ <li>
378
+ <h2>Set up a root route to replace this page</h2>
379
+ <p>You're seeing this page because you're running in development mode and you haven't set a root route yet.</p>
380
+ <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
381
+ </li>
382
+
383
+ <li>
384
+ <h2>Configure your database</h2>
385
+ <p>If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
386
+ </li>
387
+ </ol>
388
+ </div>
389
+ </div>
390
+
391
+ <div id="footer">&nbsp;</div>
392
+ </div>
393
+
394
+ <p>To run the first test, type into your browser <code>http://www.example.com:3000/paypkg_test/test1</code>. This test does a lot of PayPal acesses, so it may take a couple of minutes. If you have a problem in your setup, it'll die immediately. If all is well, you should get the results shown below.</p>
395
+
396
+ <pre>Paypkg Test1
397
+
398
+ validate_credit_card OK
399
+ validate_credit_card Passed
400
+ store_credit_card OK
401
+ retrieve_credit_card OK
402
+ retrieve_credit_card Passed
403
+ accept_tendered_cc_payment OK
404
+ retrieve_sale_transaction OK
405
+ retrieve_sale_transaction Passed
406
+ refund_sale OK
407
+ refund_sale Passed
408
+ accept_stored_cc_payment OK
409
+ retrieve_sale_transaction OK
410
+ retrieve_sale_transaction Passed
411
+ refund_sale OK
412
+ refund_sale Passed
413
+ retrieve_refund_transaction OK
414
+ retrieve_refund_transaction Passed
415
+ delete_credit_card OK</pre>
416
+
417
+ <p>Test2 will request a payment from a client through PayPal.</p>
418
+
419
+ <pre>Paypkg -- Buyer Approved
420
+
421
+ The buyer selected to approve the purchase.
422
+
423
+
424
+ payment ID: PAY-5L177311YG734994KKNK64AY
425
+
426
+ Sale ID: 2UU00055SD347731A
427
+
428
+ Amount: 3.00</pre>
429
+
430
+
431
+ <!-------------------------------------------------------------------->
432
+ <h3>Sample Responses</h3>
433
+
434
+ <p>A simple way to see what you're going to get back is to run the class in<code>rails c</code>. Here's an example of three transactions taken from the test suite <code>test/paypkg_test_controller.rb</code>.</p>
435
+
436
+ <pre>development:~/paypkg-test$ rails c
437
+ Loading development environment (Rails 4.1.0)
438
+ irb(main):001:0> </pre>
439
+
440
+ <p>First, you have to create a class instance (which also guarantees that you have a valid access code). The access code will be reused as long as it remains valid (usually 8 hours). In a Rails web app, the codes are kept in the session, but here, in the <code>irb</code>, the codes are reused until the class instance is discarded.</p>
441
+
442
+ <pre>irb(main):001:0> pp = Paypkg.new
443
+ "{\"scope\":\"openid https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/developer/.*
444
+ https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card\",
445
+ \"access_token\":\"---------your sandbox access token---------\",\"token_type\":\"Bearer\",
446
+ \"app_id\":\"-----your app id-----\",\"expires_in\":28800}"
447
+ => #&lt;Paypkg:0x00000004c58858 @session={:paypal_authorization=>{:expires_after=>2014-04-23 07:36:31 +0000,
448
+ :access_token=>"---------your sandbox access token---------"}}, @mode=:development,
449
+ @credentials={"client_id"=>"--------your sandbox client ID as assigned by PayPal--------",
450
+ "secret"=>"---------your sandbox secret as assigned by PayPal----------",
451
+ "uri_base"=>"https://api.sandbox.paypal.com", "website"=>"http://www.example.com:3000"},
452
+ @website="http://www.example.com:3000", @uri_base="https://api.sandbox.paypal.com",
453
+ @http=#&lt;Net::HTTP api.sandbox.paypal.com:443 open=false&gt;,
454
+ @access_token="---------your sandbox access token---------",
455
+ @json=[], @hash=[], @status=[], @request=[]&gt;
456
+ irb(main):002:0></pre>
457
+
458
+ <p>Here we store a new credit card. The return code of <code>true</code> tells us that the status code has been checked and is good. We also save the card_id.</p>
459
+
460
+ <pre>irb(main):002:0> @ok = pp.store_credit_card('visa', '4417119669820331', '11',
461
+ '2018', '999', 'Betsy', 'Buyer', '111 First Street', nil, 'Saratoga', 'CA', '95070', 'US', 'betsy')
462
+ => true
463
+ irb(main):003:0> card_id = card_data[:id]
464
+ => "CARD-4D566808P5063783FKNLP2XI"
465
+ irb(main):004:0></pre>
466
+
467
+ <p>The response from PayPay (in Ruby Hash format) looks like this (notice the use of <code>puts ... pretty_inspect</code>).<br/>
468
+ Compare with the documentation at <a href="https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card">Store a Credit Card</a>.</p>
469
+
470
+ <pre>irb(main):004:0> puts pp.hash.last.pretty_inspect
471
+ {
472
+ :id => "CARD-4D566808P5063783FKNLP2XI",
473
+ :state => "ok",
474
+ :payer_id => "betsy",
475
+ :type => "visa",
476
+ :number => "xxxxxxxxxxxx0331",
477
+ :expire_month => "11",
478
+ :expire_year => "2018",
479
+ :first_name => "Betsy",
480
+ :last_name => "Buyer",
481
+ :billing_address => {
482
+ :line1 => "111 First Street",
483
+ :city => "Saratoga",
484
+ :state => "CA",
485
+ :postal_code => "95070",
486
+ :country_code => "US"
487
+ },
488
+ :valid_until => "2017-04-21T00:00:00Z",
489
+ :create_time => "2014-04-22T23:38:05Z",
490
+ :update_time => "2014-04-22T23:38:05Z",
491
+ :links => [
492
+ {
493
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
494
+ :rel => "self",
495
+ :method => "GET"
496
+ },
497
+ {
498
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
499
+ :rel => "delete",
500
+ :method => "DELETE"
501
+ },
502
+ {
503
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
504
+ :rel => "patch",
505
+ :method => "PATCH"
506
+ }
507
+ ]
508
+ }
509
+ => nil
510
+ irb(main):005:0></pre>
511
+
512
+
513
+
514
+ <p>Now we retrieve the credit card.</p>
515
+
516
+ <pre>irb(main):005:0> @ok = pp.retrieve_credit_card(card_id)
517
+ => true
518
+ irb(main):006:0> </pre>
519
+
520
+ <p>And here's the response (it's the same as the response when we stored the card). The response is not always identical to the original response when the transaction was first accomplished, but it will always contain the essential information. Also note that we use the card_id we stored (in the database in a real application).</p>
521
+
522
+ <pre>irb(main):006:0> puts pp.hash.last.pretty_inspect
523
+ {
524
+ :id => "CARD-4D566808P5063783FKNLP2XI",
525
+ :state => "ok",
526
+ :payer_id => "betsy",
527
+ :type => "visa",
528
+ :number => "xxxxxxxxxxxx0331",
529
+ :expire_month => "11",
530
+ :expire_year => "2018",
531
+ :first_name => "Betsy",
532
+ :last_name => "Buyer",
533
+ :billing_address => {
534
+ :line1 => "111 First Street",
535
+ :city => "Saratoga",
536
+ :state => "CA",
537
+ :postal_code => "95070",
538
+ :country_code => "US"
539
+ },
540
+ :valid_until => "2017-04-21T00:00:00Z",
541
+ :create_time => "2014-04-22T23:38:05Z",
542
+ :update_time => "2014-04-22T23:38:05Z",
543
+ :links => [
544
+ {
545
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
546
+ :rel => "self",
547
+ :method => "GET"
548
+ },
549
+ {
550
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
551
+ :rel => "delete",
552
+ :method => "DELETE"
553
+ },
554
+ {
555
+ :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-4D566808P5063783FKNLP2XI",
556
+ :rel => "patch",
557
+ :method => "PATCH"
558
+ }
559
+ ]
560
+ }
561
+ => nil
562
+ irb(main):007:0></pre>
563
+
564
+ <p>Lastly, we delete the credit card. There's no response, other than the status code, which was verified by the <code>true</code> response.</p>
565
+ <p>If there's a reason to know whether the card was still on PayPal's servers (Paypal automatically removes expired cards), we can check the <code>status</code> code.
566
+
567
+ <pre>irb(main):007:0> @ok = pp.delete_credit_card(card_id)
568
+ => true
569
+ irb(main):008:0>pp.status.last.inspect
570
+ => "\"204\""
571
+ irb(main):009:0></pre>
572
+
573
+ <p>If it's gone, we get this response:</p>
574
+
575
+ <pre>irb(main):009:0> @ok = pp.delete_credit_card(card_id)
576
+ => false
577
+ irb(main):010:0> pp.status.last.inspect
578
+ => "\"404\""
579
+ irb(main):011:0></pre>
580
+
581
+ <p>There's no special closing process: the connection will be closed automaticall when <code>pp</code> is released (set to <code>nil</code> or garbage collected.</p>
582
+
583
+
584
+ <!-------------------------------------------------------------------->
585
+ <h3>PaypkgResponse Class</h3>
586
+
587
+ <p>The class PaypkgResponse is used to objectize a response <code>hash</code> (or almost any
588
+ hash object). Use it separately in other projects, if it works for you.</p>
589
+
590
+ <p>To get the PayPal response in an object format, after a successful call, use <code>response = pp.response</code>.<br/>
591
+ If you want this, for example:</p>
592
+
593
+ <pre>payment_data = pp.hash.last
594
+ @amount = payment_data[:transactions][0][:related_resources][0][:sale][:amount][:total]</pre>
595
+
596
+ <p>you would use this:</p>
597
+
598
+ <pre>payment_data = pp.response # this will convert pp.hash.last
599
+ @amount = payment_data.transactions[0].related_resources[0].sale.amount.total</pre>
600
+
601
+ <p>This is provided to be more compatible with views using ActiveRecord conventions.</p>
602
+
603
+ </body>
data/README.md CHANGED
@@ -3,220 +3,4 @@ Email: rubygems@czarmail.com
3
3
 
4
4
  This project is licenced under the [MIT License](LICENSE.md).
5
5
 
6
-
7
- ###############
8
- ### Install ###
9
- ###############
10
-
11
- To install this gem, use:
12
- gem install paypkg
13
-
14
- I also recommend pretty_inspect, which I use in my example below
15
- and in the test page:
16
- gem install pretty_inspect
17
-
18
- Add the following routes to your route file:
19
- get 'paypkg_test/test1' => 'paypkg_test#test1'
20
- get 'paypkg_test/test2' => 'paypkg_test#test2'
21
- get 'paypkg_test/approved' => 'paypkg_test#approved'
22
- get 'paypkg_test/cancelled' => 'paypkg_test#cancelled'
23
-
24
- Copy the files in the gem's test folder to the app/controllers and app/views, as appropriate:
25
-
26
-
27
- ####################################
28
- ### Setup the Configuration File ###
29
- ####################################
30
-
31
- This gem requires a config file in config/paypkg.yml in your
32
- Rails project that looks like this:
33
-
34
- --- begin config/paypkg.yml -----------------------------------------------
35
- development:
36
- client_id: 'AZPi5hCY-0SoaLmignRs9XV6N4mvRS2TVKFDF2ni53alKL0iJTvtcy9BSR4D'
37
- secret: 'EDubEBAg_ZztC-_HlsW16IFZcxBIatFt7c0ILuxNTpWAVnvrsO9ywVxnHr7J'
38
- uri_base: 'https://api.sandbox.paypal.com'
39
- website: 'http://www.example.com:3000'
40
-
41
- test:
42
- client_id: 'AZPi5hCY-0SoaLmignRs9XV6N4mvRS2TVKFDF2ni53alKL0iJTvtcy9BSR4D'
43
- secret: 'EDubEBAg_ZztC-_HlsW16IFZcxBIatFt7c0ILuxNTpWAVnvrsO9ywVxnHr7J'
44
- uri_base: 'https://api.sandbox.paypal.com'
45
- website: 'http://www.example.com:3000'
46
-
47
- production:
48
- client_id: 'AVWiuBCE6_ps2zCh0Qaq0MaIbP8v2bjfFnKH5esYR9v6sNvu-MzVeWny3crM'
49
- secret: 'EKKoNhCgFn_0lmpUAxXir0ySN4cmaLzGugUmnkgZHR90Kg9Y_DFmJbI2H0Ee'
50
- uri_base: 'https://api.paypal.com'
51
- website: 'https://www.example.com'
52
- --- end config/paypkg.yml -------------------------------------------------
53
-
54
- See the sample in this gem under config/paypkg.yml.
55
-
56
- You have to place your client_id and secret in the file in place of these,
57
- and you have to replace the website with yours. Note that the production
58
- website has https, not http. If your production website is not encrypted
59
- with SSL, use http instead of https.
60
-
61
-
62
- ######################
63
- ### Testing in irb ###
64
- ######################
65
-
66
- The Paypkg class can't see the session variable (because it's only visible
67
- in ApplicationController classes), so to test this interactively, go into
68
- your project and run "rails c" to start irb with a Rails environment, then
69
- create a session variable, and create an instance. You can then run the
70
- functions.
71
-
72
- Why can't I just use irb? Because you need the Rails environment.
73
- That's why the tests are supplied as a controller/views.
74
-
75
-
76
- ######################
77
- ### Using Bundler? ###
78
- ######################
79
-
80
- If you're using bundler, you'll have to add 'paypkg' and 'pretty_inspect'
81
- to your Gemfile, then do a 'bundler install' to be able to use them.
82
-
83
-
84
- ###############################
85
- ### An Example in "rails c" ###
86
- ###############################
87
-
88
- To use the example, by the way, you'll have to put in a 'CARD-XXX...'
89
- number of your own.
90
-
91
- Here is an example:
92
-
93
- devel@mail:~/czar$ rails c
94
- Loading development environment (Rails 4.0.4)
95
- irb(main):001:0> session = {}
96
- => {}
97
- irb(main):002:0> pp = Paypkg.new session
98
- => #<Paypkg:0x000000049f5138 @session={:paypal_authorization=>{:expires_after=>2014-04-19 04:54:05 +0000,\
99
- :access_token=>"8PhJDJVg1mxxGUpSHj9RzzUxB0.sS0qiajx2Nxa1.Fg"}}, @mode=:development,
100
- @credentials={"client_id"=>"AZPi5hCY-0SoaLsvRSni5mignR3a9XlKL2TVKFDFV6N4m20iJTvtcy9BSR4D",
101
- "secret"=>"EDubEBAg_ZztC-_HlscxNTpWAVtFt7c0ILZW1BIaOnvrsux6IF9ywVxnHr7J",
102
- "uri_base"=>"https://api.sandbox.paypal.com", "website"=>"http://www.example.com:3000"},
103
- @website="http://www.example.com:3000", @uri_base="https://api.sandbox.paypal.com",
104
- @http=#<Net::HTTP api.sandbox.paypal.com:443 open=false>,
105
- @access_token="8PhJDJVg1mxxGUpSHj9RzzUxB0.sS0qiajx2Nxa1.Fg", @json=[], @hash=[], @status=[]>
106
- irb(main):003:0> @ok = pp.retrieve_credit_card('CARD-22T35414AU135641UKLX6GPQ')
107
- => true
108
- irb(main):004:0> puts pp.json
109
- {"id":"CARD-22T35414AU135641UKLX6GPQ","state":"ok","payer_id":"admin","type":"visa",
110
- "number":"xxxxxxxxxxxx0331","expire_month":"11","expire_year":"2018","first_name":"Betsy",
111
- "last_name":"Buyer","billing_address":{"line1":"111 First Street", "city":"Saratoga",
112
- "state":"CA","postal_code":"95070","country_code":"US"},
113
- "valid_until":"2017-02-02T00:00:00Z","create_time":"2014-02-03T18:43:10Z",
114
- "update_time":"2014-02-03T18:43:10Z",
115
- "links":[{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ","rel":"self","method":"GET"},
116
- {"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ","rel":"delete","method":"DELETE"},
117
- {"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ","rel":"patch","method":"PATCH"}]}
118
- => nil
119
- irb(main):005:0> puts pp.status
120
- 200
121
- => nil
122
- irb(main):006:0> puts pp.mode
123
- development
124
- => nil
125
- irb(main):007:0> puts pp.hash
126
- {:id=>"CARD-22T35414AU135641UKLX6GPQ", :state=>"ok", :payer_id=>"admin", :type=>"visa",
127
- :number=>"xxxxxxxxxxxx0331", :expire_month=>"11", :expire_year=>"2018", :first_name=>"Betsy",
128
- :last_name=>"Buyer", :billing_address=>{:line1=>"111 First Street", :city=>"Saratoga",
129
- :state=>"CA", :postal_code=>"95070", :country_code=>"US"},
130
- :valid_until=>"2017-02-02T00:00:00Z", :create_time=>"2014-02-03T18:43:10Z",
131
- :update_time=>"2014-02-03T18:43:10Z",
132
- :links=>[{:href=>"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", :rel=>"self", :method=>"GET"},
133
- {:href=>"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", :rel=>"delete", :method=>"DELETE"},
134
- {:href=>"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", :rel=>"patch", :method=>"PATCH"}]}
135
- => nil
136
- irb(main):008:0> puts pp.hash.pretty_inspect
137
- [
138
- {
139
- :id => "CARD-22T35414AU135641UKLX6GPQ",
140
- :state => "ok",
141
- :payer_id => "admin",
142
- :type => "visa",
143
- :number => "xxxxxxxxxxxx0331",
144
- :expire_month => "11",
145
- :expire_year => "2018",
146
- :first_name => "Betsy",
147
- :last_name => "Buyer",
148
- :billing_address => {
149
- :line1 => "111 First Street",
150
- :city => "Saratoga",
151
- :state => "CA",
152
- :postal_code => "95070",
153
- :country_code => "US"
154
- },
155
- :valid_until => "2017-02-02T00:00:00Z",
156
- :create_time => "2014-02-03T18:43:10Z",
157
- :update_time => "2014-02-03T18:43:10Z",
158
- :links => [
159
- {
160
- :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ",
161
- :rel => "self",
162
- :method => "GET"
163
- },
164
- {
165
- :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ",
166
- :rel => "delete",
167
- :method => "DELETE"
168
- },
169
- {
170
- :href => "https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ",
171
- :rel => "patch",
172
- :method => "PATCH"
173
- }
174
- ]
175
- }
176
- ]
177
- => nil
178
- irb(main):009:0> r=pp.response
179
- => #<PaypkgResponse:0x000000045fe7a0 @id="CARD-22T35414AU135641UKLX6GPQ", @state="ok", @payer_id="admin", @type="visa", @number="xxxxxxxxxxxx0331", @expire_month="11", @expire_year="2018", @first_name="Betsy", @last_name="Buyer", @billing_address=#<PaypkgResponse:0x000000045fd170 @state="CA", @line1="111 First Street", @city="Saratoga", @postal_code="95070", @country_code="US">, @valid_until="2017-02-02T00:00:00Z", @create_time="2014-02-03T18:43:10Z", @update_time="2014-02-03T18:43:10Z", @links=[#<PaypkgResponse:0x00000004603f20 @href="https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", @rel="self", @method="GET">, #<PaypkgResponse:0x00000004603728 @href="https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", @rel="delete", @method="DELETE">, #<PaypkgResponse:0x000000046030c0 @href="https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-22T35414AU135641UKLX6GPQ", @rel="patch", @method="PATCH">]>
180
- irb(main):010:0> r.billing_address.line1
181
- => "2945 Hampton Ave"
182
- irb(main):009:0>
183
-
184
-
185
- ############################
186
- ### PaypkgResponse Class ###
187
- ############################
188
-
189
- The class PaypkgResponse is used to objectize a response hash (or almost any
190
- hash object). Free free to use it separately in other projects, if it works for you.
191
-
192
- To get the PayPal response in an object format, after a successful call, use response = pp.response.
193
- If you want this, for example:
194
-
195
- payment_data = pp.hash.last
196
- @amount = payment_data[:transactions][0][:related_resources][0][:sale][:amount][:total]
197
-
198
- you would use this:
199
-
200
- payment_data = pp.response # this will convert pp.hash.last
201
- @amount = payment_data.transactions[0].related_resources[0].sale.amount.total
202
-
203
- This is provided to be more compatible with views using ActiveRecord conventions.
204
-
205
-
206
- ###############
207
- ### Caveats ###
208
- ###############
209
-
210
- Caveats:
211
- 1. This class is designed to do the most common things most people want
212
- to do, but without much fuss.
213
- 2. You can make your own calls to PayPal by creating a json data string
214
- and calling call_paypal. See the cURL commands in the documentation
215
- to see how the json should be configured. Look at the existing methods
216
- in lib/paypkg to see how they are structured. Just add yours to the
217
- lib/paypkg folder, and it will be available after the gem is
218
- reloaded. Refer to https://developer.paypal.com/webapps/developer/docs/api/
219
- for PayPal Restful calls.
220
- 3. Be sure to look at the PaypkgTestController for information on how
221
- to use the calls in your appication.
222
-
6
+ See the README.html for more details.
@@ -1,5 +1,5 @@
1
1
  require "net/http"
2
- require "yaml"
2
+ require "json"
3
3
 
4
4
  # @author Michael J. Welch, Ph.D.
5
5
 
@@ -40,7 +40,9 @@ end
40
40
 
41
41
  class Paypkg
42
42
 
43
- attr_reader :json, :hash, :status, :mode, :link
43
+ include JSON
44
+
45
+ attr_reader :json, :hash, :status, :mode, :link, :request
44
46
 
45
47
  private
46
48
 
@@ -66,6 +68,7 @@ private
66
68
  @json = []
67
69
  @hash = []
68
70
  @status = []
71
+ @request = []
69
72
  end
70
73
 
71
74
  # The set_access_token method is called before each PayPal request to validate
@@ -84,6 +87,7 @@ private
84
87
  @access_token = nil
85
88
  raise Net::HTTPServerException.new("Unable to obtain access token from PayPal", response)
86
89
  else
90
+ puts response.body.inspect
87
91
  hash = JSON.parse(response.body, :symbolize_names=>true)
88
92
  @session[:paypal_authorization][:expires_after] = Time.now+hash[:expires_in]
89
93
  @session[:paypal_authorization][:access_token] = hash[:access_token]
@@ -122,6 +126,7 @@ public
122
126
  @json = []
123
127
  @hash = []
124
128
  @status = []
129
+ @request = []
125
130
  end
126
131
  case
127
132
  when options[:method]==:delete
@@ -131,6 +136,7 @@ public
131
136
  when options[:method]==:get
132
137
  request = Net::HTTP::Get.new(endpoint)
133
138
  end
139
+ @request << data
134
140
  request.add_field("Content-Type","application/json")
135
141
  request.add_field("Authorization", "Bearer #{@access_token}")
136
142
  request.body = data.gsub("'",'"') if data
@@ -0,0 +1,14 @@
1
+ #################################
2
+ ### Retrieve Payment Resource ###
3
+ #################################
4
+
5
+ class Paypkg
6
+ # Use the payment_id to look up a payment.
7
+ # @param payment_id [String] Required.
8
+ # @return [json String] The same json string returned when
9
+ # the payment was orginally authorized.
10
+ def retrieve_payment_resource(payment_id)
11
+ call_paypal("/v1/payments/payment/#{payment_id}")
12
+ return (@status.last=='200')
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Version
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require_relative File.dirname(__FILE__) + '/lib/paypkg/version'
2
+ include Version
3
+ Gem::Specification.new do |s|
4
+ s.name = 'paypkg'
5
+ # when changing version, also change the lib/paypkg.rb
6
+ s.version = VERSION
7
+ s.date = '2014-04-22'
8
+ s.summary = 'Simple PayPal Connection for Ruby'
9
+ s.description = "This gem uses Net::HTTP to communicate with the PayPal servers. It has calls for the most common PayPal functions to simplify using PayPal in a Ruby application."
10
+ s.authors = ["Michael J. Welch, Ph.D."]
11
+ s.email = 'rubygems@czarmail.com'
12
+ s.files = Dir.glob(["paypkg.gemspec", "config/paypkg.yml", "CHANGELOG.md", "README.md", "README.html", "lib/paypkg.rb", "lib/paypkg/*", "test/*", "test/paypkg_test/*" ])
13
+ s.require_paths = ["lib"]
14
+ s.homepage = 'http://rubygems.org/gems/paypkg'
15
+ s.license = 'MIT'
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypkg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-19 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem uses Net::HTTP to communicate with the PayPal servers. It has
14
14
  calls for the most common PayPal functions to simplify using PayPal in a Ruby application.
@@ -17,29 +17,32 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - config/paypkg.yml
21
20
  - CHANGELOG.md
21
+ - README.html
22
22
  - README.md
23
+ - config/paypkg.yml
23
24
  - 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
25
  - lib/paypkg/accept-pp-payment.rb
29
- - lib/paypkg/store-credit-card.rb
30
- - lib/paypkg/retrieve-sale-transaction.rb
26
+ - lib/paypkg/accept-stored-cc-payment.rb
27
+ - lib/paypkg/accept-tendered-cc-payment.rb
28
+ - lib/paypkg/delete-credit-card.rb
29
+ - lib/paypkg/nil-empty?.rb
31
30
  - lib/paypkg/paypal-countries.rb
32
31
  - lib/paypkg/paypal-currencies.rb
33
32
  - 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
33
+ - lib/paypkg/refund-sale.rb
37
34
  - lib/paypkg/retrieve-credit-card.rb
38
- - lib/paypkg/nil-empty?.rb
39
- - test/paypkg_test_controller.rb
35
+ - lib/paypkg/retrieve-payment-resource.rb
36
+ - lib/paypkg/retrieve-refund-transaction.rb
37
+ - lib/paypkg/retrieve-sale-transaction.rb
38
+ - lib/paypkg/store-credit-card.rb
39
+ - lib/paypkg/validate-credit-card.rb
40
+ - lib/paypkg/version.rb
41
+ - paypkg.gemspec
42
+ - test/paypkg_test/approved.html.erb
40
43
  - test/paypkg_test/cancelled.html.erb
41
44
  - test/paypkg_test/test1.html.erb
42
- - test/paypkg_test/approved.html.erb
45
+ - test/paypkg_test_controller.rb
43
46
  homepage: http://rubygems.org/gems/paypkg
44
47
  licenses:
45
48
  - MIT
@@ -60,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
63
  version: '0'
61
64
  requirements: []
62
65
  rubyforge_project:
63
- rubygems_version: 2.0.7
66
+ rubygems_version: 2.2.2
64
67
  signing_key:
65
68
  specification_version: 4
66
69
  summary: Simple PayPal Connection for Ruby