paypal_adaptive 0.0.3 → 0.0.4
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.
- data/README.markdown +8 -3
- data/VERSION +1 -1
- data/lib/request.rb +2 -1
- data/lib/response.rb +9 -1
- data/paypal_adaptive.gemspec +8 -4
- data/test/data/invalid_preapproval.json +12 -0
- data/test/data/valid_preapproval.json +11 -0
- data/test/preapproval_test.rb +38 -0
- metadata +6 -2
data/README.markdown
CHANGED
@@ -3,8 +3,10 @@ This gem is a lightweight wrapper for the paypal adaptive payments API.
|
|
3
3
|
|
4
4
|
This is very much a work in progress! Use at your own risk or submit bug fixes :)
|
5
5
|
|
6
|
-
Before you need start,
|
7
|
-
It'll be invaluable for parameters and error messages.
|
6
|
+
Before you need start, read the API manual https://www.x.com/docs/DOC-1531 and check out the forums on http://x.com
|
7
|
+
It'll be invaluable for parameters and error messages. The gem keeps the request/response as hashes so you will have to
|
8
|
+
read the manual to make the proper calls. I made a few test cases for further examples at http://github.com/tc/paypal_adaptive/tree/master/test/
|
9
|
+
|
8
10
|
|
9
11
|
## HOWTO
|
10
12
|
Create paypal_adaptive.yml to your config folder:
|
@@ -60,7 +62,7 @@ Upon payment completion page, they will be redirected to http://testserver.com/p
|
|
60
62
|
They can also click cancel to go to http://testserver.com/payments/canceled_payment_request
|
61
63
|
|
62
64
|
The actual payment details will be sent to your server via "ipnNotificationUrl"
|
63
|
-
You have to create a listener to receive POST messages from paypal. I added a Rails metal template in the templates folder which handles the
|
65
|
+
You have to create a listener to receive POST messages from paypal. I added a Rails metal template in the templates folder which handles the callback.
|
64
66
|
|
65
67
|
Additionally, you can make calls to Paypal Adaptive's other APIs:
|
66
68
|
payment_details, preapproval, preapproval_details, cancel_preapproval, convert_currency, refund
|
@@ -68,6 +70,9 @@ Additionally, you can make calls to Paypal Adaptive's other APIs:
|
|
68
70
|
Input is just a Hash just like the pay method. Refer to the Paypal manual for more details.
|
69
71
|
|
70
72
|
## Changelog
|
73
|
+
0.0.4
|
74
|
+
Preapproval now returns a PaypalAdaptive::Response class. Added preapproval test cases.
|
75
|
+
|
71
76
|
0.0.3
|
72
77
|
Renamed PayRequest, PayResponse into Request, Response since other api calls use the class as well.
|
73
78
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/request.rb
CHANGED
@@ -41,7 +41,8 @@ module PaypalAdaptive
|
|
41
41
|
def preapproval(data)
|
42
42
|
raise NoDataError unless data
|
43
43
|
|
44
|
-
call_api(data, "/AdaptivePayments/Preapproval")
|
44
|
+
response_data = call_api(data, "/AdaptivePayments/Preapproval")
|
45
|
+
PaypalAdaptive::Response.new(response_data, @env)
|
45
46
|
end
|
46
47
|
|
47
48
|
def preapproval_details(data)
|
data/lib/response.rb
CHANGED
@@ -18,7 +18,15 @@ module PaypalAdaptive
|
|
18
18
|
self['error']
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
def error_message
|
23
|
+
if success?
|
24
|
+
return nil
|
25
|
+
else
|
26
|
+
self['error'].first['message'] rescue nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
22
30
|
def approve_paypal_payment_url
|
23
31
|
"#{@@paypal_base_url}/webscr?cmd=_ap-payment&paykey=#{self['payKey']}"
|
24
32
|
end
|
data/paypal_adaptive.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{paypal_adaptive}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tommy Chheng"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-29}
|
13
13
|
s.description = %q{Lightweight wrapper for Paypal's Adaptive Payments API.}
|
14
14
|
s.email = %q{tommy.chheng@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,14 +33,17 @@ Gem::Specification.new do |s|
|
|
33
33
|
"templates/paypal_ipn.rb",
|
34
34
|
"test/data/invalid_chain_pay_request.json",
|
35
35
|
"test/data/invalid_parallel_pay_request.json",
|
36
|
+
"test/data/invalid_preapproval.json",
|
36
37
|
"test/data/invalid_simple_pay_request_1.json",
|
37
38
|
"test/data/valid_chain_pay_request.json",
|
38
39
|
"test/data/valid_parallel_pay_request.json",
|
40
|
+
"test/data/valid_preapproval.json",
|
39
41
|
"test/data/valid_simple_pay_request_1.json",
|
40
42
|
"test/helper.rb",
|
41
43
|
"test/pay_request_schema_test.rb",
|
42
44
|
"test/pay_request_test.rb",
|
43
|
-
"test/payment_details_test.rb"
|
45
|
+
"test/payment_details_test.rb",
|
46
|
+
"test/preapproval_test.rb"
|
44
47
|
]
|
45
48
|
s.homepage = %q{http://github.com/tc/paypal_adaptive}
|
46
49
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -51,7 +54,8 @@ Gem::Specification.new do |s|
|
|
51
54
|
"test/helper.rb",
|
52
55
|
"test/pay_request_schema_test.rb",
|
53
56
|
"test/pay_request_test.rb",
|
54
|
-
"test/payment_details_test.rb"
|
57
|
+
"test/payment_details_test.rb",
|
58
|
+
"test/preapproval_test.rb"
|
55
59
|
]
|
56
60
|
|
57
61
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"returnUrl":"http://127.0.0.1:3000/payments/completed_payment_request",
|
3
|
+
"requestEnvelope":{"errorLanguage":"en_US"},
|
4
|
+
"currencyCode":"USD",
|
5
|
+
"cancelUrl":"http://127.0.0.1:3000/payments/canceled_payment_request",
|
6
|
+
"actionType":"PAY",
|
7
|
+
"maxTotalAmountOfAllPayments": "1500.00",
|
8
|
+
"maxNumberOfPayments":"30",
|
9
|
+
"startingDate":"2010-07-13T07sdf00.000Z",
|
10
|
+
"endingDate":"2010-12-13T07dfg0000.000Z"
|
11
|
+
}
|
12
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"returnUrl":"http://127.0.0.1:3000/payments/completed_payment_request",
|
3
|
+
"requestEnvelope":{"errorLanguage":"en_US"},
|
4
|
+
"currencyCode":"USD",
|
5
|
+
"cancelUrl":"http://127.0.0.1:3000/payments/canceled_payment_request",
|
6
|
+
"maxTotalAmountOfAllPayments": "1500.00",
|
7
|
+
"maxNumberOfPayments":"30",
|
8
|
+
"startingDate":"2010-07-13T07:00:00.000Z",
|
9
|
+
"endingDate":"2010-12-13T07:00:00.000Z"
|
10
|
+
}
|
11
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require '../lib/request'
|
3
|
+
|
4
|
+
class PreapprovalTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@preapproval_request = PaypalAdaptive::Request.new("test")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_preapproval
|
10
|
+
puts "-------"
|
11
|
+
puts "valid test"
|
12
|
+
data_filepath = "../test/data/valid_preapproval.json"
|
13
|
+
|
14
|
+
data = read_json_file(data_filepath)
|
15
|
+
pp_response = @preapproval_request.preapproval(data)
|
16
|
+
puts "preapproval code is #{pp_response['preapprovalKey']}"
|
17
|
+
|
18
|
+
assert_not_nil pp_response['preapprovalKey']
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_invalid_preapproval
|
23
|
+
puts "-------"
|
24
|
+
puts "invalid"
|
25
|
+
data_filepath = "../test/data/invalid_preapproval.json"
|
26
|
+
|
27
|
+
data = read_json_file(data_filepath)
|
28
|
+
pp_response = @preapproval_request.preapproval(data)
|
29
|
+
puts "error message is #{pp_response.error_message}"
|
30
|
+
|
31
|
+
assert_nil pp_response['preapprovalKey']
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_json_file(filepath)
|
35
|
+
File.open(filepath, "rb"){|f| JSON.parse(f.read)}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal_adaptive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy Chheng
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-29 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,14 +58,17 @@ files:
|
|
58
58
|
- templates/paypal_ipn.rb
|
59
59
|
- test/data/invalid_chain_pay_request.json
|
60
60
|
- test/data/invalid_parallel_pay_request.json
|
61
|
+
- test/data/invalid_preapproval.json
|
61
62
|
- test/data/invalid_simple_pay_request_1.json
|
62
63
|
- test/data/valid_chain_pay_request.json
|
63
64
|
- test/data/valid_parallel_pay_request.json
|
65
|
+
- test/data/valid_preapproval.json
|
64
66
|
- test/data/valid_simple_pay_request_1.json
|
65
67
|
- test/helper.rb
|
66
68
|
- test/pay_request_schema_test.rb
|
67
69
|
- test/pay_request_test.rb
|
68
70
|
- test/payment_details_test.rb
|
71
|
+
- test/preapproval_test.rb
|
69
72
|
has_rdoc: true
|
70
73
|
homepage: http://github.com/tc/paypal_adaptive
|
71
74
|
licenses: []
|
@@ -99,3 +102,4 @@ test_files:
|
|
99
102
|
- test/pay_request_schema_test.rb
|
100
103
|
- test/pay_request_test.rb
|
101
104
|
- test/payment_details_test.rb
|
105
|
+
- test/preapproval_test.rb
|