paypal-sdk-core 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paypal-sdk-core.rb +1 -0
- data/lib/paypal-sdk/core/api/ipn.rb +71 -0
- data/lib/paypal-sdk/core/config.rb +2 -1
- data/lib/paypal-sdk/core/version.rb +1 -1
- data/spec/config/sample_data.yml +3 -0
- data/spec/core/api/ipn_spec.rb +39 -0
- data/spec/log/test.log +60 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/sample_data.rb +5 -0
- metadata +11 -4
data/lib/paypal-sdk-core.rb
CHANGED
@@ -12,6 +12,7 @@ module PayPal
|
|
12
12
|
autoload :Base, "paypal-sdk/core/api/base"
|
13
13
|
autoload :Merchant, "paypal-sdk/core/api/merchant"
|
14
14
|
autoload :Platform, "paypal-sdk/core/api/platform"
|
15
|
+
autoload :IPN, "paypal-sdk/core/api/ipn"
|
15
16
|
|
16
17
|
module DataTypes
|
17
18
|
autoload :Base, "paypal-sdk/core/api/data_types/base"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module PayPal
|
4
|
+
module SDK
|
5
|
+
module Core
|
6
|
+
module API
|
7
|
+
module IPN
|
8
|
+
|
9
|
+
END_POINTS = {
|
10
|
+
:sandbox => "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr",
|
11
|
+
:live => "https://ipnpb.paypal.com/cgi-bin/webscr"
|
12
|
+
}
|
13
|
+
VERIFIED = "VERIFIED"
|
14
|
+
INVALID = "INVALID"
|
15
|
+
|
16
|
+
class Message
|
17
|
+
include PayPal::SDK::Core::Configuration
|
18
|
+
|
19
|
+
attr_accessor :message
|
20
|
+
|
21
|
+
def initialize(message, env = nil, options = {})
|
22
|
+
@message = message
|
23
|
+
set_config(env, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Fetch end point
|
27
|
+
def ipn_end_point
|
28
|
+
config.ipn_end_point || default_ipn_end_point
|
29
|
+
end
|
30
|
+
|
31
|
+
# Default IPN end point
|
32
|
+
def default_ipn_end_point
|
33
|
+
end_point = END_POINTS[(config.mode || :sandbox).to_sym] rescue nil
|
34
|
+
end_point || END_POINTS[:sandbox]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Request IPN service for validating the content
|
38
|
+
# === Return
|
39
|
+
# return http response object
|
40
|
+
def request
|
41
|
+
uri = URI(ipn_end_point)
|
42
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
43
|
+
http.use_ssl = true
|
44
|
+
http.ca_file = config.ca_file if config.ca_file
|
45
|
+
query_string = "cmd=_notify-validate&#{message}"
|
46
|
+
http.post(uri.path, query_string)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Validate the given content
|
50
|
+
# === Return
|
51
|
+
# return true or false
|
52
|
+
def valid?
|
53
|
+
request.body == VERIFIED
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class << self
|
58
|
+
def valid?(*args)
|
59
|
+
Message.new(*args).valid?
|
60
|
+
end
|
61
|
+
|
62
|
+
def request(*args)
|
63
|
+
Message.new(*args).request
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -51,7 +51,8 @@ module PayPal::SDK::Core
|
|
51
51
|
:token, :token_secret, :subject,
|
52
52
|
:http_timeout, :http_retry, :http_proxy, :ca_file,
|
53
53
|
:device_ipaddress, :sandbox_email_address,
|
54
|
-
:mode, :end_point, :merchant_end_point, :platform_end_point, :
|
54
|
+
:mode, :end_point, :merchant_end_point, :platform_end_point, :ipn_end_point,
|
55
|
+
:redirect_url, :dev_central_url,
|
55
56
|
:logfile
|
56
57
|
|
57
58
|
# Create Config object
|
@@ -0,0 +1,3 @@
|
|
1
|
+
ipn:
|
2
|
+
valid_message: item_number=&residence_country=US&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXi5tzp0u2U-8QDyy.oC2A1Dhx04&address_country=United+States&address_city=San+Jose&address_status=unconfirmed&business=platfo_1255077030_biz%40gmail.com&payment_status=Pending&transaction_subject=&protection_eligibility=Ineligible&shipping=0.00&payer_id=934EKX9W68RRU&first_name=John&mc_fee=0.38&txn_id=5AL16697HX185734U&quantity=1&receiver_email=platfo_1255077030_biz%40gmail.com¬ify_version=3.7&txn_type=web_accept&mc_gross=1.00&payer_status=unverified&mc_currency=USD&test_ipn=1&custom=&payment_date=01%3A48%3A31+Dec+04%2C+2012+PST&payment_fee=0.38&charset=windows-1252&address_country_code=US&payment_gross=1.00&address_zip=95131&ipn_track_id=af0f53159f21e&address_state=CA&receipt_id=4050-1771-4106-3070&pending_reason=paymentreview&tax=0.00&handling_amount=0.00&item_name=&address_name=John+Doe&last_name=Doe&payment_type=instant&receiver_id=HZH2W8NPXUE5W&address_street=1+Main+St
|
3
|
+
invalid_message: invalid=invalid
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PayPal::SDK::Core::API::IPN do
|
4
|
+
|
5
|
+
IPN = PayPal::SDK::Core::API::IPN
|
6
|
+
|
7
|
+
describe "Configuration" do
|
8
|
+
it "set IPN end_point" do
|
9
|
+
ipn_validate_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"
|
10
|
+
message = IPN::Message.new(samples["ipn"]["valid_message"], :ipn_end_point => ipn_validate_url )
|
11
|
+
message.config.ipn_end_point.should eql ipn_validate_url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Valid" do
|
16
|
+
it "request" do
|
17
|
+
response = IPN.request(samples["ipn"]["valid_message"])
|
18
|
+
response.body.should eql IPN::VERIFIED
|
19
|
+
end
|
20
|
+
|
21
|
+
it "valid?" do
|
22
|
+
response = IPN.valid?(samples["ipn"]["valid_message"])
|
23
|
+
response.should be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Invalid" do
|
28
|
+
it "request" do
|
29
|
+
response = IPN.request(samples["ipn"]["invalid_message"])
|
30
|
+
response.body.should eql IPN::INVALID
|
31
|
+
end
|
32
|
+
|
33
|
+
it "valid?" do
|
34
|
+
response = IPN.valid?(samples["ipn"]["invalid_message"])
|
35
|
+
response.should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/log/test.log
CHANGED
@@ -82,3 +82,63 @@ I, [2012-12-11T12:32:19.329705 #6859] INFO -- : [1.319] Request: ConvertCurrenc
|
|
82
82
|
I, [2012-12-11T12:32:50.074458 #6859] INFO -- : [30.743] Request: ConvertCurrency
|
83
83
|
I, [2012-12-11T12:32:51.847657 #6859] INFO -- : [1.772] Request: InvalidAction
|
84
84
|
I, [2012-12-11T12:32:53.445379 #6859] INFO -- : [1.596] Request: ConvertCurrency
|
85
|
+
I, [2012-12-12T15:42:10.097532 #4040] INFO -- : [5.706] Request: TransactionSearch
|
86
|
+
I, [2012-12-12T15:42:13.126581 #4040] INFO -- : [3.012] Request: TransactionSearch
|
87
|
+
I, [2012-12-12T15:42:15.537397 #4040] INFO -- : [2.390] Request: TransactionSearch
|
88
|
+
I, [2012-12-12T15:42:17.875409 #4040] INFO -- : [2.319] Request: TransactionSearch
|
89
|
+
I, [2012-12-12T15:42:20.267079 #4040] INFO -- : [2.385] Request: TransactionSearch
|
90
|
+
I, [2012-12-12T15:42:21.168100 #4040] INFO -- : [0.898] Request: TransactionSearch
|
91
|
+
I, [2012-12-12T15:42:23.148098 #4040] INFO -- : [1.976] Request: TransactionSearch
|
92
|
+
I, [2012-12-12T15:42:25.398191 #4040] INFO -- : [2.247] Request: InvalidAction
|
93
|
+
I, [2012-12-12T15:42:27.407999 #4040] INFO -- : [2.007] Request: TransactionSearch
|
94
|
+
I, [2012-12-12T15:42:29.498555 #4040] INFO -- : [2.089] Request: ConvertCurrency
|
95
|
+
I, [2012-12-12T15:42:31.157382 #4040] INFO -- : [1.657] Request: ConvertCurrency
|
96
|
+
I, [2012-12-12T15:42:32.601904 #4040] INFO -- : [1.442] Request: CreateInvoice
|
97
|
+
I, [2012-12-12T15:42:34.299088 #4040] INFO -- : [1.695] Request: ConvertCurrency
|
98
|
+
I, [2012-12-12T15:42:35.697230 #4040] INFO -- : [1.397] Request: ConvertCurrency
|
99
|
+
I, [2012-12-12T15:42:37.027075 #4040] INFO -- : [1.328] Request: ConvertCurrency
|
100
|
+
I, [2012-12-12T15:42:37.257037 #4040] INFO -- : [0.229] Request: ConvertCurrency
|
101
|
+
I, [2012-12-12T15:42:38.812104 #4040] INFO -- : [1.554] Request: ConvertCurrency
|
102
|
+
I, [2012-12-12T15:43:09.574416 #4040] INFO -- : [30.761] Request: ConvertCurrency
|
103
|
+
I, [2012-12-12T15:43:10.898431 #4040] INFO -- : [1.323] Request: InvalidAction
|
104
|
+
I, [2012-12-12T15:43:12.496711 #4040] INFO -- : [1.597] Request: ConvertCurrency
|
105
|
+
I, [2012-12-13T14:01:55.245105 #6375] INFO -- : [2.674] Request: TransactionSearch
|
106
|
+
I, [2012-12-13T14:01:58.422731 #6375] INFO -- : [3.156] Request: TransactionSearch
|
107
|
+
I, [2012-12-13T14:02:00.184799 #6375] INFO -- : [1.731] Request: TransactionSearch
|
108
|
+
I, [2012-12-13T14:02:01.870172 #6375] INFO -- : [1.665] Request: TransactionSearch
|
109
|
+
I, [2012-12-13T14:02:03.612103 #6375] INFO -- : [1.739] Request: TransactionSearch
|
110
|
+
I, [2012-12-13T14:02:03.847798 #6375] INFO -- : [0.232] Request: TransactionSearch
|
111
|
+
I, [2012-12-13T14:02:05.609705 #6375] INFO -- : [1.758] Request: TransactionSearch
|
112
|
+
I, [2012-12-13T14:02:06.964165 #6375] INFO -- : [1.352] Request: InvalidAction
|
113
|
+
I, [2012-12-13T14:02:08.891713 #6375] INFO -- : [1.924] Request: TransactionSearch
|
114
|
+
I, [2012-12-13T14:02:10.562697 #6375] INFO -- : [1.669] Request: ConvertCurrency
|
115
|
+
I, [2012-12-13T14:02:12.262162 #6375] INFO -- : [1.698] Request: ConvertCurrency
|
116
|
+
I, [2012-12-13T14:02:13.687827 #6375] INFO -- : [1.423] Request: CreateInvoice
|
117
|
+
I, [2012-12-13T14:02:15.546968 #6375] INFO -- : [1.857] Request: ConvertCurrency
|
118
|
+
I, [2012-12-13T14:02:16.939778 #6375] INFO -- : [1.391] Request: ConvertCurrency
|
119
|
+
I, [2012-12-13T14:02:18.274281 #6375] INFO -- : [1.332] Request: ConvertCurrency
|
120
|
+
I, [2012-12-13T14:02:18.505326 #6375] INFO -- : [0.230] Request: ConvertCurrency
|
121
|
+
I, [2012-12-13T14:02:20.060557 #6375] INFO -- : [1.554] Request: ConvertCurrency
|
122
|
+
I, [2012-12-13T14:02:50.830238 #6375] INFO -- : [30.768] Request: ConvertCurrency
|
123
|
+
I, [2012-12-13T14:02:52.160641 #6375] INFO -- : [1.328] Request: InvalidAction
|
124
|
+
I, [2012-12-13T14:02:53.749537 #6375] INFO -- : [1.588] Request: ConvertCurrency
|
125
|
+
I, [2012-12-13T14:08:52.771110 #6666] INFO -- : [2.868] Request: TransactionSearch
|
126
|
+
I, [2012-12-13T14:08:55.383219 #6666] INFO -- : [2.609] Request: TransactionSearch
|
127
|
+
I, [2012-12-13T14:08:57.032401 #6666] INFO -- : [1.628] Request: TransactionSearch
|
128
|
+
I, [2012-12-13T14:08:58.736146 #6666] INFO -- : [1.661] Request: TransactionSearch
|
129
|
+
I, [2012-12-13T14:09:00.475631 #6666] INFO -- : [1.737] Request: TransactionSearch
|
130
|
+
I, [2012-12-13T14:09:00.712815 #6666] INFO -- : [0.234] Request: TransactionSearch
|
131
|
+
I, [2012-12-13T14:09:02.484585 #6666] INFO -- : [1.770] Request: TransactionSearch
|
132
|
+
I, [2012-12-13T14:09:03.837166 #6666] INFO -- : [1.350] Request: InvalidAction
|
133
|
+
I, [2012-12-13T14:09:05.518594 #6666] INFO -- : [1.679] Request: TransactionSearch
|
134
|
+
I, [2012-12-13T14:09:07.170847 #6666] INFO -- : [1.651] Request: ConvertCurrency
|
135
|
+
I, [2012-12-13T14:09:08.835684 #6666] INFO -- : [1.663] Request: ConvertCurrency
|
136
|
+
I, [2012-12-13T14:09:10.236225 #6666] INFO -- : [1.399] Request: CreateInvoice
|
137
|
+
I, [2012-12-13T14:09:11.917710 #6666] INFO -- : [1.680] Request: ConvertCurrency
|
138
|
+
I, [2012-12-13T14:09:13.319314 #6666] INFO -- : [1.400] Request: ConvertCurrency
|
139
|
+
I, [2012-12-13T14:09:14.639341 #6666] INFO -- : [1.319] Request: ConvertCurrency
|
140
|
+
I, [2012-12-13T14:09:14.871986 #6666] INFO -- : [0.231] Request: ConvertCurrency
|
141
|
+
I, [2012-12-13T14:09:16.194203 #6666] INFO -- : [1.321] Request: ConvertCurrency
|
142
|
+
I, [2012-12-13T14:09:46.960190 #6666] INFO -- : [30.765] Request: ConvertCurrency
|
143
|
+
I, [2012-12-13T14:09:48.288044 #6666] INFO -- : [1.326] Request: InvalidAction
|
144
|
+
I, [2012-12-13T14:09:49.883667 #6666] INFO -- : [1.594] Request: ConvertCurrency
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal-sdk-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xml-simple
|
@@ -36,13 +36,16 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- spec/core/api/platform_spec.rb
|
38
38
|
- spec/core/api/data_type_spec.rb
|
39
|
+
- spec/core/api/ipn_spec.rb
|
39
40
|
- spec/core/api/merchant_spec.rb
|
40
41
|
- spec/core/config_spec.rb
|
41
42
|
- spec/core/logging_spec.rb
|
43
|
+
- spec/support/sample_data.rb
|
42
44
|
- spec/log/test.log
|
43
45
|
- spec/spec_helper.rb
|
44
46
|
- spec/config/paypal.yml
|
45
47
|
- spec/config/cert_key.pem
|
48
|
+
- spec/config/sample_data.yml
|
46
49
|
- lib/paypal-sdk-core.rb
|
47
50
|
- lib/generators/paypal/sdk/USAGE
|
48
51
|
- lib/generators/paypal/sdk/templates/paypal.yml
|
@@ -50,6 +53,7 @@ files:
|
|
50
53
|
- lib/generators/paypal/sdk/install_generator.rb
|
51
54
|
- lib/paypal-sdk/core/util/oauth_signature.rb
|
52
55
|
- lib/paypal-sdk/core/api/merchant.rb
|
56
|
+
- lib/paypal-sdk/core/api/ipn.rb
|
53
57
|
- lib/paypal-sdk/core/api/platform.rb
|
54
58
|
- lib/paypal-sdk/core/api/data_types/simple_types.rb
|
55
59
|
- lib/paypal-sdk/core/api/data_types/enum.rb
|
@@ -81,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
85
|
version: '0'
|
82
86
|
segments:
|
83
87
|
- 0
|
84
|
-
hash:
|
88
|
+
hash: 1022374001
|
85
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
90
|
none: false
|
87
91
|
requirements:
|
@@ -90,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
94
|
version: '0'
|
91
95
|
segments:
|
92
96
|
- 0
|
93
|
-
hash:
|
97
|
+
hash: 1022374001
|
94
98
|
requirements: []
|
95
99
|
rubyforge_project:
|
96
100
|
rubygems_version: 1.8.24
|
@@ -100,10 +104,13 @@ summary: Core library for PayPal ruby SDK
|
|
100
104
|
test_files:
|
101
105
|
- spec/core/api/platform_spec.rb
|
102
106
|
- spec/core/api/data_type_spec.rb
|
107
|
+
- spec/core/api/ipn_spec.rb
|
103
108
|
- spec/core/api/merchant_spec.rb
|
104
109
|
- spec/core/config_spec.rb
|
105
110
|
- spec/core/logging_spec.rb
|
111
|
+
- spec/support/sample_data.rb
|
106
112
|
- spec/log/test.log
|
107
113
|
- spec/spec_helper.rb
|
108
114
|
- spec/config/paypal.yml
|
109
115
|
- spec/config/cert_key.pem
|
116
|
+
- spec/config/sample_data.yml
|