unlock_moip 0.0.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d11cefc19d503db776320d7ce6dfa1b1525a5f7b
4
- data.tar.gz: 1aec8ad2672bd9999e13d114ae8860dfa983b845
3
+ metadata.gz: cc03ae3313500f874e417d7619bc987909b4bcbb
4
+ data.tar.gz: d76184ef2694455bd5f0fadcf76cd36cf4f64447
5
5
  SHA512:
6
- metadata.gz: ebd55075bc1c2ef113c5380644192d3abd71cfe5a0838867b22572ee0e3dae6ebd33c98e2bd47fcd39ed24d08426f54ab033b9cd97c2fbc8131010c0c3a5c3df
7
- data.tar.gz: fe639d7124fc8a1a80a005d9b974f9ceefb3c7ee6cce95070a44a26fd8e3ebc31536a9af10d43f8f79838d08317c358570b02fdba3a33e3ae60f970181c0b02b
6
+ metadata.gz: 75581b94b79d765e89184c0f171931384b0d9c6d6bb1b5a1271cb788b5a5e24003b5dc38ebf67a0b33edd0548a3cd80518c838b8c8ee66b865d60561581938f7
7
+ data.tar.gz: bd85f97f2736af5f1ee49cd474c81650e97c4d5289b2e6de00846a8e34379901b9023a30321ec8da0ff7ed3d3ff49e0e71509080235d0dfd5d9d348ea241d5a0
@@ -1,16 +1,13 @@
1
1
  $(document).ready ->
2
- if action() == "new" and controller() == "contributions" and namespace() == "initiatives"
3
- $('#contribution_value').maskMoney
4
- thousands: ''
5
- decimal: ''
6
- precision: 0
7
2
  if action() == "edit" and controller() == "contributions" and namespace() == "unlockmoip"
8
- $('#pay_form [type=submit]').on "click", (event) ->
3
+ $('#pay_form').on "submit", (event) ->
9
4
  event.preventDefault()
10
5
  event.stopPropagation()
11
- billing_info_ok = false
12
- form = $('#pay_form')
6
+ form = $(@)
13
7
  submit = form.find('[type=submit]')
8
+ return unless submit.is(':visible')
9
+ submit.hide()
10
+ billing_info_ok = false
14
11
  status = form.find('.gateway_data')
15
12
  terms = form.find('#terms')
16
13
  status.removeClass 'success'
@@ -20,14 +17,12 @@ $(document).ready ->
20
17
  status.addClass 'failure'
21
18
  status.html("<h4>Você precisa aceitar os termos de uso para continuar.</h4>")
22
19
  status.show()
20
+ submit.show()
23
21
  else
24
22
  status.html("<h4>Enviando dados de pagamento para o Moip...</h4><ul></ul>")
25
- token = form.data('token')
26
- plan_code = form.data('plan')
27
- submit.hide()
28
23
  status.show()
29
24
  if MoipAssinaturas?
30
- moip = new MoipAssinaturas(token)
25
+ moip = new MoipAssinaturas(form.data('token'))
31
26
  moip.callback (response) ->
32
27
  status.find('h4').html("#{response.message} (Moip)")
33
28
  unless response.has_errors()
@@ -36,22 +31,10 @@ $(document).ready ->
36
31
  subscription = new Subscription()
37
32
  subscription.with_code(form.data('subscription'))
38
33
  subscription.with_customer(customer)
39
- subscription.with_plan_code(plan_code)
34
+ subscription.with_plan_code(form.data('plan'))
40
35
  moip.subscribe(subscription)
41
36
  else
42
- next_invoice = "#{response.next_invoice_date.day}/#{response.next_invoice_date.month}/#{response.next_invoice_date.year}"
43
- $.ajax
44
- url: form.data('activate'),
45
- type: 'PUT',
46
- dataType: 'json',
47
- success: (response) ->
48
- window.location.href = form.data('show')
49
- error: (response) ->
50
- status.find('h4').html("Não foi possível ativar sua assinatura")
51
- status.addClass 'failure'
52
- for error in response.responseJSON.errors
53
- status.find('ul').append("<li>#{error}</li>")
54
- submit.show()
37
+ $('form.edit_contribution').submit()
55
38
  else
56
39
  status.addClass 'failure'
57
40
  for error in response.errors
@@ -1,13 +1,7 @@
1
1
  body[data-action="edit"][data-controller="contributions"][data-namespace="unlockmoip"]
2
2
  article
3
- width: 92%
4
- +media($tablet)
5
- width: 90%
6
- +media($desktop)
7
- width: 70%
8
- margin-left: auto
9
- margin-right: auto
10
3
  form
4
+ margin-top: 0
11
5
  .field
12
6
  float: left
13
7
  width: 100%
@@ -1,4 +1,4 @@
1
- body[data-action="new"][data-controller="contributions"][data-namespace="initiatives"], body[data-action="create"][data-controller="contributions"][data-namespace="unlockmoip"]
1
+ body[data-action="new"][data-controller="contributions"][data-namespace="initiatives"], body[data-action="create"][data-controller="contributions"]
2
2
  article
