Skip to content

Commit 077b95e

Browse files
committed
Merge pull request #32 from Lostmyname/refund-notification-fix
Fix for state machine errors after refunding in Adyen interface
2 parents 2d16c78 + df7b25a commit 077b95e

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

app/models/spree/adyen/notification_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def handle_modification_event
7272
refund_reason_id: ::Spree::RefundReason.first.id # FIXME
7373
)
7474
# payment was processing, move back to completed
75-
payment.complete!
75+
payment.complete! unless payment.completed?
7676
notification.processed!
7777
end
7878
end

spec/models/spree/adyen/notification_processor_spec.rb

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,37 @@
146146
end
147147

148148
context "when event is REFUND" do
149-
include_examples "processed event"
149+
shared_examples "refund" do
150+
let(:event_type) { :refund }
151+
it "creates a refund" do
152+
expect { subject }.
153+
to change { payment.reload.refunds.count }.
154+
from(0).
155+
to(1)
156+
end
157+
end
150158

151-
let(:event_type) { :refund }
152-
let(:payment_state) { "processing" }
159+
context "when refunded from Solidus" do
160+
let(:payment_state) { "processing" }
161+
include_examples "refund"
153162

154-
it "creates a refund" do
155-
expect { subject }.
156-
to change { payment.reload.refunds.count }.
157-
from(0).
158-
to(1)
163+
it "changes the payment state to completed" do
164+
expect { subject }.
165+
to change { payment.reload.state }.
166+
from("processing").
167+
to("completed")
168+
end
159169
end
160170

161-
it "changes the payment state to completed" do
162-
expect { subject }.
163-
to change { payment.reload.state }.
164-
from("processing").
165-
to("completed")
171+
context "when refunded from Adyen" do
172+
let(:payment_state) { "completed" }
173+
include_examples "refund"
174+
175+
it "does not change the payment state" do
176+
expect { subject }.
177+
not_to change { payment.reload.state }.
178+
from("completed")
179+
end
166180
end
167181
end
168182

0 commit comments

Comments
 (0)