catarse_paypal_express 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b89329023598b1ed9e39384aa566a45f533002f5
4
- data.tar.gz: 8e101b28b9165382f8da2f5af956230f195d5fbf
3
+ metadata.gz: 462880b88a69a04cb38588b2ef1cf645a3e5f2a5
4
+ data.tar.gz: d8b93811dc10e125d1de20db10d92d4afc4b2fc6
5
5
  SHA512:
6
- metadata.gz: 21c800b9c57b8902797d48b075deb2e1d46759cb7db39ec70f8342014b336fedfd53a17e735697457c53b433f2334a40026800523f0307d5b6872dd6f8f40777
7
- data.tar.gz: af28d53d3843797abf0f215ebba738c390676b99cd7c979790a67da68c10d0002937de6676ef0f2564ad60563ba9654c341f8a27a794b8aed1e15ac43a76aa4a
6
+ metadata.gz: f312249be9030a40ee51e0f8e4a4e48ce488fb45609c1a169b4a1c65284dc003fc8eaa9972710cc4ed5816471bc1ec49758c05eace37cd6afce539798ed7fd2c
7
+ data.tar.gz: 4a3630047639182d35448adce5da2a78cbe0d21948d60d62b98d4755b22b0a89365130856a52e227cbe56db75b891e9240c0256998ea5be3c5196dccb9cee3aa
@@ -1,4 +1,6 @@
1
1
  class CatarsePaypalExpress::PaypalExpressController < ApplicationController
2
+ include ActiveMerchant::Billing::Integrations
3
+
2
4
  skip_before_filter :force_http
3
5
  SCOPE = "projects.backers.checkout"
4
6
  layout :false
@@ -6,15 +8,27 @@ class CatarsePaypalExpress::PaypalExpressController < ApplicationController
6
8
  def review
7
9
  end
8
10
 
11
+ def refund
12
+ refund_request = gateway.refund(nil, backer.payment_id)
13
+
14
+ if refund_request.success?
15
+ flash[:notice] = I18n.t('projects.backers.refund.success')
16
+ else
17
+ flash[:alert] = I18n.t('projects.backers.refund.error')
18
+ end
19
+
20
+ redirect_to main_app.admin_backers_path
21
+ end
22
+
9
23
  def ipn
10
- if backer
24
+ if backer && notification.acknowledge
11
25
  process_paypal_message params
12
26
  backer.update_attributes({
13
27
  :payment_service_fee => params['mc_fee'],
14
28
  :payer_email => params['payer_email']
15
29
  })
16
30
  else
17
- return render status: 500, text: e.inspect
31
+ return render status: 500, nothing: true
18
32
  end
19
33
  return render status: 200, nothing: true
20
34
  rescue Exception => e
@@ -110,4 +124,10 @@ class CatarsePaypalExpress::PaypalExpressController < ApplicationController
110
124
  puts "[PayPal] An API Certificate or API Signature is required to make requests to PayPal"
111
125
  end
112
126
  end
127
+
128
+ protected
129
+
130
+ def notification
131
+ @notification ||= Paypal::Notification.new(request.raw_post)
132
+ end
113
133
  end
@@ -1,2 +1,2 @@
1
- ActiveMerchant::Billing::PaypalExpressGateway.default_currency = 'BRL'
1
+ ActiveMerchant::Billing::PaypalExpressGateway.default_currency = (PaymentEngines.configuration[:currency_charge] rescue nil) || 'BRL'
2
2
  ActiveMerchant::Billing::Base.mode = :test if (PaymentEngines.configuration[:paypal_test] == 'true' rescue nil)
@@ -1,5 +1,14 @@
1
1
  begin
2
- PaymentEngines.register({name: 'paypal', review_path: ->(backer){ CatarsePaypalExpress::Engine.routes.url_helpers.review_paypal_express_path(backer) }, locale: 'en'})
2
+ PaymentEngines.register({
3
+ name: 'paypal',
4
+ review_path: ->(backer) {
5
+ CatarsePaypalExpress::Engine.routes.url_helpers.review_paypal_express_path(backer)
6
+ },
7
+ refund_path: ->(backer) {
8
+ CatarsePaypalExpress::Engine.routes.url_helpers.refund_paypal_express_path(backer)
9
+ },
10
+ locale: 'en'
11
+ })
3
12
  rescue Exception => e