3
3
  form
4
4
  em
@@ -1,14 +1,6 @@
1
1
  class UnlockMoip::ContributionsController < ::ApplicationController
2
2
 
3
- inherit_resources
4
- actions :create, :edit
5
- custom_actions member: %i[activate suspend]
6
- respond_to :html, except: [:activate, :suspend]
7
- respond_to :json, only: [:activate, :suspend]
8
-
9
- after_action :verify_authorized
10
- after_action :verify_policy_scoped, only: %i[]
11
- before_action :authenticate_user!, only: %i[edit]
3
+ is_unlock_gateway
12
4
 
13
5
  def create
14
6
 
@@ -17,14 +9,7 @@ class UnlockMoip::ContributionsController < ::ApplicationController
17
9
  params[:contribution][:user_attributes][:birthdate] = params[:pickadate_birthdate_submit]
18
10
  end
19
11
 
20
- # Creating the contribution
21
- @initiative = Initiative.find(contribution_params[:initiative_id])
22
- @gateways = @initiative.gateways.without_state(:draft).order(:ordering)
23
- @contribution = @initiative.contributions.new(contribution_params)
24
- @contribution.gateway_state = @contribution.gateway.state
25
- authorize @contribution
26
-
27
- if @contribution.save
12
+ if create_contribution
28
13
 
29
14
  data = {}
30
15
  # Storing the customer_code and subscription_code
@@ -152,48 +137,8 @@ class UnlockMoip::ContributionsController < ::ApplicationController
152
137
  flash[:success] = "Apoio iniciado com sucesso! Agora é só realizar o pagamento :D"
153
138
  return redirect_to edit_moip_contribution_path(@contribution)
154
139
 
155
- else
156
- return render '/initiatives/contributions/new'
157
140
  end
158
141
 
159
142
  end
160
143
 
161
- def edit
162
- edit! { authorize resource }
163
- end
164
-
165
- def activate
166
- transition_state("activate", :active)
167
- end
168
-
169
- def suspend
170
- transition_state("suspend", :suspended)
171
- end
172
-
173
- private
174
-
175
- def transition_state(transition, state)
176
- authorize resource
177
- errors = []
178
- if resource.send("can_#{transition}?")
179
- begin
180
- if resource.moip_state_name != state
181
- response = Moip::Assinaturas::Subscription.send(transition.to_sym, resource.subscription_code, resource.moip_auth)
182
- resource.send("#{transition}!") if response[:success]
183
- else
184
- resource.send("#{transition}!")
185
- end
186
- rescue
187
- errors << "Não foi possível alterar o status de seu apoio."
188
- end
189
- else
190
- errors << "Não é permitido alterar o status deste apoio."
191
- end
192
- render(json: {success: (errors.size == 0), errors: errors}, status: ((errors.size == 0) ? 200 : 422))
193
- end
194
-
195
- def contribution_params
196
- params.require(:contribution).permit(*policy(@contribution || Contribution.new).permitted_attributes)
197
- end
198
-
199
144
  end
@@ -1,23 +1,6 @@
1
1
  = form_for @contribution, url: moip_contributions_path, method: :post do |form|
2
- - if gateway.sandbox?
3
- .warning
4
- h3 Atenção! Este unlock encontra-se em modo de testes (Sandbox) no Moip.
5
- ul
6
- li Nenhum apoio realizado neste modo será concretizado.
7
- li Você pode testar livremente, sem medo de ser debitado.
8
- - if @contribution.errors.any?
9
- #error_explanation.warning
10
- h3 = "#{pluralize(@contribution.errors.count, "erro impediu", "erros impediram")} que este apoio fosse salvo:"
11
- ul
12
- - @contribution.errors.full_messages.each do |msg|
13
- li= msg
14
- = form.hidden_field :user_id
15
- = form.hidden_field :initiative_id
16
- = form.hidden_field :gateway_id, value: gateway.id
17
- h3 Com quanto você quer apoiar por mês?
18
- = form.label :value
19
- = form.text_field :value, class: "has_em"
20
- em Assinatura mensal cobrada via cartão de crédito pelo meio de pagamentos #{link_to 'Moip', 'https://moip.com.br/', target: :_blank }. Você pode suspender #{ link_to 'a qualquer momento', my_contributions_path, target: :_blank }.
2
+ = render partial: 'initiatives/contributions/sandbox_warning', locals: { gateway: gateway }
3
+ = render partial: 'initiatives/contributions/base_form', locals: { form: form, gateway: gateway }
21
4
  h3 Preencha e revise os dados para pagamento
22
5
  = form.fields_for :user do |user_fields|
23
6
  = user_fields.hidden_field :id
@@ -2,13 +2,9 @@
2
2
  = "Dados de pagamento"
3
3
  - content_for :external_js do
