Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Handle credit cards with problems #11

Merged
merged 6 commits into from

2 participants

@Irio Irio added the WIP label
@Irio Irio self-assigned this
@Irio Irio removed the WIP label
...neighborly/balanced/creditcard/payments_controller.rb
@@ -22,8 +22,11 @@ def create
contribution.id
)
else
- prepare_new_view
- render 'new'
+ flash[:alert] = t('title', scope: 'payments.common.error')
@josemarluedke Owner

We should get the translations here in the gem as well. So the main app does not need to have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...pts/neighborly/balanced/creditcard/payments.js.coffee
((6 lines not shown))
selectedCard.val(response.data.uri)
$('[data-balanced-credit-card-form] form').submit()
+
+ balanced_callback_for_402 = (response) ->
+ alertBox = $('<div>', { 'class': 'row', 'html':
+ $('<div>', { 'class': 'alert-box large-10 columns large-centered animated fadeIn alert dismissible', 'html': 'The card submitted is invalid.' })
+ } )
+ flashWrapper = $('.flash') || $('body > header').next($('<div>', { 'class': 'flash', 'html' }))
+ flashWrapper.append(alertBox)
+ $('.neighborly-balanced-creditcard-form [type="submit"').
@josemarluedke Owner

We have the .neighborly-balanced-creditcard-form in the el. You should use this.$('[type="submit"') instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...pts/neighborly/balanced/creditcard/payments.js.coffee
((6 lines not shown))
selectedCard.val(response.data.uri)
$('[data-balanced-credit-card-form] form').submit()
+
+ balanced_callback_for_402 = (response) ->
+ alertBox = $('<div>', { 'class': 'row', 'html':
+ $('<div>', { 'class': 'alert-box large-10 columns large-centered animated fadeIn alert dismissible', 'html': 'The card submitted is invalid.' })
@josemarluedke Owner

Any suggestions to get the text in I18n?

@Irio Collaborator
Irio added a note

Changing the file to js.coffee.erb. What do you think about it?

@josemarluedke Owner

I think that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...pts/neighborly/balanced/creditcard/payments.js.coffee
((6 lines not shown))
selectedCard.val(response.data.uri)
$('[data-balanced-credit-card-form] form').submit()
+
+ balanced_callback_for_402 = (response) ->
+ alertBox = $('<div>', { 'class': 'row', 'html':
+ $('<div>', { 'class': 'alert-box large-10 columns large-centered animated fadeIn alert dismissible', 'html': 'The card submitted is invalid.' })
+ } )
+ flashWrapper = $('.flash') || $('body > header').next($('<div>', { 'class': 'flash', 'html' }))
+ flashWrapper.append(alertBox)
+ $('.neighborly-balanced-creditcard-form [type="submit"').
+ removeAttr('disabled').
+ remoreAttr('data-disable-with').
+ attr('value', 'Confirm payment')
@josemarluedke Owner

Okay, I guess Rails JS has a method to remove the disable on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@josemarluedke josemarluedke merged commit 82a6c05 into from
@josemarluedke josemarluedke deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
18 ...neighborly/balanced/creditcard/payments.js.coffee → ...hborly/balanced/creditcard/payments.js.coffee.erb
@@ -41,6 +41,22 @@ Neighborly.Neighborly.Balanced.Creditcard.Payments.New = Backbone.View.extend
security_code: this.$('#payment_security_code').val()
this.$('[data-balanced-credit-card-input]').val('')
- balanced.card.create creditCardData, (response) ->
+ balanced_callback_for_201 = (response) ->
selectedCard.val(response.data.uri)
$('[data-balanced-credit-card-form] form').submit()
+
+ balanced_callback_for_402 = (response) ->
+ alertBox = $('<div>', { 'class': 'row', 'html':
+ $('<div>', { 'class': 'alert-box large-10 columns large-centered animated fadeIn alert dismissible', 'html': '<%= I18n.t('neighborly.balanced.creditcard.payments.new.errors.card_tokenization_error') %>' })
+ } )
+ flashWrapper = $('.flash') || $('body > header').next($('<div>', { 'class': 'flash', 'html' }))
+ flashWrapper.append(alertBox)
+ $('.neighborly-balanced-creditcard-form [type="submit"]').
+ removeAttr('disabled').
+ removeAttr('data-disable-with').
+ attr('value', 'Confirm payment')
+
+ balanced.card.create creditCardData, (response) ->
+ switch response.status
+ when 201 then balanced_callback_for_201(response)
+ when 402 then balanced_callback_for_402(response)
View
7 app/controllers/neighborly/balanced/creditcard/payments_controller.rb
@@ -22,8 +22,11 @@ def create
contribution.id
)
else
- prepare_new_view
- render 'new'
+ flash[:alert] = t('.errors.default')
+ redirect_to main_app.edit_project_contribution_path(
+ contribution.project.permalink,
+ contribution.id
+ )
end
end
View
5 config/locales/en.yml
@@ -18,3 +18,8 @@ en:
title: 'Credit & Debit Cards'
add_new_card: 'Add new Card'
card_ending_in: '%{brand} xxxxxxxxxxxx%{last_four}'
+ errors:
+ card_tokenization_error: 'The card submitted is invalid.'
+ create:
+ errors:
+ default: "Sorry, something must've gone wrong."
View
16 spec/controllers/neighborly/balanced/creditcard/payments_controller_spec.rb
@@ -50,6 +50,12 @@
end
describe "POST 'create'" do
+ let(:project) { double('Project', permalink: 'thirty-three').as_null_object }
+ let(:contribution) do
+ double('Contribution', model_name: 'Contribution',
+ id: 42,
+ project: project).as_null_object
+ end
let(:params) do
{
'payment' => {
@@ -135,11 +141,6 @@
end
it "redirects to contribution page" do
- project = double('Project', permalink: 'thirty-three').as_null_object
- contribution = double('Contribution',
- model_name: 'Contribution',
- id: 42,
- project: project).as_null_object
Contribution.stub(:find).with('42').and_return(contribution)
post :create, params
expect(response).to redirect_to('/projects/thirty-three/contributions/42')
@@ -153,9 +154,10 @@
and_return(false)
end
- it "renders 'new' view" do
+ it "redirects to contribution edit page" do
+ Contribution.stub(:find).with('42').and_return(contribution)
post :create, params
- expect(response).to render_template('new')
+ expect(response).to redirect_to('/projects/thirty-three/contributions/42/edit')
end
end
end
Something went wrong with that request. Please try again.