4
13
  puts "Error while registering payment engine: #{e}"
5
14
  end
@@ -1,6 +1,9 @@
1
1
  en:
2
2
  projects:
3
3
  backers:
4
+ refund:
5
+ success: 'Pedido de reembolso enviado com sucesso!'
6
+ error: 'OPS! Ocorreu um erro ao tentar enviar o pedido de reembolso.'
4
7
  review:
5
8
  paypal: 'PayPal'
6
9
  international:
@@ -1,6 +1,9 @@
1
1
  pt:
2
2
  projects:
3
3
  backers:
4
+ refund:
5
+ success: 'Pedido de reembolso enviado com sucesso!'
6
+ error: 'OPS! Ocorreu um erro ao tentar enviar o pedido de reembolso.'
4
7
  review:
5
8
  paypal: 'Pagamento internacional - PayPal'
6
9
  international:
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ CatarsePaypalExpress::Engine.routes.draw do
5
5
  end
6
6
 
7
7
  member do
8
+ post :refund
8
9
  get :review
9
10
  post :pay
10
11
  get :success
@@ -1,3 +1,3 @@
1
1
  module CatarsePaypalExpress
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -40,6 +40,21 @@ describe CatarsePaypalExpress::PaypalExpressController do
40
40
  address_phone_number: '123'
41
41
  }) }
42
42
 
43
+ describe "POST refund" do
44
+ before do
45
+ success_refund = double
46
+ success_refund.stub(:success?).and_return(true)
47
+
48
+ main_app.should_receive(:admin_backers_path).and_return('admin_backers_path')
49
+
50
+ gateway.should_receive(:refund).with(nil, backer.payment_id).and_return(success_refund)
51
+
52
+ post :refund, id: backer.id, use_route: 'catarse_paypal_express'
53
+ end
54
+
55
+ it { should redirect_to('admin_backers_path') }
56
+ end
57
+
43
58
  describe "GET review" do
44
59
  before do
45
60
  get :review, id: backer.id, use_route: 'catarse_paypal_express'
@@ -49,24 +64,63 @@ describe CatarsePaypalExpress::PaypalExpressController do
49
64
 
50
65
  describe "POST ipn" do
51
66
  let(:ipn_data){ {"mc_gross"=>"50.00", "protection_eligibility"=>"Eligible", "address_status"=>"unconfirmed", "payer_id"=>"S7Q8X88KMGX5S", "tax"=>"0.00", "address_street"=>"Rua Tatui, 40 ap 81\r\nJardins", "payment_date"=>"09:03:01 Nov 05, 2012 PST", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"01409-010", "first_name"=>"Paula", "mc_fee"=>"3.30", "address_country_code"=>"BR", "address_name"=>"Paula Rizzo", "notify_version"=>"3.7", "custom"=>"", "payer_status"=>"verified", "address_country"=>"Brazil", "address_city"=>"Sao Paulo", "quantity"=>"1", "verify_sign"=>"ALBe4QrXe2sJhpq1rIN8JxSbK4RZA.Kfc5JlI9Jk4N1VQVTH5hPYOi2S", "payer_email"=>"paula.rizzo@gmail.com", "txn_id"=>"3R811766V4891372K", "payment_type"=>"instant", "last_name"=>"Rizzo", "address_state"=>"SP", "receiver_email"=>"financeiro@catarse.me", "payment_fee"=>"", "receiver_id"=>"BVUB4EVC7YCWL", "txn_type"=>"express_checkout", "item_name"=>"Back project", "mc_currency"=>"BRL", "item_number"=>"", "residence_country"=>"BR", "handling_amount"=>"0.00", "transaction_subject"=>"Back project", "payment_gross"=>"", "shipping"=>"0.00", "ipn_track_id"=>"5865649c8c27"} }