4
4
  script type="text/javascript" src="https://#{( @contribution.gateway.sandbox? ? 'sandbox' : 'api' )}.moip.com.br/moip-assinaturas.min.js"
5
- form#pay_form autocomplete="off" data-token=@contribution.gateway.settings["token"] data-plan=@contribution.plan_code data-customer=@contribution.customer_code data-subscription=@contribution.subscription_code data-activate=activate_moip_contribution_path data-show=initiative_contribution_path(@contribution.initiative.id, @contribution)
6
- - if @contribution.gateway.sandbox?
7
- .warning
8
- h3 Atenção! Este unlock encontra-se em modo de testes (Sandbox) no Moip.
9
- ul
10
- li Nenhum apoio realizado neste modo será concretizado.
11
- li Você pode testar livremente, sem medo de ser debitado.
5
+ = form_for @contribution, url: activate_moip_contribution_path(@contribution), method: :put, html: { style: 'display: none'} do |form|
6
+ form#pay_form autocomplete="off" data-token=@contribution.gateway.settings["token"] data-plan=@contribution.plan_code data-customer=@contribution.customer_code data-subscription=@contribution.subscription_code
7
+ = render partial: 'initiatives/contributions/sandbox_warning', locals: { gateway: @contribution.gateway }
12
8
  .field
13
9
  = label_tag :holder_name, "Nome escrito no cartão de crédito"
14
10
  = text_field_tag :holder_name, "", autocomplete: "off"
@@ -1,4 +1 @@
1
- begin
2
- Gateway.register 'UnlockMoip'
3
- rescue
4
- end
1
+ UnlockGateway.register 'UnlockMoip'
@@ -6,7 +6,13 @@ module UnlockMoip
6
6
 
7
7
  def moip_auth
8
8
  return {} unless self.gateway && self.gateway.settings
9
- { moip_auth: { token: self.gateway.settings["token"], key: self.gateway.settings["key"], sandbox: self.gateway.sandbox? }}
9
+ {
10
+ moip_auth: {
11
+ token: self.gateway.settings["token"],
12
+ key: self.gateway.settings["key"],
13
+ sandbox: self.gateway.sandbox?
14
+ }
15
+ }
10
16
  end
11
17
 
12
18
  def plan_code
@@ -33,7 +39,11 @@ module UnlockMoip
33
39
  end
34
40
  end
35
41
 
36
- def moip_state_name
42
+ def gateway_identifier
43
+ self.gateway_data && self.gateway_data["subscription_code"]
44
+ end
45
+
46
+ def state_on_gateway
37
47
  begin
38
48
  response = Moip::Assinaturas::Subscription.details(self.subscription_code, self.moip_auth)
39
49
  rescue
@@ -50,15 +60,10 @@ module UnlockMoip
50
60
  end
51
61
  end
52
62
 
53
- def update_state_from_gateway!
54
- if self.state_name != self.moip_state_name
55
- case self.moip_state_name
56
- when :active
57
- self.activate! if self.can_activate?
58
- when :suspended
59
- self.suspend! if self.can_suspend?
60
- end
61
- end
63
+ def update_state_on_gateway!(state)
64
+ transition = self.transition_by_state(state)
65
+ response = Moip::Assinaturas::Subscription.send(transition, self.subscription_code, self.moip_auth)
66
+ response[:success]
62
67
  end
63
68
 
64
69
  end
@@ -16,6 +16,10 @@ module UnlockMoip
16
16
  "unlock_moip/logo.png"
17
17
  end
18
18
 
19
+ def url
20
+ "https://moip.com.br/"
21
+ end
22
+
19
23
  def path
20
24
  "/moip"
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module UnlockMoip
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unlock_moip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.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-08 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.1.6
27
27
  - !ruby/object:Gem::Dependency
28
- name: moip-assinaturas
28
+ name: unlock_gateway
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.2
33
+ version: 0.1.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.4.2
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: unlock_gateway
42
+ name: moip-assinaturas
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.5
47
+ version: 0.4.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.5
54
+ version: 0.4.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,6 @@ files:
83
83
  - app/assets/stylesheets/unlock_moip/unlock_moip.sass
84
84
  - app/controllers/unlock_moip/contributions_controller.rb
85
85
  - app/views/unlock_moip/contributions/_form.html.slim
86
- - app/views/unlock_moip/contributions/_gateway_data.html.slim
87
86
  - app/views/unlock_moip/contributions/edit.html.slim
88
87
  - config/initializers/moip_assinaturas.rb
89
88
  - config/initializers/register.rb
@@ -1,5 +0,0 @@
1
- ul
2
- li Seu código de assinatura é <strong>#{@contribution.subscription_code}</strong>
3
- li Seu pagamento ainda será processado pelo <a href='https://www.moip.com.br/' target='_blank'>Moip</a>.
4
- li Se você quiser suspender seu apoio, basta acessar o menu <a href='/my_contributions'>Unlocks apoiados</a> a qualquer momento.
5
- li Sua próxima cobrança será realizada em #{@contribution.next_invoice_date}.