active_paypal_adaptive_payment 0.2.5 → 0.2.6

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,20 @@
1
+ # encoding: utf-8
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ module Integrations #:nodoc:
5
+ class Notification
6
+
7
+ private
8
+
9
+ # Take the posted data and move the relevant data into a hash
10
+ def parse(post)
11
+ @raw = post.to_s
12
+ for line in @raw.split('&')
13
+ key, value = CGI.unescape(*line).scan( %r{^([A-Za-z0-9_.\[\]]+)\=(.*)$} ).flatten
14
+ params[key] = CGI.unescape(value)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ module Integrations #:nodoc:
5
+ module PaypalAdaptivePayment
6
+ autoload :Return, 'active_merchant/billing/integrations/paypal_adaptive_payment/return.rb'
7
+ autoload :Helper, 'active_merchant/billing/integrations/paypal_adaptive_payment/helper.rb'
8
+ autoload :Notification, 'active_merchant/billing/integrations/paypal_adaptive_payment/notification.rb'
9
+
10
+ # Overwrite this if you want to change the Paypal test url
11
+ mattr_accessor :test_url
12
+ self.test_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
13
+
14
+ # Overwrite this if you want to change the Paypal production url
15
+ mattr_accessor :production_url
16
+ self.production_url = 'https://www.paypal.com/cgi-bin/webscr'
17
+
18
+ def self.service_url
19
+ mode = ActiveMerchant::Billing::Base.integration_mode
20
+ case mode
21
+ when :production
22
+ self.production_url
23
+ when :test
24
+ self.test_url
25
+ else
26
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
27
+ end
28
+ end
29
+
30
+ def self.notification(post, options = {})
31
+ Notification.new(post)
32
+ end
33
+
34
+ def self.return(query_string, options = {})
35
+ Return.new(query_string)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ module Integrations #:nodoc:
5
+ module PaypalAdaptivePayment
6
+ class Helper < ActiveMerchant::Billing::Integrations::Paypal::Helper
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: utf-8
2
+ require 'net/http'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ module Integrations #:nodoc:
7
+ module PaypalAdaptivePayment
8
+ # Parser and handler for incoming Instant payment notifications from paypal.
9
+ # The Example shows a typical handler in a rails application. Note that this
10
+ # is an example, please read the Paypal API documentation for all the details
11
+ # on creating a safe payment controller.
12
+ #
13
+ # Example
14
+ #
15
+ # class BackendController < ApplicationController
16
+ # include ActiveMerchant::Billing::Integrations
17
+ #
18
+ # def paypal_ipn
19
+ # notify = PaypalAdaptivePayment::Notification.new(request.raw_post)
20
+ #
21
+ # order = Order.find(notify.item_id)
22
+ #
23
+ # if notify.acknowledge
24
+ # begin
25
+ #
26
+ # if notify.complete? and order.total == notify.amount
27
+ # order.status = 'COMPLETED'
28
+ #
29
+ # shop.ship(order)
30
+ # else
31
+ # logger.error("Failed to verify Paypal's notification, please investigate")
32
+ # end
33
+ #
34
+ # rescue => e
35
+ # order.status = 'ERROR'
36
+ # raise
37
+ # ensure
38
+ # order.save
39
+ # end
40
+ # end
41
+ #
42
+ # render :nothing
43
+ # end
44
+ # end
45
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
46
+ include PostsData
47
+
48
+ # Was the transaction complete?
49
+ def complete?
50
+ status == "COMPLETED"
51
+ end
52
+
53
+ # Status of transaction. List of possible values:
54
+ # <tt>CREATED</tt>::
55
+ # <tt>COMPLETED</tt>::
56
+ # <tt>INCOMPLETE</tt>::
57
+ # <tt>ERROR</tt>::
58
+ # <tt>REVERSALERROR</tt>::
59
+ # <tt>PROCESSING</tt>::
60
+ # <tt>PENDING</tt>::
61
+ def status
62
+ params['status']
63
+ end
64
+
65
+ # Id of this transaction (paypal number)
66
+ def transaction_id
67
+ params['transaction[0].id_for_sender_txn']
68
+ end
69
+
70
+ def type
71
+ params['action_type']
72
+ end
73
+
74
+ # This is the item number which we submitted to paypal
75
+ # The custom field is also mapped to item_id because PayPal
76
+ # doesn't return item_number in dispute notifications
77
+ def item_id
78
+ params['item_number'] || params['custom']
79
+ end
80
+
81
+ # This is the invoice which you passed to paypal
82
+ def invoice
83
+ params['transaction[0].invoiceId']
84
+ end
85
+
86
+ # Was this a test transaction?
87
+ def test?
88
+ params['test_ipn'] == '1'
89
+ end
90
+
91
+ def account
92
+ params['business'] || params['transaction[0].receiver']
93
+ end
94
+
95
+ # Acknowledge the transaction to paypal. This method has to be called after a new
96
+ # ipn arrives. Paypal will verify that all the information we received are correct and will return a
97
+ # ok or a fail.
98
+ #
99
+ # Example:
100
+ #
101
+ # def paypal_ipn
102
+ # notify = PaypalAdaptivePaymentNotification.new(request.raw_post)
103
+ #
104
+ # if notify.acknowledge
105
+ # ... process order ... if notify.complete?
106
+ # else
107
+ # ... log possible hacking attempt ...
108
+ # end
109
+ def acknowledge
110
+ payload = raw
111
+
112
+ response = ssl_post(Paypal.service_url + '?cmd=_notify-validate', payload,
113
+ 'Content-Length' => "#{payload.size}",
114
+ 'User-Agent' => "Active Merchant -- http://activemerchant.org"
115
+ )
116
+
117
+ raise StandardError.new("Faulty paypal result: #{response}") unless ["VERIFIED", "INVALID"].include?(response)
118
+
119
+ response == "VERIFIED"
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module PaypalAdaptivePayment
5
+ class Return < ActiveMerchant::Billing::Integrations::Return
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
1
2
  require 'active_merchant'
