Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Save fees information on contribution after payment checkout #13

Merged
merged 1 commit into from

2 participants

@Irio
Collaborator

Depends on neighborly/neighborly#74 and finishes #9.

@Irio
Collaborator

A contribution of US$1000 with user choosing to pay fees will be saved like this:

> c = Contribution.last
> [c.value.to_f, c.payment_service_fee_paid_by_user?, c.payment_service_fee.to_f]
=> [1000.0, true, 29.3]

Choosing to not pay fees:

> c = Contribution.last
> [c.value.to_f, c.payment_service_fee_paid_by_user?, c.payment_service_fee.to_f]
=> [1000.0, false, 29.3]
@josemarluedke josemarluedke merged commit 56338f5 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
8 app/models/neighborly/balanced/payment.rb
@@ -15,8 +15,12 @@ def checkout!
else
@contribution.confirm!
ensure
- @contribution.update_attributes(payment_id: @debit.try(:id),
- payment_method: @engine_name)
+ @contribution.update_attributes(
+ payment_id: @debit.try(:id),
+ payment_method: @engine_name,
+ payment_service_fee: fee_calculator.fees,
+ payment_service_fee_paid_by_user: @attrs[:pay_fee]
+ )
end
def contribution_amount_in_cents
View
56 spec/models/neighborly/balanced/payment_spec.rb
@@ -35,6 +35,39 @@
end
describe "checkout" do
+ shared_examples "updates contribution object" do
+ let(:attributes) { { pay_fee: '1', use_card: 'my-new-card' } }
+
+ it "debits customer on selected funding instrument" do
+ customer.should_receive(:debit).
+ with(hash_including(source: 'my-new-card')).
+ and_return(debit)
+ subject.checkout!
+ end
+
+ it "defines given engine's name as payment method of the contribution" do
+ contribution.should_receive(:update_attributes).
+ with(hash_including(payment_method: 'balanced-creditcard'))
+ subject.checkout!
+ end
+
+ it "saves paid fees on contribution object" do
+ calculator = double('FeeCalculator', fees: 0.42).as_null_object
+ subject.stub(:fee_calculator).and_return(calculator)
+ contribution.should_receive(:update_attributes).
+ with(hash_including(payment_service_fee: 0.42))
+ subject.checkout!
+ end
+
+ it "saves who paid the fees" do
+ calculator = double('FeeCalculator', fees: 0.42).as_null_object
+ subject.stub(:fee_calculator).and_return(calculator)
+ contribution.should_receive(:update_attributes).
+ with(hash_including(payment_service_fee_paid_by_user: '1'))
+ subject.checkout!
+ end
+ end
+
context "when customer is paying fees" do
let(:attributes) { { pay_fee: '1', use_card: 'my-new-card' } }
@@ -47,16 +80,11 @@
end
end
- it "debits customer on selected funding instrument" do
- customer.should_receive(:debit).
- with(hash_including(source: 'my-new-card')).
- and_return(debit)
- subject.checkout!
- end
-
context "with successful debit" do
before { customer.stub(:debit).and_return(debit) }
+ include_examples "updates contribution object"
+
it "confirms the contribution" do
expect(contribution).to receive(:confirm!)
subject.checkout!
@@ -68,12 +96,6 @@
with(hash_including(payment_id: 'i-am-an-id!'))
subject.checkout!
end
-
- it "defines given engine's name as payment method of the contribution" do
- contribution.should_receive(:update_attributes).
- with(hash_including(payment_method: 'balanced-creditcard'))
- subject.checkout!
- end
end
context "when raising Balanced::PaymentRequired exception" do
@@ -81,16 +103,12 @@
customer.stub(:debit).and_raise(Balanced::PaymentRequired.new({}))
end
+ include_examples "updates contribution object"
+
it "cancels the contribution" do
expect(contribution).to receive(:cancel!)
subject.checkout!
end
-
- it "defines given engine's name as payment method of the contribution" do
- contribution.should_receive(:update_attributes).
- with(hash_including(payment_method: 'balanced-creditcard'))
- subject.checkout!
- end
end
end
Something went wrong with that request. Please try again.