unlock_paypal 0.1.0 → 0.2.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: 21e10fb6618d1683d2e715875edca3191d43f199
4
- data.tar.gz: 39b32c8bd52807b33cdc7637f0e3057cd27d301d
3
+ metadata.gz: 942f31b8d6f7f37a5fb9d72f83127ff5e3875f79
4
+ data.tar.gz: 59220b5d737980dd78ae88d53fdfb04d3b65675f
5
5
  SHA512:
6
- metadata.gz: 497a1636d893079c0122a94356d90f979abf995ea2d27f637048b6366e8317fc6f59d2cdfef33ee6d31a84c63f3c662f99e8dc211c4465ec3d008adefaba2fcd
7
- data.tar.gz: 55a6bd144aa154020eef8f2b366465c7f852a511de94e40f238564d64e3317ff2030753face4a391230a9f48ecc76641f944aea018b7eb7591d9dbc3cafadee1
6
+ metadata.gz: 712e0a5c8d1bde5f24f058a2aa923677ddda74e20379988f245a78d44826a1d7f3ca83116178cdfdeaeb340cefc6d071d6e33374dc0462753af68112402e4f60
7
+ data.tar.gz: a957aa23d77006c31e81337f92a73d7dfada2c45bd936fd459ac44b27e79074ad9180046aa5ffd37f33ddc2dc0a278f254aa45b448291ced195551d6195c5a40
@@ -34,70 +34,57 @@ class UnlockPaypal::ContributionsController < ::ApplicationController
34
34
  end
35
35
 
36
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({
37
+ authorize @contribution
38
+ @initiative = @contribution.initiative
39
+ @gateways = @initiative.gateways.without_state(:draft).order(:ordering)
40
+ paypal = PayPal::Recurring.new({token: params[:token]}.merge(@contribution.paypal_auth))
41
+ details = paypal.checkout_details
42
+ @contribution.gateway_data = {} unless @contribution.gateway_data
43
+ @contribution.gateway_data["token"] = params[:token]
44
+ @contribution.gateway_data["PayerID"] = params[:PayerID]
45
+ @contribution.gateway_data["checkout_status"] = details.status
46
+ @contribution.gateway_data["email"] = details.email
47
+ @contribution.gateway_data["payer_status"] = details.payer_status
48
+ @contribution.gateway_data["payer_status"] = details.payer_status
49
+ @contribution.gateway_data["first_name"] = details.first_name
50
+ @contribution.gateway_data["last_name"] = details.last_name
51
+ @contribution.gateway_data["country"] = details.country
52
+ @contribution.gateway_data["currency"] = details.currency
53
+ @contribution.gateway_data["amount"] = details.amount
54
+ @contribution.gateway_data["description"] = details.description
55
+ @contribution.gateway_data["ipn_url"] = details.ipn_url
56
+ @contribution.gateway_data["agreed"] = details.agreed?
57
+ @contribution.save!
58
+ paypal = PayPal::Recurring.new({
59
+ token: params[:token],
60
+ payer_id: params[:PayerID],
61
+ description: details.description,
62
+ amount: details.amount,
63
+ currency: details.currency
64
+ }.merge(@contribution.paypal_auth))
65
+ payment = paypal.request_payment
66
+ if payment.approved? && payment.completed?
67
+ recurring = PayPal::Recurring.new({
68
+ ipn_url: details.ipn_url,
69
+ description: details.description,
70
+ amount: details.amount,
71
+ currency: details.currency,
72
+ frequency: 1,
60
73
  token: params[:token],
74
+ period: :monthly,
61
75
  payer_id: params[:PayerID],
62
- description: details.description,
63
- amount: details.amount,
64
- currency: details.currency
76
+ start_at: Time.now,
77
+ failed: 3,
78
+ outstanding: :next_billing
65
79
  }.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
80
+ profile = recurring.create_recurring_profile
81
+ if profile.valid? && profile.profile_id.present? && profile.status == "ActiveProfile"
82
+ profile_data = {}
83
+ profile_data["profile_id"] = profile.profile_id
84
+ profile_data["profile_status"] = profile.status
85
+ @contribution.update gateway_data: @contribution.gateway_data.merge(profile_data)
86
+ @contribution.activate!
87
+ return redirect_to initiative_contribution_path(@initiative.id, @contribution)
101
88
  else
102
89
  if payment.errors.size > 0
103
90
  payment.errors.each do |error|
@@ -106,10 +93,21 @@ class UnlockPaypal::ContributionsController < ::ApplicationController
106
93
  end
107
94
  end
108
95
  else
109
- @contribution.errors.add(:base, "Ooops. Ocorreu um erro ao processar seu pagamento no PayPal.")
96
+ @contribution.errors.add(:base, "Ooops. Ocorreu um erro ao ativar seu perfil recorrente no PayPal.")
110
97
  end
111
98
  return render '/initiatives/contributions/new'
112
99
  end
100
+ else
101
+ if payment.errors.size > 0
102
+ payment.errors.each do |error|
103
+ error[:messages].each do |message|
104
+ @contribution.errors.add(:base, "#{error[:code]} #{message} (PayPal)")
105
+ end
106
+ end
107
+ else
108
+ @contribution.errors.add(:base, "Ooops. Ocorreu um erro ao processar seu pagamento no PayPal.")
109
+ end
110
+ return render '/initiatives/contributions/new'
113
111
  end
114
112
  end
115
113
 
@@ -1,3 +1,3 @@
1
1
  module UnlockPaypal
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unlock_paypal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Weinmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-09 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.0
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.0
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: paypal-recurring
43
43
  requirement: !ruby/object:Gem::Requirement