mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Create a new payment when none is present
This commit is contained in:
@@ -5,7 +5,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def update!
|
||||
return if payment.blank?
|
||||
create_payment if payment.blank?
|
||||
|
||||
if card_required? && !card_set?
|
||||
return unless ensure_credit_card
|
||||
@@ -20,6 +20,13 @@ module OpenFoodNetwork
|
||||
@payment ||= @order.pending_payments.last
|
||||
end
|
||||
|
||||
def create_payment
|
||||
@payment = @order.payments.create(
|
||||
payment_method_id: @order.standing_order.payment_method_id,
|
||||
amount: @order.outstanding_balance
|
||||
)
|
||||
end
|
||||
|
||||
def card_required?
|
||||
payment.payment_method.is_a? Spree::Gateway::StripeConnect
|
||||
end
|
||||
|
||||
@@ -46,13 +46,24 @@ module OpenFoodNetwork
|
||||
describe "#update!" do
|
||||
let!(:payment){ create(:payment, amount: 10) }
|
||||
|
||||
context "when no payment is present" do
|
||||
before { allow(updater).to receive(:payment) { nil } }
|
||||
it { expect(updater.update!).to be nil }
|
||||
context "when no pending payments are present" do
|
||||
let(:payment_method) { create(:payment_method) }
|
||||
let(:standing_order) { double(:standing_order, payment_method_id: payment_method.id) }
|
||||
|
||||
before do
|
||||
allow(order).to receive(:pending_payments).once { [] }
|
||||
allow(order).to receive(:outstanding_balance) { 5 }
|
||||
allow(order).to receive(:standing_order) { standing_order }
|
||||
end
|
||||
|
||||
it "creates a new payment on the order" do
|
||||
expect{updater.update!}.to change(Spree::Payment, :count).by(1)
|
||||
expect(order.payments.first.amount).to eq 5
|
||||
end
|
||||
end
|
||||
|
||||
context "when a payment is present" do
|
||||
before { allow(updater).to receive(:payment) { payment } }
|
||||
before { allow(order).to receive(:pending_payments).once { [payment] } }
|
||||
|
||||
context "when a credit card is not required" do
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user