paypkg 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +9 -0
- data/README.html +3 -3
- data/README.md +2 -0
- data/lib/paypkg.rb +4 -3
- data/lib/paypkg/version.rb +2 -2
- data/paypkg.gemspec +1 -1
- data/test/app.rb +154 -0
- data/test/config.ru +20 -0
- data/test/start +2 -0
- metadata +9 -10
- data/test/paypkg_test/approved.html.erb +0 -10
- data/test/paypkg_test/cancelled.html.erb +0 -2
- data/test/paypkg_test/test1.html.erb +0 -15
- data/test/paypkg_test_controller.rb +0 -229
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ca6091ca0664adf590e09d236bc64d96d12ad4d7e90940e952e6be735e278f6
|
4
|
+
data.tar.gz: b5db87c1edd2d7213ce177439190702b7a229b4f5ce71de0ca2155d870bea024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92de94962d3e6dca7bc380f6f880773b698f950338a93d83573274fc7a529c2f08e9865587b6f2c9b2143789789ce7daf934464ca0bc8d61d5a6aedd2f1a78cf
|
7
|
+
data.tar.gz: 56331a58c96f5655aec8f036a2ce20960289175a9bde5c4a8e31adf122cca909c6b8d33d9bbd26ddd0631034fb148893671a7f380317d8789da54fa874b09c4a
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
+
0.1.7
|
2
|
+
-----
|
3
|
+
* Changed the initialize method to pass the database extension (development, test, production), and the database (project) path name. This change was necessary in order to allow this gem to operate without Ruby on Rails.
|
4
|
+
|
5
|
+
Before: pp = Paypkg.new(session)
|
6
|
+
|
7
|
+
After: pp = Paypkg.new(session, Rails.env, Rails.root.to_path)
|
8
|
+
|
1
9
|
0.1.6
|
2
10
|
-----
|
3
11
|
* Changed the spelling of Polish currency to its US-ASCII equivalent to avoid getting the error 'invalid multibyte char' during require.
|
4
12
|
|
5
13
|
0.1.5
|
14
|
+
-----
|
6
15
|
* Moved the release date into the same file as the version so as not to forget to change it along with the version number.
|
7
16
|
|
8
17
|
0.1.4
|
data/README.html
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
<!-------------------------------------------------------------------->
|
23
23
|
<h3>Copyright</h3>
|
24
24
|
|
25
|
-
<p>Copyright (©) 2014, Michael J. Welch, Ph.D. and Contributors. All Rights Reserved.</p>
|
25
|
+
<p>Copyright (©) 2014-2018, Michael J. Welch, Ph.D. and Contributors. All Rights Reserved.</p>
|
26
26
|
|
27
27
|
<p>Email: rubygems@czarmail.com</p>
|
28
28
|
|
@@ -52,7 +52,7 @@ development:~$ gem install pretty_inspect</pre>
|
|
52
52
|
<p>Follow the steps below. First, create a rails project. In this case, I'm using bundler. You probably are too..</p>
|
53
53
|
|
54
54
|
<pre>development:~$ rails new paypkg-test -d mysql
|
55
|
-
create
|
55
|
+
create
|
56
56
|
create README.rdoc
|
57
57
|
...
|
58
58
|
create vendor/assets/stylesheets/.keep
|
@@ -108,7 +108,7 @@ development:~/paypkg-test$ </pre>
|
|
108
108
|
get 'paypkg_test/approved' => 'paypkg_test#approved'
|
109
109
|
get 'paypkg_test/cancelled' => 'paypkg_test#cancelled'
|
110
110
|
end</pre>
|
111
|
-
|
111
|
+
|
112
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
113
|
|
114
114
|
<p>Copy the test page and view folder. Your gems might be in a different place, so beware!</p>
|
data/README.md
CHANGED
data/lib/paypkg.rb
CHANGED
@@ -49,14 +49,15 @@ private
|
|
49
49
|
# The initialize method reads the config file, calls PayPal for an access_token,
|
50
50
|
# stores the access_token in the session, and initializes some variables
|
51
51
|
# @param session [Hash] The session object from your ApplicationController subclass
|
52
|
-
def initialize(session=nil)
|
52
|
+
def initialize(session=nil, env=nil, path=nil)
|
53
|
+
env = 'development' if env.nil?
|
54
|
+
path = '.' if path.nil?
|
53
55
|
@session = if session then session else {} end
|
54
56
|
@session[:paypal_authorization] ||= {}
|
55
57
|
@session[:paypal_authorization][:expires_after] ||= Time.now-6
|
56
58
|
@session[:paypal_authorization][:access_token] ||= ""
|
57
|
-
env = Rails.env
|
58
59
|
@mode = env.to_sym
|
59
|
-
@credentials = YAML.load_file("#{
|
60
|
+
@credentials = YAML.load_file("#{path}/config/paypkg.yml")[env]
|
60
61
|
@website = @credentials['website']
|
61
62
|
@uri_base = @credentials['uri_base']
|
62
63
|
uri = URI.parse(@uri_base)
|
data/lib/paypkg/version.rb
CHANGED
data/paypkg.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.summary = 'Simple PayPal Connection for Ruby'
|
8
8
|
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. I developed this package as a way to call PayPal's REST API with greater transparancy than the paypal-sdk-rest gem has, making development easier. This package can be easily extended by simply adding additional methods (as files) to the lib/paypkg folder. Contributions welcome."
|
9
9
|
s.authors = ["Michael J. Welch, Ph.D."]
|
10
|
-
s.email = '
|
10
|
+
s.email = 'mjwelchphd@gmail.com'
|
11
11
|
s.files = Dir.glob(["paypkg.gemspec", "config/paypkg.yml", "CHANGELOG.md", "README.md", "README.html", "lib/paypkg.rb", "lib/paypkg/*", "test/*", "test/paypkg_test/*" ])
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.homepage = 'http://rubygems.org/gems/paypkg'
|
data/test/app.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'rack/session/pool'
|
5
|
+
require 'sequel'
|
6
|
+
|
7
|
+
require 'pretty_inspect'
|
8
|
+
|
9
|
+
Log = File::open('log/app.log','a') # use the same log as Rack uses
|
10
|
+
|
11
|
+
Sequel.extension :inflector # http://sequel.jeremyevans.net/rdoc-plugins/classes/String.html
|
12
|
+
# camelize, humanize, pluralize, singularize, tableize, titleize, to_date, to_datetime, to_time, underscore
|
13
|
+
|
14
|
+
class BigDecimal
|
15
|
+
def inspect
|
16
|
+
"%0.2f"%self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Application
|
21
|
+
attr_accessor :path, :routing_map, :env
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@routing_map = {} # the route=>controller map
|
25
|
+
@path = File.absolute_path('.') # used to do 'absolute' requires
|
26
|
+
|
27
|
+
@env = ENV['MODE'] # 'development' or 'production'
|
28
|
+
$app = self # just a pointer to the application object
|
29
|
+
# require "#{$app.path}/models/init" # do this first: scaffolding needs DB
|
30
|
+
require "#{$app.path}/helpers/init" # load all the helpers
|
31
|
+
require "#{$app.path}/controllers/init" # get all the controllers and map them
|
32
|
+
end
|
33
|
+
|
34
|
+
def call(env)
|
35
|
+
# save the request, and create a response
|
36
|
+
request = Rack::Request.new(env)
|
37
|
+
response = Rack::Response.new
|
38
|
+
|
39
|
+
# search the map created when the controllers were loaded
|
40
|
+
parts = request.path_info.downcase.split('/')
|
41
|
+
parts.delete_at(0) if parts[0]==""
|
42
|
+
|
43
|
+
# calculate the routing for this request
|
44
|
+
|
45
|
+
#puts "--> *10* parts.size=>#{parts.size} parts=>#{parts.inspect}"
|
46
|
+
case
|
47
|
+
when parts.size==0
|
48
|
+
controller = MainController
|
49
|
+
method_name = 'index'
|
50
|
+
when parts.size==1
|
51
|
+
controller = $app.routing_map["/#{parts[0]}"]
|
52
|
+
if controller
|
53
|
+
method_name = 'index'
|
54
|
+
else
|
55
|
+
controller = MainController
|
56
|
+
method_name = parts[0]
|
57
|
+
end
|
58
|
+
else
|
59
|
+
method_name = parts.delete_at(-1)
|
60
|
+
controller = $app.routing_map["/#{parts.join('/')}"]
|
61
|
+
end
|
62
|
+
method = method_name.to_sym
|
63
|
+
#puts "--> *11* controller=>#{controller.inspect}"
|
64
|
+
#puts "--> *12* method_name=>#{method_name.inspect}"
|
65
|
+
|
66
|
+
# log the routing on the console
|
67
|
+
msg = "Routing: request.path_info=>#{request.path_info.inspect}, (#{parts.size}) part(s)=>#{parts.inspect}, method_name=>#{method_name.inspect}, controller=>#{controller.inspect}, method=>#{method.inspect}"
|
68
|
+
Log.write("#{msg}\n")
|
69
|
+
Log.flush
|
70
|
+
|
71
|
+
# try to route it
|
72
|
+
if controller
|
73
|
+
# we found a valid controller, so get an instance
|
74
|
+
obj = controller.new
|
75
|
+
begin
|
76
|
+
file, line = obj.method(method).source_location
|
77
|
+
# reload controller in 'dev' mode
|
78
|
+
if @env=='development' && File::exists?(file)
|
79
|
+
Log.write("Reloading #{file.inspect} in 'development' mode.\n")
|
80
|
+
load file
|
81
|
+
end
|
82
|
+
|
83
|
+
# the method exists, so call it
|
84
|
+
request[:route] = "/#{parts.join('/')}"
|
85
|
+
if !request.session.has_key?(:home_url)
|
86
|
+
request.session.delete(:id)
|
87
|
+
request.session.delete(:username)
|
88
|
+
request.session.delete(:first)
|
89
|
+
request.session[:home_url] = '/'
|
90
|
+
end
|
91
|
+
obj.request = request
|
92
|
+
obj.response = response
|
93
|
+
obj.params = {}
|
94
|
+
request.params.each { |k,v| obj.params[k.to_sym] = v }
|
95
|
+
|
96
|
+
# check the authorization here -- I had it in the Controller class, but
|
97
|
+
# the scaffolding can't access the session variable, so I had to move it here --
|
98
|
+
# #method raises a NameError (undocumented) and also returns true false
|
99
|
+
begin
|
100
|
+
authorized = obj.authorize(method)
|
101
|
+
rescue NameError=>e
|
102
|
+
if request.session[:id].nil?
|
103
|
+
authorized = false
|
104
|
+
else
|
105
|
+
p = Person.select(:role).where(:id=>request.session[:id]).first
|
106
|
+
c = Role.select(:id).where(:role_name=>p.role, :controller_name=>obj.class.name)
|
107
|
+
authorized = !c.first.nil?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if authorized
|
112
|
+
begin
|
113
|
+
# run the 'before', if any
|
114
|
+
obj.before(request.path_info, controller, method)
|
115
|
+
# run the method and get a response
|
116
|
+
out = obj.send(method)
|
117
|
+
response.write(out)
|
118
|
+
# run the 'after', if any
|
119
|
+
obj.after(request.path_info, controller, method, out)
|
120
|
+
rescue => e
|
121
|
+
# this is the "rescue of last resort"
|
122
|
+
Log.write("*** Rescue of Last Resort ***\n")
|
123
|
+
Log.write(e.inspect)
|
124
|
+
e.backtrace.each { |line| Log.write("#{line}\n") }
|
125
|
+
Log.flush
|
126
|
+
response.write("Rescue of last resort: #{e} (see log)")
|
127
|
+
response.write(e.inspect) # TODO!
|
128
|
+
e.backtrace.each { |line| response.write("#{line}\n") }
|
129
|
+
end
|
130
|
+
return response.finish
|
131
|
+
else
|
132
|
+
message = "Sorry, but you're not authorized to make that request"
|
133
|
+
end
|
134
|
+
rescue NameError => e
|
135
|
+
puts "--> *20* e=>#{e.inspect}"
|
136
|
+
e.backtrace.each { |line| puts("#{line}\n") }
|
137
|
+
message = "There is no method <i>#{method}</i> for controller <i>#{obj.class.name}</i>"
|
138
|
+
message << "\n"
|
139
|
+
e.backtrace.each { |line| message << "#{line}\n" }
|
140
|
+
end
|
141
|
+
else
|
142
|
+
message = "There is no controller for that request"
|
143
|
+
end
|
144
|
+
|
145
|
+
# return the error message
|
146
|
+
obj = MainController.new
|
147
|
+
obj.request = request
|
148
|
+
obj.response = response
|
149
|
+
response.write(obj.send(:not_authorized, "<body><h3>#{message}.</h3></body>"))
|
150
|
+
response.status = 404
|
151
|
+
response.finish
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
data/test/config.ru
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# TO RUN:
|
2
|
+
# rackup --port 3000 --host ekgreaders.com
|
3
|
+
|
4
|
+
require 'rack'
|
5
|
+
require './app.rb'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
application = Application.new
|
9
|
+
logger = Logger.new('log/app.log','weekly')
|
10
|
+
|
11
|
+
use Rack::CommonLogger, logger
|
12
|
+
use Rack::Static, :urls => ["/css", "/images", "/javascript"], :root => "public"
|
13
|
+
use Rack::Session::Cookie, :key=>'rack.session',
|
14
|
+
:domain => 'ekgreaders.com',
|
15
|
+
:expire_after => 2592000,
|
16
|
+
:secret => 'Cocosaurus Rex',
|
17
|
+
:old_secret => 'Cocosaurus Rex'
|
18
|
+
use Rack::Session::Pool, :domain => 'ekgreaders.com',
|
19
|
+
:expire_after => 2592000
|
20
|
+
run application
|
data/test/start
ADDED
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.
|
4
|
+
version: 0.1.7
|
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:
|
11
|
+
date: 2018-05-16 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.
|
@@ -16,7 +16,7 @@ description: This gem uses Net::HTTP to communicate with the PayPal servers. It
|
|
16
16
|
than the paypal-sdk-rest gem has, making development easier. This package can be
|
17
17
|
easily extended by simply adding additional methods (as files) to the lib/paypkg
|
18
18
|
folder. Contributions welcome.
|
19
|
-
email:
|
19
|
+
email: mjwelchphd@gmail.com
|
20
20
|
executables: []
|
21
21
|
extensions: []
|
22
22
|
extra_rdoc_files: []
|
@@ -43,10 +43,9 @@ files:
|
|
43
43
|
- lib/paypkg/validate-credit-card.rb
|
44
44
|
- lib/paypkg/version.rb
|
45
45
|
- paypkg.gemspec
|
46
|
-
- test/
|
47
|
-
- test/
|
48
|
-
- test/
|
49
|
-
- test/paypkg_test_controller.rb
|
46
|
+
- test/app.rb
|
47
|
+
- test/config.ru
|
48
|
+
- test/start
|
50
49
|
homepage: http://rubygems.org/gems/paypkg
|
51
50
|
licenses:
|
52
51
|
- MIT
|
@@ -57,17 +56,17 @@ require_paths:
|
|
57
56
|
- lib
|
58
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
|
-
- -
|
59
|
+
- - ">="
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '0'
|
63
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
63
|
requirements:
|
65
|
-
- -
|
64
|
+
- - ">="
|
66
65
|
- !ruby/object:Gem::Version
|
67
66
|
version: '0'
|
68
67
|
requirements: []
|
69
68
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.7.6
|
71
70
|
signing_key:
|
72
71
|
specification_version: 4
|
73
72
|
summary: Simple PayPal Connection for Ruby
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<h1>Paypkg -- Buyer Approved</h1>
|
2
|
-
<p>The buyer selected to approve the purchase.</p>
|
3
|
-
<br/>
|
4
|
-
<% if @note %>
|
5
|
-
<p>Response: <%= @note %></p>
|
6
|
-
<% else %>
|
7
|
-
<p>payment ID: <%= @payment_id %></p>
|
8
|
-
<p>Sale ID: <%= @sale_id %></p>
|
9
|
-
<p>Amount: <%= @amount %></p>
|
10
|
-
<% end %>
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<style>
|
2
|
-
red: { color: red; }
|
3
|
-
</style>
|
4
|
-
|
5
|
-
<h1>Paypkg Test1</h1>
|
6
|
-
|
7
|
-
<pre>
|
8
|
-
<% @notes.each do |note| %>
|
9
|
-
<% if note.index(' NOT ') || note.index(' Failed') %>
|
10
|
-
<red><%= note %></red>
|
11
|
-
<% else %>
|
12
|
-
<%= note %>
|
13
|
-
<% end %>
|
14
|
-
<% end %>
|
15
|
-
</pre>
|
@@ -1,229 +0,0 @@
|
|
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
|