unlock_paypal 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21e10fb6618d1683d2e715875edca3191d43f199
4
+ data.tar.gz: 39b32c8bd52807b33cdc7637f0e3057cd27d301d
5
+ SHA512:
6
+ metadata.gz: 497a1636d893079c0122a94356d90f979abf995ea2d27f637048b6366e8317fc6f59d2cdfef33ee6d31a84c63f3c662f99e8dc211c4465ec3d008adefaba2fcd
7
+ data.tar.gz: 55a6bd144aa154020eef8f2b366465c7f852a511de94e40f238564d64e3317ff2030753face4a391230a9f48ecc76641f944aea018b7eb7591d9dbc3cafadee1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'UnlockPaypal'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
File without changes
@@ -0,0 +1 @@
1
+ @import unlock_paypal/unlock_paypal
@@ -0,0 +1,121 @@
1
+ class UnlockPaypal::ContributionsController < ::ApplicationController
2
+
3
+ is_unlock_gateway
4
+ after_action :verify_authorized, except: %i[ipn]
5
+
6
+ def create
7
+
8
+ if create_contribution
9
+
10
+ paypal = PayPal::Recurring.new({
11
+ return_url: edit_paypal_contribution_url(@contribution),
12
+ cancel_url: new_initiative_contribution_url(@initiative.id),
13
+ ipn_url: ipn_paypal_contributions_url,
14
+ description: @initiative.name,
15
+ amount: ('%.2f' % @contribution.value),
16
+ currency: "BRL"
17
+ }.merge(@contribution.paypal_auth))
18
+
19
+ checkout = paypal.checkout
20
+
21
+ if checkout.valid?
22
+ redirect_to checkout.checkout_url
23
+ else
24
+ if @contribution.gateway.sandbox?
25
+ @contribution.errors.add(:base, "Parece que este Unlock não está autorizado a utilizar o ambiente de Sandbox do PayPal.#{ ' Você já solicitou acesso à API? Verifique também se configurou o nome de usuário, a senha e a assinatura de API no PayPal.' if @initiative.user == current_user }")
26
+ else
27
+ @contribution.errors.add(:base, "Parece que este Unlock não está autorizado a utilizar o ambiente de produção do PayPal.#{ ' Você já solicitou acesso à API? Verifique também se configurou o nome de usuário, a senha e a assinatura de API no PayPal.' if @initiative.user == current_user }")
28
+ end
29
+ return render '/initiatives/contributions/new'
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ def edit
37
+ edit! do
38
+ authorize resource
39
+ @initiative = @contribution.initiative
40
+ @gateways = @initiative.gateways.without_state(:draft).order(:ordering)
41
+ paypal = PayPal::Recurring.new({token: params[:token]}.merge(@contribution.paypal_auth))
42
+ details = paypal.checkout_details
43
+ @contribution.gateway_data = {} unless @contribution.gateway_data
44
+ @contribution.gateway_data["token"] = params[:token]
45
+ @contribution.gateway_data["PayerID"] = params[:PayerID]
46
+ @contribution.gateway_data["checkout_status"] = details.status
47
+ @contribution.gateway_data["email"] = details.email
48
+ @contribution.gateway_data["payer_status"] = details.payer_status
49
+ @contribution.gateway_data["payer_status"] = details.payer_status
50
+ @contribution.gateway_data["first_name"] = details.first_name
51
+ @contribution.gateway_data["last_name"] = details.last_name
52
+ @contribution.gateway_data["country"] = details.country
53
+ @contribution.gateway_data["currency"] = details.currency
54
+ @contribution.gateway_data["amount"] = details.amount
55
+ @contribution.gateway_data["description"] = details.description
56
+ @contribution.gateway_data["ipn_url"] = details.ipn_url
57
+ @contribution.gateway_data["agreed"] = details.agreed?
58
+ @contribution.save!
59
+ paypal = PayPal::Recurring.new({
60
+ token: params[:token],
61
+ payer_id: params[:PayerID],
62
+ description: details.description,
63
+ amount: details.amount,
64
+ currency: details.currency
65
+ }.merge(@contribution.paypal_auth))
66
+ payment = paypal.request_payment
67
+ if payment.approved? && payment.completed?
68
+ recurring = PayPal::Recurring.new({
69
+ ipn_url: details.ipn_url,
70
+ description: details.description,
71
+ amount: details.amount,
72
+ currency: details.currency,
73
+ frequency: 1,
74
+ token: params[:token],
75
+ period: :monthly,
76
+ payer_id: params[:PayerID],
77
+ start_at: Time.now,
78
+ failed: 3,
79
+ outstanding: :next_billing
80
+ }.merge(@contribution.paypal_auth))
81
+ profile = recurring.create_recurring_profile
82
+ if profile.valid? && profile.profile_id.present? && profile.status == "ActiveProfile"
83
+ profile_data = {}
84
+ profile_data["profile_id"] = profile.profile_id
85
+ profile_data["profile_status"] = profile.status
86
+ @contribution.update gateway_data: @contribution.gateway_data.merge(profile_data)
87
+ @contribution.activate!
88
+ return redirect_to initiative_contribution_path(@initiative.id, @contribution)
89
+ else
90
+ if payment.errors.size > 0
91
+ payment.errors.each do |error|
92
+ error[:messages].each do |message|
93
+ @contribution.errors.add(:base, "#{error[:code]} #{message} (PayPal)")
94
+ end
95
+ end
96
+ else
97
+ @contribution.errors.add(:base, "Ooops. Ocorreu um erro ao ativar seu perfil recorrente no PayPal.")
98
+ end
99
+ return render '/initiatives/contributions/new'
100
+ end
101
+ else
102
+ if payment.errors.size > 0
103
+ payment.errors.each do |error|
104
+ error[:messages].each do |message|
105
+ @contribution.errors.add(:base, "#{error[:code]} #{message} (PayPal)")
106
+ end
107
+ end
108
+ else
109
+ @contribution.errors.add(:base, "Ooops. Ocorreu um erro ao processar seu pagamento no PayPal.")
110
+ end
111
+ return render '/initiatives/contributions/new'
112
+ end
113
+ end
114
+ end
115
+
116
+ def ipn
117
+ # TODO implement ipn in the future
118
+ head :ok
119
+ end
120
+
121
+ end
@@ -0,0 +1,4 @@
1
+ = form_for @contribution, url: paypal_contributions_path, method: :post do |form|
2
+ = render partial: 'initiatives/contributions/sandbox_warning', locals: { gateway: gateway }
3
+ = render partial: 'initiatives/contributions/base_form', locals: { form: form, gateway: gateway }
4
+ .submit= form.submit "Realizar pagamento pelo Paypal"
@@ -0,0 +1,6 @@
1
+ PayPal::Recurring.configure do |config|
2
+ config.sandbox = true
3
+ config.username = "NO_USERNAME_FOR_NOW"
4
+ config.password = "NO_PASSWORD_FOR_NOW"
5
+ config.signature = "NO_SIGNATURE_FOR_NOW"
6
+ end
@@ -0,0 +1 @@
1
+ UnlockGateway.register 'UnlockPaypal'
data/config/routes.rb ADDED
@@ -0,0 +1,13 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :paypal_contributions, controller: 'unlock_paypal/contributions', only: [:create, :edit, :update], path: '/paypal' do
4
+ member do
5
+ put :activate
6
+ put :suspend
7
+ end
8
+ collection do
9
+ post :ipn
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :unlock_paypal do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,4 @@
1
+ module UnlockPaypal
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ module UnlockPaypal
2
+ module Models
3
+ module Contribution
4
+
5
+ include UnlockGateway::Models::Contribution
6
+
7
+ def gateway_identifier
8
+ self.gateway_data && self.gateway_data["profile_id"]
9
+ end
10
+
11
+ def state_on_gateway
12
+ profile = PayPal::Recurring.new({profile_id: self.gateway_identifier}.merge(self.paypal_auth)).profile
13
+ if profile.valid? && profile.active?
14
+ :active
15
+ else
16
+ :suspended
17
+ end
18
+ end
19
+
20
+ def update_state_on_gateway!(state)
21
+ profile = PayPal::Recurring.new({profile_id: self.gateway_identifier}.merge(self.paypal_auth))
22
+ case state
23
+ when :active
24
+ response = profile.reactivate
25
+ when :suspended
26
+ response = profile.suspend
27
+ end
28
+ response.valid?
29
+ end
30
+
31
+ def paypal_auth
32
+ return {} unless self.gateway && self.gateway.settings
33
+ {
34
+ username: self.gateway.settings["username"],
35
+ password: self.gateway.settings["password"],
36
+ signature: self.gateway.settings["signature"],
37
+ sandbox: self.gateway.sandbox?
38
+ }
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ module UnlockPaypal
2
+ module Models
3
+ module Gateway
4
+
5
+ include UnlockGateway::Models::Gateway
6
+
7
+ def name
8
+ "PayPal"
9
+ end
10
+
11
+ def description
12
+ "Economize tempo e dinheiro com as Assinaturas e Cobranças recorrentes do PayPal"
13
+ end
14
+
15
+ def image
16
+ "unlock_paypal/logo.png"
17
+ end
18
+
19
+ def url
20
+ "https://www.paypal.com"
21
+ end
22
+
23
+ def path
24
+ "/paypal"
25
+ end
26
+
27
+ def available_settings
28
+ settings = []
29
+ instructions = "Com sua conta de Especial ou Comercial habilitada no Paypal, vá em <a href='https://www.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-api-access&upgrade.x=1' target='_blank'>Minha conta › Perfil › Mais opções › Minhas ferramentas de venda › Acesso à API › Atualizar</a> e escolha a <strong>Opção 2</strong>. Depois, clique em <a href='https://www.paypal.com/br/cgi-bin/webscr?cmd=_profile-api-signature' target='_blank'>Exibir assinatura de API</a>."
30
+ settings << UnlockGateway::Setting.new(:username, "Nome do usuário de API", instructions)
31
+ settings << UnlockGateway::Setting.new(:password, "Senha de API", instructions)
32
+ settings << UnlockGateway::Setting.new(:signature, "Assinatura de API", instructions)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module UnlockPaypal
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "paypal/recurring"
2
+ require "unlock_gateway"
3
+ require "unlock_paypal/engine"
4
+ require "unlock_paypal/models/gateway"
5
+ require "unlock_paypal/models/contribution"
6
+
7
+ module UnlockPaypal
8
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unlock_paypal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Weinmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: unlock_gateway
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: paypal-recurring
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: paypal-recurrring integration with Unlock
70
+ email:
71
+ - danielweinmann@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - Rakefile
78
+ - app/assets/images/unlock_paypal/logo.png
79
+ - app/assets/javascripts/unlock_paypal.js.coffee
80
+ - app/assets/stylesheets/unlock_paypal.sass
81
+ - app/assets/stylesheets/unlock_paypal/unlock_paypal.sass
82
+ - app/controllers/unlock_paypal/contributions_controller.rb
83
+ - app/views/unlock_paypal/contributions/_form.html.slim
84
+ - config/initializers/paypal-recurring.rb
85
+ - config/initializers/register.rb
86
+ - config/routes.rb
87
+ - lib/tasks/unlock_moip_tasks.rake
88
+ - lib/unlock_paypal.rb
89
+ - lib/unlock_paypal/engine.rb
90
+ - lib/unlock_paypal/models/contribution.rb
91
+ - lib/unlock_paypal/models/gateway.rb
92
+ - lib/unlock_paypal/version.rb
93
+ homepage: https://github.com/danielweinmann/unlock_paypal
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: paypal-recurrring integration with Unlock
117
+ test_files: []