paypal-recurring 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paypal-recurring (0.1.4)
4
+ paypal-recurring (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -11,6 +11,7 @@ module PayPal
11
11
  autoload :Request, "paypal/recurring/request"
12
12
  autoload :Response, "paypal/recurring/response"
13
13
  autoload :Version, "paypal/recurring/version"
14
+ autoload :Utils, "paypal/recurring/utils"
14
15
 
15
16
  ENDPOINTS = {
16
17
  :sandbox => {
@@ -1,8 +1,26 @@
1
1
  module PayPal
2
2
  module Recurring
3
3
  class Notification
4
+ extend PayPal::Recurring::Utils
5
+
4
6
  attr_reader :params
5
7
 
8
+ mapping({
9
+ :type => :txn_type,
10
+ :transaction_id => :txn_id,
11
+ :fee => [:mc_fee, :payment_fee],
12
+ :reference => [:rp_invoice_id, :custom, :invoice],
13
+ :payment_id => :recurring_payment_id,
14
+ :amount => [:amount, :mc_gross, :payment_gross],
15
+ :currency => :mc_currency,
16
+ :status => :payment_status,
17
+ :payment_date => [:time_created, :payment_date],
18
+ :seller_id => :receiver_id,
19
+ :email => :receiver_email,
20
+ :initial_amount => :initial_payment_amount,
21
+ :payer_email => :payer_email
22
+ })
23
+
6
24
  def initialize(params = {})
7
25
  self.params = params
8
26
  end
@@ -13,10 +31,6 @@ module PayPal
13
31
  end
14
32
  end
15
33
 
16
- def type
17
- params[:txn_type]
18
- end
19
-
20
34
  def express_checkout?
21
35
  type == "express_checkout"
22
36
  end
@@ -25,6 +39,10 @@ module PayPal
25
39
  type == "recurring_payment"
26
40
  end
27
41
 
42
+ def recurring_payment_profile?
43
+ type == "recurring_payment_profile_created"
44
+ end
45
+
28
46
  def request
29
47
  @request ||= PayPal::Recurring::Request.new.tap do |request|
30
48
  request.uri = URI.parse("#{PayPal::Recurring.site_endpoint}?cmd=_notify-validate")
@@ -36,47 +54,19 @@ module PayPal
36
54
  end
37
55
 
38
56
  def valid?
39
- completed? && verified? && params[:receiver_email] == PayPal::Recurring.email && params[:receiver_id] == PayPal::Recurring.seller_id
57
+ completed? && verified? && email == PayPal::Recurring.email && seller_id == PayPal::Recurring.seller_id
40
58
  end
41
59
 
42
60
  def completed?
43
61
  status == "Completed"
44
62
  end
45
63
 
46
- def transaction_id
47
- params[:txn_id]
48
- end
49
-
50
- def fee
51
- params[:mc_currency]
52
- end
53
-
54
- def reference
55
- params[:rp_invoice_id]
56
- end
57
-
58
- def payment_id
59
- params[:recurring_payment_id]
60
- end
61
-
62
64
  def next_payment_date
63
- Time.parse(params[:next_payment_date]) if params[:next_payment_date]
65
+ self.class.convert_to_time(params[:next_payment_date]) if params[:next_payment_date]
64
66
  end
65
67
 
66
68
  def paid_at
67
- Time.parse params[:time_created] if params[:time_created]
68
- end
69
-
70
- def amount
71
- params[:amount]
72
- end
73
-
74
- def currency
75
- params[:mc_currency]
76
- end
77
-
78
- def status
79
- params[:payment_status]
69
+ self.class.convert_to_time(payment_date) if payment_date
80
70
  end
81
71
 
82
72
  def verified?
@@ -2,24 +2,9 @@ module PayPal
2
2
  module Recurring
3
3
  module Response
4
4
  class Base
5
- attr_accessor :response
5
+ extend PayPal::Recurring::Utils
6
6
 
7
- def self.mapping(options = {})
8
- options.each do |to, from|
9
- class_eval <<-RUBY
10
- def #{to}
11
- @#{to} ||= begin
12
- from = [#{from.inspect}].flatten
13
- name = from.find {|name| params[name]}
14
- value = nil
15
- value = params[name] if name
16
- value = send("build_#{to}", value) if respond_to?("build_#{to}", true)
17
- value
18
- end
19
- end
20
- RUBY
21
- end
22
- end
7
+ attr_accessor :response
23
8
 
24
9
  mapping(
25
10
  :token => :TOKEN,
@@ -0,0 +1,26 @@
1
+ module PayPal
2
+ module Recurring
3
+ module Utils
4
+ def convert_to_time(string)
5
+ DateTime.strptime(string, "%H:%M:%S %b %e, %Y %Z").new_offset(0)
6
+ end
7
+
8
+ def mapping(options = {})
9
+ options.each do |to, from|
10
+ class_eval <<-RUBY
11
+ def #{to}
12
+ @#{to} ||= begin
13
+ from = [#{from.inspect}].flatten
14
+ name = from.find {|name| params[name]}
15
+ value = nil
16
+ value = params[name] if name
17
+ value = send("build_#{to}", value) if respond_to?("build_#{to}", true)
18
+ value
19
+ end
20
+ end
21
+ RUBY
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@ module PayPal
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- PATCH = 4
6
+ PATCH = 5
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
9
9
  end
@@ -0,0 +1,35 @@
1
+ {
2
+ "mc_gross":"9.00",
3
+ "invoice":"1234",
4
+ "protection_eligibility":"Ineligible",
5
+ "payer_id":"6KAQNBYBZ6KAC",
6
+ "tax":"0.00",
7
+ "payment_date":"20:37:01 Jul 04, 2011 PDT",
8
+ "payment_status":"Completed",
9
+ "charset":"windows-1252",
10
+ "first_name":"Test",
11
+ "mc_fee":"0.56",
12
+ "notify_version":"3.1",
13
+ "custom":"1234",
14
+ "payer_status":"verified",
15
+ "quantity":"1",
16
+ "verify_sign":"AZP9aUnslyCXgo2.9xWwtk8th8HXAnLqF6TgvmD3ME7fM.iCQhnQ0iRS",
17
+ "payer_email":"buyer_1309779460_per@simplesideias.com.br",
18
+ "txn_id":"8JD75017U43409907",
19
+ "payment_type":"instant",
20
+ "last_name":"User",
21
+ "receiver_email":"seller_1308793919_biz_api1.simplesideias.com.br",
22
+ "payment_fee":"0.56",
23
+ "receiver_id":"GSZCRUB62BL5L",
24
+ "txn_type":"express_checkout",
25
+ "item_name":"Awesome - Monthly Subscription",
26
+ "mc_currency":"USD",
27
+ "item_number":"",
28
+ "residence_country":"US",
29
+ "test_ipn":"1",
30
+ "handling_amount":"0.00",
31
+ "transaction_subject":"",
32
+ "payment_gross":"9.00",
33
+ "shipping":"0.00",
34
+ "ipn_track_id":"sAEWZiSm95ZxQfYHq-RE8w"
35
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "mc_gross":"9.00",
3
+ "period_type":" Regular",
4
+ "outstanding_balance":"0.00",
5
+ "next_payment_date":"03:00:00 Jul 06, 2011 PDT",
6
+ "protection_eligibility":"Ineligible",
7
+ "payment_cycle":"Daily",
8
+ "tax":"0.00",
9
+ "payer_id":"6KAQNBYBZ6KAC",
10
+ "payment_date":"03:06:59 Jul 05, 2011 PDT",
11
+ "payment_status":"Completed",
12
+ "product_name":"Awesome - Monthly Subscription",
13
+ "charset":"windows-1252",
14
+ "rp_invoice_id":"1234",
15
+ "recurring_payment_id":"I-E9EJKE50EPPY",
16
+ "first_name":"Test",
17
+ "mc_fee":"0.56",
18
+ "notify_version":"3.1",
19
+ "amount_per_cycle":"9.00",
20
+ "payer_status":"verified",
21
+ "currency_code":"USD",
22
+ "business":"seller_1308793919_biz_api1.simplesideias.com.br",
23
+ "verify_sign":"A31F-vcNTWfrBDr18m0ZsQO28jDTAvPYHS7RmO4dZDD-ObUm6mgY-vS1",
24
+ "payer_email":"buyer_1309779460_per@simplesideias.com.br",
25
+ "initial_payment_amount":"0.00",
26
+ "profile_status":"Active",
27
+ "amount":"9.00",
28
+ "txn_id":"8UT11014H0627171P",
29
+ "payment_type":"instant",
30
+ "last_name":"User",
31
+ "receiver_email":"seller_1308793919_biz_api1.simplesideias.com.br",
32
+ "payment_fee":"0.56",
33
+ "receiver_id":"GSZCRUB62BL5L",
34
+ "txn_type":"recurring_payment",
35
+ "mc_currency":"USD",
36
+ "residence_country":"US",
37
+ "test_ipn":"1",
38
+ "transaction_subject":"",
39
+ "payment_gross":"9.00",
40
+ "shipping":"0.00",
41
+ "product_type":"1",
42
+ "time_created":"20:37:06 Jul 04, 2011 PDT",
43
+ "ipn_track_id":"ZuDCTZrTVSGEOmiIJmdZ8Q"
44
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "payment_cycle":"Daily",
3
+ "txn_type":"recurring_payment_profile_created",
4
+ "last_name":"User",
5
+ "next_payment_date":"03:00:00 Jul 05, 2011 PDT",
6
+ "residence_country":"US",
7
+ "initial_payment_amount":"0.00",
8
+ "rp_invoice_id":"1234",
9
+ "currency_code":"USD",
10
+ "time_created":"20:37:06 Jul 04, 2011 PDT",
11
+ "verify_sign":"AKAZgvqH1r0IxFcG2KYlwYC.bd7rAhHiMcfsQu1D8ouxLCbt2THiAy6E",
12
+ "period_type":" Regular",
13
+ "payer_status":"verified",
14
+ "test_ipn":"1",
15
+ "tax":"0.00",
16
+ "payer_email":"buyer_1309779460_per@simplesideias.com.br",
17
+ "first_name":"Test",
18
+ "receiver_email":"seller_1308793919_biz_api1.simplesideias.com.br",
19
+ "payer_id":"6KAQNBYBZ6KAC",
20
+ "product_type":"1",
21
+ "shipping":"0.00",
22
+ "amount_per_cycle":"9.00",
23
+ "profile_status":"Active",
24
+ "charset":"windows-1252",
25
+ "notify_version":"3.1",
26
+ "amount":"9.00",
27
+ "outstanding_balance":"0.00",
28
+ "recurring_payment_id":"I-E9EJKE50EPPY",
29
+ "product_name":"Awesome - Monthly Subscription",
30
+ "ipn_track_id":"aWXcwC-7TDo7InmzVuuRrQ"
31
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "payment_cycle":"Daily",
3
+ "txn_type":"recurring_payment_profile_created",
4
+ "last_name":"User",
5
+ "initial_payment_status":"Completed",
6
+ "next_payment_date":"03:00:00 Jul 05, 2011 PDT",
7
+ "residence_country":"US",
8
+ "initial_payment_amount":"9.00",
9
+ "rp_invoice_id":"1234",
10
+ "currency_code":"USD",
11
+ "time_created":"05:40:02 Jul 05, 2011 PDT",
12
+ "verify_sign":"AhkQm37iumIaDqpU.GmMvkOH76DtA5R4Y1kgjo4B5u43tAt9yNOaY9H5",
13
+ "period_type":" Regular",
14
+ "payer_status":"verified",
15
+ "test_ipn":"1",
16
+ "tax":"0.00",
17
+ "payer_email":"buyer_1309779460_per@simplesideias.com.br",
18
+ "first_name":"Test",
19
+ "receiver_email":"seller_1309778833_biz@simplesideias.com.br",
20
+ "payer_id":"6KAQNBYBZ6KAC",
21
+ "product_type":"1",
22
+ "initial_payment_txn_id":"13V89154YA849712L",
23
+ "shipping":"0.00",
24
+ "amount_per_cycle":"9.00",
25
+ "profile_status":"Active",
26
+ "charset":"windows-1252",
27
+ "notify_version":"3.1",
28
+ "amount":"9.00",
29
+ "outstanding_balance":"0.00",
30
+ "recurring_payment_id":"I-NYWX42K14ES6",
31
+ "product_name":"Awesome - Monthly Subscription",
32
+ "ipn_track_id":"mLafq7gjIItS.n58DnlbIg"
33
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "mc_gross":"9.00",
3
+ "period_type":" Regular",
4
+ "outstanding_balance":"0.00",
5
+ "next_payment_date":"03:00:00 Jul 06, 2011 PDT",
6
+ "protection_eligibility":"Ineligible",
7
+ "payment_cycle":"Daily",
8
+ "tax":"0.00",
9
+ "payer_id":"6KAQNBYBZ6KAC",
10
+ "payment_date":"05:40:47 Jul 05, 2011 PDT",
11
+ "payment_status":"Completed",
12
+ "product_name":"Awesome - Monthly Subscription",
13
+ "charset":"windows-1252",
14
+ "rp_invoice_id":"1234",
15
+ "recurring_payment_id":"I-NYWX42K14ES6",
16
+ "first_name":"Test",
17
+ "mc_fee":"0.56",
18
+ "notify_version":"3.1",
19
+ "amount_per_cycle":"9.00",
20
+ "payer_status":"verified",
21
+ "currency_code":"USD",
22
+ "business":"seller_1309778833_biz@simplesideias.com.br",
23
+ "verify_sign":"AY-Nybk0IAfkhZd8.NnjoCJhyPXTAMk10-hj23D6C6FuZpclLam-uxRI",
24
+ "payer_email":"buyer_1309779460_per@simplesideias.com.br",
25
+ "initial_payment_amount":"9.00",
26
+ "profile_status":"Active",
27
+ "amount":"9.00",
28
+ "txn_id":"8C0558302N704203M",
29
+ "payment_type":"instant",
30
+ "last_name":"User",
31
+ "receiver_email":"seller_1309778833_biz@simplesideias.com.br",
32
+ "payment_fee":"0.56",
33
+ "receiver_id":"GSZCRUB62BL5L",
34
+ "txn_type":"recurring_payment",
35
+ "mc_currency":"USD",
36
+ "residence_country":"US",
37
+ "test_ipn":"1",
38
+ "transaction_subject":"",
39
+ "payment_gross":"9.00",
40
+ "shipping":"0.00",
41
+ "product_type":"1",
42
+ "time_created":"05:40:02 Jul 05, 2011 PDT",
43
+ "ipn_track_id":"kmiVwXjypSUWUOeF0F1URA"
44
+ }
@@ -11,6 +11,79 @@ describe PayPal::Recurring::Notification do
11
11
  subject.should be_recurring_payment
12
12
  end
13
13
 
14
+ it "detects recurring payment profile" do
15
+ subject.params[:txn_type] = "recurring_payment_profile_created"
16
+ subject.should be_recurring_payment_profile
17
+ end
18
+
19
+ it "normalizes payment date" do
20
+ subject.params[:payment_date] = "20:37:06 Jul 04, 2011 PDT" # PDT = -0700
21
+ subject.paid_at.strftime("%Y-%m-%d %H:%M:%S").should == "2011-07-05 03:37:06"
22
+ end
23
+
24
+ it "returns currency" do
25
+ subject.params[:mc_currency] = "BRL"
26
+ subject.currency.should == "BRL"
27
+ end
28
+
29
+ describe "#payment_date" do
30
+ it "returns date from time_created field" do
31
+ subject.params[:time_created] = "2011-07-05"
32
+ subject.payment_date.should == "2011-07-05"
33
+ end
34
+
35
+ it "returns date from payment_date field" do
36
+ subject.params[:payment_date] = "2011-07-05"
37
+ subject.payment_date.should == "2011-07-05"
38
+ end
39
+ end
40
+
41
+ describe "#fee" do
42
+ it "returns fee from mc_fee field" do
43
+ subject.params[:mc_fee] = "0.56"
44
+ subject.fee.should == "0.56"
45
+ end
46
+
47
+ it "returns fee from payment_fee field" do
48
+ subject.params[:payment_fee] = "0.56"
49
+ subject.fee.should == "0.56"
50
+ end
51
+ end
52
+
53
+ describe "#amount" do
54
+ it "returns amount from amount field" do
55
+ subject.params[:amount] = "9.00"
56
+ subject.amount.should == "9.00"
57
+ end
58
+
59
+ it "returns amount from mc_gross field" do
60
+ subject.params[:mc_gross] = "9.00"
61
+ subject.amount.should == "9.00"
62
+ end
63
+
64
+ it "returns amount from payment_gross field" do
65
+ subject.params[:payment_gross] = "9.00"
66
+ subject.amount.should == "9.00"
67
+ end
68
+ end
69
+
70
+ describe "#reference" do
71
+ it "returns from recurring IPN" do
72
+ subject.params[:rp_invoice_id] = "abc"
73
+ subject.reference.should == "abc"
74
+ end
75
+
76
+ it "returns from custom field" do
77
+ subject.params[:custom] = "abc"
78
+ subject.reference.should == "abc"
79
+ end
80
+
81
+ it "returns from invoice field" do
82
+ subject.params[:invoice] = "abc"
83
+ subject.reference.should == "abc"
84
+ end
85
+ end
86
+
14
87
  context "when successful" do
15
88
  use_vcr_cassette "notification/success"
16
89
 
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,8 @@ RSpec.configure do |config|
19
19
  config.username = "seller_1308793919_biz_api1.simplesideias.com.br"
20
20
  config.password = "1308793931"
21
21
  config.signature = "AFcWxV21C7fd0v3bYYYRCpSSRl31AzaB6TzXx5amObyEghjU13.0av2Y"
22
+ config.seller_id = "GSZCRUB62BL5L"
23
+ config.email = "seller_1308793919_biz_api1.simplesideias.com.br"
22
24
  end
23
25
  end
24
26
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paypal-recurring
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-05 00:00:00 Z
13
+ date: 2011-07-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -98,6 +98,7 @@ files:
98
98
  - lib/paypal/recurring/response/manage_profile.rb
99
99
  - lib/paypal/recurring/response/payment.rb
100
100
  - lib/paypal/recurring/response/profile.rb
101
+ - lib/paypal/recurring/utils.rb
101
102
  - lib/paypal/recurring/version.rb
102
103
  - paypal-recurring.gemspec
103
104
  - spec/fixtures/checkout/failure.yml
@@ -107,6 +108,11 @@ files:
107
108
  - spec/fixtures/details/cancelled.yml
108
109
  - spec/fixtures/details/failure.yml
109
110
  - spec/fixtures/details/success.yml
111
+ - spec/fixtures/ipn/express_checkout.json
112
+ - spec/fixtures/ipn/recurring_payment.json
113
+ - spec/fixtures/ipn/recurring_payment_profile_created.json
114
+ - spec/fixtures/ipn/recurring_payment_profile_created_with_initial_amount.json
115
+ - spec/fixtures/ipn/recurring_payment_with_initial_amount.json
110
116
  - spec/fixtures/notification/failure.yml
111
117
  - spec/fixtures/notification/success.yml
112
118
  - spec/fixtures/payment/failure.yml
@@ -143,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
149
  requirements:
144
150
  - - ">="
145
151
  - !ruby/object:Gem::Version
146
- hash: 4517482826422449883
152
+ hash: -54874171068176103
147
153
  segments:
148
154
  - 0
149
155
  version: "0"
@@ -152,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
158
  requirements:
153
159
  - - ">="
154
160
  - !ruby/object:Gem::Version
155
- hash: 4517482826422449883
161
+ hash: -54874171068176103
156
162
  segments:
157
163
  - 0
158
164
  version: "0"
@@ -171,6 +177,11 @@ test_files:
171
177
  - spec/fixtures/details/cancelled.yml
172
178
  - spec/fixtures/details/failure.yml
173
179
  - spec/fixtures/details/success.yml
180
+ - spec/fixtures/ipn/express_checkout.json
181
+ - spec/fixtures/ipn/recurring_payment.json
182
+ - spec/fixtures/ipn/recurring_payment_profile_created.json
183
+ - spec/fixtures/ipn/recurring_payment_profile_created_with_initial_amount.json
184
+ - spec/fixtures/ipn/recurring_payment_with_initial_amount.json
174
185
  - spec/fixtures/notification/failure.yml
175
186
  - spec/fixtures/notification/success.yml
176
187
  - spec/fixtures/payment/failure.yml