Merge pull request #13777 from rioug/13481-webhook-payment

Payment status change webhook
This commit is contained in:
Filipe
2026-01-08 11:26:41 +00:00
committed by GitHub
26 changed files with 597 additions and 54 deletions

View File

@@ -35,6 +35,12 @@ module Spree
}
before do
# mock the call with "ofn.payment_transition" so we don't call the related listener
# and services
allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original
allow(ActiveSupport::Notifications).to receive(:instrument)
.with("ofn.payment_transition", any_args).and_return(nil)
allow(order).to receive_message_chain(:line_items, :empty?).and_return(false)
allow(order).to receive_messages total: 100
stub_request(:get, "https://api.stripe.com/v1/payment_intents/12345").

View File

@@ -3,6 +3,13 @@
require 'spec_helper'
RSpec.describe Spree::Payment do
before do
# mock the call with "ofn.payment_transition" so we don't call the related listener and services
allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original
allow(ActiveSupport::Notifications).to receive(:instrument)
.with("ofn.payment_transition", any_args).and_return(nil)
end
context 'original specs from Spree' do
before { Stripe.api_key = "sk_test_12345" }
let(:order) { create(:order) }
@@ -1064,4 +1071,17 @@ RSpec.describe Spree::Payment do
expect(payment.captured_at).to be_present
end
end
describe "payment transition" do
it "notifies of payment status change" do
payment = create(:payment)
allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original
expect(ActiveSupport::Notifications).to receive(:instrument).with(
"ofn.payment_transition", payment: payment, event: "processing"
)
payment.started_processing!
end
end
end

View File

@@ -5,5 +5,9 @@ require 'spec_helper'
RSpec.describe WebhookEndpoint do
describe "validations" do
it { is_expected.to validate_presence_of(:url) }
it {
is_expected.to validate_inclusion_of(:webhook_type)
.in_array(%w(order_cycle_opened payment_status_changed))
}
end
end