52
-
53
67
  let(:backer){ double(:backer, :payment_id => ipn_data['txn_id'] ) }
68
+ let(:notification) { double }
54
69
 
55
70
  before do
56
- params = ipn_data.merge({ use_route: 'catarse_paypal_express' })
57
- backer.should_receive(:update_attributes).with({
58
- payment_service_fee: ipn_data['mc_fee'],
59
- payer_email: ipn_data['payer_email']
60
- })
61
- controller.should_receive(:process_paypal_message).with(ipn_data.merge({
62
- "controller"=>"catarse_paypal_express/paypal_express",
63
- "action"=>"ipn"
64
- }))
65
- post :ipn, params
71
+ controller.stub(:notification).and_return(notification)
66
72
  end
67
73
 
68
- its(:status){ should == 200 }
69
- its(:body){ should == ' ' }
74
+ context "when is a valid ipn data" do
75
+ before do
76
+ params = ipn_data.merge({ use_route: 'catarse_paypal_express' })
77
+
78
+ notification.stub(:acknowledge).and_return(true)
79
+
80
+ backer.should_receive(:update_attributes).with({
81
+ payment_service_fee: ipn_data['mc_fee'],
82
+ payer_email: ipn_data['payer_email']
83
+ })
84
+ controller.should_receive(:process_paypal_message).with(ipn_data.merge({
85
+ "controller"=>"catarse_paypal_express/paypal_express",
86
+ "action"=>"ipn"
87
+ }))
88
+
89
+ notification.should_receive(:acknowledge)
90
+
91
+ post :ipn, params
92
+ end
93
+
94
+ its(:status){ should == 200 }
95
+ its(:body){ should == ' ' }
96
+ end
97
+
98
+ context "when is not valid ipn data" do
99
+ let(:ipn_data){ {"mc_gross"=>"50.00", "payment_status" => 'confirmed', "txn_id" => "3R811766V4891372K", 'payer_email' => 'fake@email.com', 'mc_fee' => '0.0'} }
100
+
101
+ before do
102
+ params = ipn_data.merge({ use_route: 'catarse_paypal_express' })
103
+
104
+ notification.stub(:acknowledge).and_return(false)
105
+
106
+ backer.should_receive(:update_attributes).with({
107
+ payment_service_fee: ipn_data['mc_fee'],
108
+ payer_email: ipn_data['payer_email']
109
+ }).never
110
+
111
+ controller.should_receive(:process_paypal_message).with(ipn_data.merge({
112
+ "controller"=>"catarse_paypal_express/paypal_express",
113
+ "action"=>"ipn"
114
+ })).never
115
+
116
+ notification.should_receive(:acknowledge)
117
+
118
+ post :ipn, params
119
+ end
120
+
121
+ its(:status){ should == 500 }
122
+ its(:body){ should == ' ' }
123
+ end
70
124
  end
71
125
 
72
126
  describe "POST pay" do
@@ -9,6 +9,7 @@
9
9
  # Choose the win32 build.
10
10
  # Install PostgreSQL and put its /bin directory on your path.
11
11
  development:
12
+ host: localhost
12
13
  adapter: postgresql
13
14
  encoding: utf-8
14
15
  database: catarse_development
@@ -35,6 +36,7 @@ development:
35
36
  # re-generated from your development database when you run "rake".
36
37
  # Do not set this db to the same as development or production.
37
38
  test: &test
39
+ host: localhost
38
40
  adapter: postgresql
39
41
  encoding: utf-8
40
42
  database: catarse_test
@@ -43,6 +45,7 @@ test: &test
43
45
 
44
46
 
45
47
  production:
48
+ host: localhost
46
49
  adapter: postgresql
47
50
  encoding: utf-8
48
51
  database: catarse_production
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_paypal_express
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-15 00:00:00.000000000 Z
13
+ date: 2013-11-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.0.3
189
+ rubygems_version: 2.1.10
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: PaypalExpress integration with Catarse