paypal-brazil 3.0.2

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.
@@ -0,0 +1,19 @@
1
+ module Paypal
2
+ module Helpers
3
+ module Rails
4
+ # Convenience helper. Can replace <%= form_tag Paypal::Notification.ipn_url %>
5
+ # takes optional url parameter, default is Paypal::Notification.ipn_url
6
+ def paypal_form_tag(url = Paypal::Config.ipn_url, options = {})
7
+ form_tag(url, options)
8
+ end
9
+
10
+ def paypal_form_tag(url = Paypal::Config.ipn_url, options = {}, &block)
11
+ if block
12
+ concat(form_tag(url, options)+capture(&block)+"</form>", block.binding)
13
+ else
14
+ form_tag(url, options)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,188 @@
1
+ require 'rack'
2
+ require 'net/http'
3
+
4
+ module Paypal
5
+ class NoDataError < StandardError; end
6
+
7
+ # Parser and handler for incoming Instant payment notifications from paypal.
8
+ # The Example shows a typical handler in a rails application. Note that this
9
+ # is an example, please read the Paypal API documentation for all the details
10
+ # on creating a safe payment controller.
11
+ #
12
+ # Example (Sinatra)
13
+ # def raw_post
14
+ # request.env["rack.input"].read
15
+ # end
16
+ #
17
+ # post "/paypal_ipn" do
18
+ # notify = Paypal::Notification.new(raw_post)
19
+ #
20
+ # order = Order.find(notify.item_id)
21
+ #
22
+ # if notify.acknowledge
23
+ # begin
24
+ # if notify.complete? and order.total == notify.amount and notify.business == 'sales@myshop.com'
25
+ # order.status = 'success'
26
+ #
27
+ # shop.ship(order)
28
+ # else
29
+ # logger.error("Failed to verify Paypal's notification, please investigate")
30
+ # end
31
+ #
32
+ # rescue => e
33
+ # order.status = 'failed'
34
+ # raise
35
+ # ensure
36
+ # order.save
37
+ # end
38
+ # end
39
+ #
40
+ # nil
41
+ # end
42
+ # end
43
+ #
44
+ # Example (Rails)
45
+ #
46
+ # class BackendController < ApplicationController
47
+ #
48
+ # def paypal_ipn
49
+ # notify = Paypal::Notification.new(request.raw_post)
50
+ #
51
+ # order = Order.find(notify.item_id)
52
+ #
53
+ # if notify.acknowledge
54
+ # begin
55
+ #
56
+ # if notify.complete? and order.total == notify.amount and notify.business == 'sales@myshop.com'
57
+ # order.status = 'success'
58
+ #
59
+ # shop.ship(order)
60
+ # else
61
+ # logger.error("Failed to verify Paypal's notification, please investigate")
62
+ # end
63
+ #
64
+ # rescue => e
65
+ # order.status = 'failed'
66
+ # raise
67
+ # ensure
68
+ # order.save
69
+ # end
70
+ # end
71
+ #
72
+ # render :nothing
73
+ # end
74
+ # end
75
+ class Notification
76
+ attr_accessor :params
77
+ attr_accessor :raw
78
+
79
+ # Creates a new paypal object. Pass the raw html you got from paypal in.
80
+ # In a rails application this looks something like this
81
+ #
82
+ # def paypal_ipn
83
+ # paypal = Paypal::Notification.new(request.raw_post)
84
+ # ...
85
+ # end
86
+ def initialize(post)
87
+ raise NoDataError if post.to_s.empty?
88
+
89
+ @params = {}
90
+ @raw = ""
91
+
92
+ parse(post)
93
+ end
94
+
95
+ # Transaction statuses
96
+ def canceled_reversal?
97
+ status == :Canceled_Reversal
98
+ end
99
+
100
+ def completed?
101
+ status == :Completed
102
+ end
103
+
104
+ def denied?
105
+ status == :Denied
106
+ end
107
+
108
+ def expired?
109
+ status == :Expired
110
+ end
111
+
112
+ def failed?
113
+ status == :Failed
114
+ end
115
+
116
+ def pending?
117
+ status == :Pending
118
+ end
119
+
120
+ def processed?
121
+ status == :Processed
122
+ end
123
+
124
+ def refunded?
125
+ status == :Refunded
126
+ end
127
+
128
+ def reversed?
129
+ status == :Reversed
130
+ end
131
+
132
+ def voided?
133
+ status == :Voided
134
+ end
135
+
136
+ # Acknowledge the transaction to paypal. This method has to be called after a new
137
+ # ipn arrives. Paypal will verify that all the information we received are correct and will return a
138
+ # ok or a fail.
139
+ #
140
+ # Example:
141
+ #
142
+ # def paypal_ipn
143
+ # notify = PaypalNotification.new(request.raw_post)
144
+ #
145
+ # if notify.acknowledge
146
+ # ... process order ... if notify.complete?
147
+ # else
148
+ # ... log possible hacking attempt ...
149
+ # end
150
+ def acknowledge
151
+ payload = raw
152
+
153
+ uri = URI.parse(Paypal::Config.ipn_url)
154
+ request = Net::HTTP::Post.new(Paypal::Config.ipn_validation_path)
155
+ request['Content-Length'] = "#{payload.size}"
156
+ request['User-Agent'] = "paypal ruby -- http://github.com/JonathanTron/paypal"
157
+
158
+ http = Net::HTTP.new(uri.host, uri.port)
159
+
160
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_strict
161
+ http.use_ssl = true
162
+
163
+ request = http.request(request, payload)
164
+
165
+ raise StandardError.new("Faulty paypal result: #{request.body}") unless ["VERIFIED", "INVALID"].include?(request.body)
166
+
167
+ request.body == "VERIFIED"
168
+ end
169
+
170
+ def method_missing(method, *args)
171
+ params[method.to_s] || super
172
+ end
173
+
174
+ private
175
+
176
+ def status
177
+ @status ||= (params['payment_status'] ? params['payment_status'].to_sym : nil)
178
+ end
179
+
180
+ # Take the posted data and move the relevant data into a hash
181
+ def parse(post)
182
+ @raw = post
183
+ self.params = Rack::Utils.parse_query(post)
184
+ # Rack allows duplicate keys in queries, we need to use only the last value here
185
+ self.params.each{|k,v| self.params[k] = v.last if v.is_a?(Array)}
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,8 @@
1
+ require 'active_support'
2
+ require File.join(File.dirname(__FILE__),'config')
3
+ require File.join(File.dirname(__FILE__),'helpers', '/common')
4
+ require File.join(File.dirname(__FILE__),'helpers', '/rails')
5
+ require File.join(File.dirname(__FILE__),'notification')
6
+
7
+ ActionView::Base.send(:include, Paypal::Helpers::Common)
8
+ ActionView::Base.send(:include, Paypal::Helpers::Rails)
@@ -0,0 +1,3 @@
1
+ module Paypal
2
+ VERSION = "3.0.2"
3
+ end
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ for i in 1.9.2-head 1.9.1 ree 1.8.7; do
4
+ rvm use $i && echo `ruby -v` && bundle install > /dev/null && bundle exec rake spec && bundle show
5
+ done
Binary file
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "paypal/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "paypal-brazil"
7
+ s.version = Paypal::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Lairton Borges","Jonathan TRON", "Joseph HALTER", "Tobias LUETKE"]
10
+ s.email = "ljoseppi@gmail.com"
11
+ s.homepage = "https://github.com/ljoseppi/paypal"
12
+ s.summary = %q{Integrate Paypal Express}
13
+ s.description = %q{Paypal Express Integration}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.extra_rdoc_files = [
22
+ "LICENSE",
23
+ "README.md"
24
+ ]
25
+
26
+ s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
27
+
28
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
29
+ s.add_development_dependency(%q<rcov>, [">= 0.9.8"])
30
+ s.add_development_dependency(%q<nokogiri>, [">= 0"])
31
+ s.add_development_dependency(%q<bluecloth>, [">= 0"])
32
+ s.add_development_dependency(%q<yard>, [">= 0"])
33
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
34
+ end
@@ -0,0 +1,168 @@
1
+ require "spec_helper"
2
+
3
+ describe Paypal::Config do
4
+ after do
5
+ Paypal.class_eval do
6
+ remove_const :Config if const_defined?(:Config)
7
+ end
8
+ load "paypal/config.rb"
9
+ end
10
+
11
+ describe "ipn_urls" do
12
+ it "should define url for :production" do
13
+ Paypal::Config.ipn_urls[:production].should eql("https://www.paypal.com/cgi-bin/webscr")
14
+ end
15
+ it "should define url for :sandbox" do
16
+ Paypal::Config.ipn_urls[:sandbox].should eql("https://www.sandbox.paypal.com/cgi-bin/webscr")
17
+ end
18
+ it "should allow changing urls" do
19
+ url = "https://myownsandbox.com"
20
+ Paypal::Config.ipn_urls[:sandbox] = url
21
+ Paypal::Config.ipn_urls[:sandbox].should eql(url)
22
+ end
23
+ end
24
+
25
+ describe "mode" do
26
+ it "should be :sandbox by default" do
27
+ Paypal::Config.mode.should eql(:sandbox)
28
+ end
29
+
30
+ it "should accept :sandbox" do
31
+ lambda {
32
+ Paypal::Config.mode = :sandbox
33
+ }.should_not raise_error
34
+ end
35
+
36
+ it "should accept :production" do
37
+ lambda {
38
+ Paypal::Config.mode = :production
39
+ }.should_not raise_error
40
+ end
41
+
42
+ it "should not accept something different than :production or :sandbox" do
43
+ lambda {
44
+ Paypal::Config.mode = :demo
45
+ }.should raise_error(ArgumentError)
46
+ end
47
+ end
48
+
49
+ describe "when setting mode to sandbox" do
50
+ before do
51
+ Paypal::Config.mode = :sandbox
52
+ end
53
+
54
+ it "should be in :sandbox mode" do
55
+ Paypal::Config.mode.should eql(:sandbox)
56
+ end
57
+
58
+ it "should have ipn url for sandbox" do
59
+ Paypal::Config.ipn_url.should eql("https://www.sandbox.paypal.com/cgi-bin/webscr")
60
+ end
61
+
62
+ it "should have the ipn validation path for sandbox" do
63
+ Paypal::Config.ipn_validation_path.should eql("/cgi-bin/webscr?cmd=_notify-validate")
64
+ end
65
+
66
+ it "should have the ipn validation url for sandbox" do
67
+ Paypal::Config.ipn_validation_url.should eql("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate")
68
+ end
69
+
70
+ it "should have paypal cert for sandbox" do
71
+ Paypal::Config.paypal_cert.should eql(
72
+ "-----BEGIN CERTIFICATE-----
73
+ MIIDoTCCAwqgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBmDELMAkGA1UEBhMCVVMx
74
+ EzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMRUwEwYDVQQK
75
+ EwxQYXlQYWwsIEluYy4xFjAUBgNV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+Opd2yhPpneGezmw3aU222
91
+ CGrdKhOrBJRRcpoO3FjHHmXWkqgbQqDWdG7S+/l8n1QfDPp+jpULOrcnGEUY41Im
92
+ jZJTylbJQ1b5PBBjGiP0PpK48cdF
93
+ -----END CERTIFICATE-----")
94
+ end
95
+
96
+ it "should allow setting a new sandbox cert" do
97
+ lambda {
98
+ Paypal::Config.paypal_sandbox_cert = "TEST"
99
+ }.should_not raise_error
100
+ Paypal::Config.paypal_cert.should eql("TEST")
101
+ end
102
+ end
103
+
104
+ describe "when setting mode to :production" do
105
+ before do
106
+ Paypal::Config.mode = :production
107
+ end
108
+
109
+ it "should be in :production mode" do
110
+ Paypal::Config.mode.should eql(:production)
111
+ end
112
+
113
+ it "should have ipn url for production" do
114
+ Paypal::Config.ipn_url.should eql("https://www.paypal.com/cgi-bin/webscr")
115
+ end
116
+
117
+ it "should have the ipn validation path for production" do
118
+ Paypal::Config.ipn_validation_path.should eql("/cgi-bin/webscr?cmd=_notify-validate")
119
+ end
120
+
121
+ it "should have the ipn validation url for production" do
122
+ Paypal::Config.ipn_validation_url.should eql("https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate")
123
+ end
124
+
125
+ describe "when paypal_production_cert was not set" do
126
+ before do
127
+ @old_cert, Paypal::Config.paypal_production_cert = Paypal::Config.paypal_production_cert, nil
128
+ end
129
+
130
+ after do
131
+ Paypal::Config.paypal_production_cert = @old_cert
132
+ end
133
+
134
+ it "should raise an error" do
135
+ lambda {
136
+ Paypal::Config.paypal_cert
137
+ }.should raise_error(StandardError)
138
+ end
139
+ end
140
+
141
+ describe "when paypal_production_cert was set" do
142
+ before do
143
+ @old_cert, Paypal::Config.paypal_production_cert = Paypal::Config.paypal_production_cert, "TEST"
144
+ end
145
+
146
+ after do
147
+ Paypal::Config.paypal_production_cert = @old_cert
148
+ end
149
+
150
+ it "should not raise an error" do
151
+ lambda {
152
+ Paypal::Config.paypal_cert
153
+ }.should_not raise_error(StandardError)
154
+ end
155
+
156
+ it "should use the paypal production certificate" do
157
+ Paypal::Config.paypal_cert.should eql("TEST")
158
+ end
159
+ end
160
+
161
+ it "should allow setting a new production cert" do
162
+ lambda {
163
+ Paypal::Config.paypal_production_cert = "TEST"
164
+ }.should_not raise_error
165
+ Paypal::Config.paypal_cert.should eql("TEST")
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIC/jCCAmegAwIBAgIJAPlQUrHaPFrXMA0GCSqGSIb3DQEBBQUAMF4xCzAJBgNV
3
+ BAYTAkZSMRMwEQYDVQQIEwpTb21lLVN0YXRlMR4wHAYDVQQKExVPcGVuaG9vZCAt
4
+ IFBheXBhbCBnZW0xGjAYBgNVBAMTEU9wZW5ob29kUGF5cGFsR2VtMB4XDTEwMDMy
5
+ ODE1MjgwM1oXDTIwMDMyNTE1MjgwM1owXjELMAkGA1UEBhMCRlIxEzARBgNVBAgT
6
+ ClNvbWUtU3RhdGUxHjAcBgNVBAoTFU9wZW5ob29kIC0gUGF5cGFsIGdlbTEaMBgG
7
+ A1UEAxMRT3Blbmhvb2RQYXlwYWxHZW0wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
8
+ AoGBAMaHlHZGjccN7p2xV6ro+TWc34EnRWhXRe1g9z/YwxhKA3Iu9etrU8m8Bbdh
9
+ EpBQTv/IOp7EG7kiUWcdyZp5gEQn6vX/+VIyvIJEDIiyWbxk2TBr6ofb0N8dwebh
10
+ M1T4Z7RvpqSAQWjbqFnN32IWR8SzmnZ5Hl/omfOsII14rWmDAgMBAAGjgcMwgcAw
11
+ HQYDVR0OBBYEFDDSdBbUWCfW8kVhoIkjEQm0a5P1MIGQBgNVHSMEgYgwgYWAFDDS
12
+ dBbUWCfW8kVhoIkjEQm0a5P1oWKkYDBeMQswCQYDVQQGEwJGUjETMBEGA1UECBMK
13
+ U29tZS1TdGF0ZTEeMBwGA1UEChMVT3Blbmhvb2QgLSBQYXlwYWwgZ2VtMRowGAYD
14
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