2
- require File.dirname(__FILE__) +
3
- '/active_merchant/billing/gateways/paypal_adaptive_payment'
3
+ require '/active_merchant/billing/gateways/paypal_adaptive_payment'
4
+ require '/active_merchant/billing/integrations/paypal_adaptive_payment'
5
+ require '/active_merchant/billing/integrations/notification'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_paypal_adaptive_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000Z
12
+ date: 2011-10-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemerchant
16
- requirement: &8151980 !ruby/object:Gem::Requirement
16
+ requirement: &12059900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.5.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8151980
24
+ version_requirements: *12059900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &8151440 !ruby/object:Gem::Requirement
27
+ requirement: &12057740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *8151440
35
+ version_requirements: *12057740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rash
38
- requirement: &8150900 !ruby/object:Gem::Requirement
38
+ requirement: &12056220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.3.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *8150900
46
+ version_requirements: *12056220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: money
49
- requirement: &8150260 !ruby/object:Gem::Requirement
49
+ requirement: &12052900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: 3.6.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *8150260
57
+ version_requirements: *12052900
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ requirement: &12049960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 0.10.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *12049960
58
69
  description: ! ' This library is meant to interface with PayPal''s Adaptive Payment
59
70
  Gateway.
60
71
 
@@ -66,6 +77,11 @@ extensions: []
66
77
  extra_rdoc_files: []
67
78
  files:
68
79
  - lib/active_paypal_adaptive_payment.rb
80
+ - lib/active_merchant/billing/integrations/paypal_adaptive_payment.rb
81
+ - lib/active_merchant/billing/integrations/paypal_adaptive_payment/helper.rb
82
+ - lib/active_merchant/billing/integrations/paypal_adaptive_payment/return.rb
83
+ - lib/active_merchant/billing/integrations/paypal_adaptive_payment/notification.rb
84
+ - lib/active_merchant/billing/integrations/notification.rb
69
85
  - lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
70
86
  - lib/active_merchant/billing/gateways/paypal_adaptive_payments/ext.rb
71
87
  - lib/active_merchant/billing/gateways/paypal_adaptive_payments/exceptions.rb