Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(customer): Fix update customer webhook #2904

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ PLATFORMS
aarch64-linux-musl
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-21
x86_64-darwin-22
x86_64-darwin-23
Expand Down
8 changes: 7 additions & 1 deletion app/services/customers/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def create_from_api(organization:, params:)
new_customer:
)

if new_customer
SendWebhookJob.perform_later('customer.created', customer)
else
SendWebhookJob.perform_later('customer.updated', customer)
end

track_customer_created(customer)
result
rescue BaseService::ServiceFailure => e
Expand Down Expand Up @@ -196,6 +202,7 @@ def create(**args)
new_customer: true
)

SendWebhookJob.perform_later('customer.created', customer)
track_customer_created(customer)
result
rescue ActiveRecord::RecordInvalid => e
Expand Down Expand Up @@ -335,7 +342,6 @@ def track_customer_created(customer)
organization_id: customer.organization_id
}
)
SendWebhookJob.perform_later("customer.created", customer)
end

def should_create_billing_configuration?(billing, customer)
Expand Down
8 changes: 8 additions & 0 deletions spec/services/customers/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@
end
end

it 'calls SendWebhookJob with customer.updated' do
customers_service.create_from_api(
organization:,
params: create_args
)
expect(SendWebhookJob).to have_received(:perform_later).with('customer.updated', customer)
end

context 'with provider customer' do
let(:payment_provider) { create(:stripe_provider, organization:) }
let(:stripe_customer) { create(:stripe_customer, customer:, payment_provider:) }
Expand Down
Loading