-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from mejuri-inc/develop
Preparing the new v0.0.10 release
- Loading branch information
Showing
6 changed files
with
163 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module FlowcommerceSpree | ||
class FlowIoWorker | ||
include Sidekiq::Worker | ||
|
||
sidekiq_retries_exhausted do |message, exception| | ||
Rails.logger.warn("[!] #{self.class} max attempts reached: #{message} - #{exception}") | ||
notification_setting = FlowcommerceSpree::Config.notification_setting | ||
return unless notification_setting[:slack].present? | ||
|
||
slack_message = "[#{Rails.env}] #{message}" | ||
Slack_client.chat_postMessage(channel: notification_setting[:slack][:channel], text: slack_message) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/workers/flowcommerce_spree/update_payment_capture_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module FlowcommerceSpree | ||
class UpdatePaymentCaptureWorker < FlowIoWorker | ||
sidekiq_options retry: 3, queue: :flow_io | ||
|
||
def perform(order_number, capture = {}) | ||
order = Spree::Order.find_by number: order_number | ||
raise 'Order has no payments' if order.payments.empty? | ||
|
||
FlowcommerceSpree::Webhooks::CaptureUpsertedV2.new({ capture: capture }.as_json) | ||
.store_payment_capture(order, capture) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe FlowcommerceSpree::UpdatePaymentCaptureWorker, type: :worker do | ||
let(:gateway) { create(:flow_io_gateway) } | ||
let(:order) { create(:order) } | ||
subject(:job) { described_class.new } | ||
|
||
describe '#perform' do | ||
context 'when order has payments' do | ||
let!(:payment) { create(:payment, order: order, payment_method_id: gateway.id) } | ||
|
||
it 'calls CaptureUpsertedV2#store_payment_capture method' do | ||
expect_any_instance_of(FlowcommerceSpree::Webhooks::CaptureUpsertedV2).to(receive(:store_payment_capture)) | ||
job.perform(order.number, anything) | ||
end | ||
end | ||
|
||
context 'when order has no payments' do | ||
it 'does not call CaptureUpsertedV2#store_payment_capture method' do | ||
expect_any_instance_of(FlowcommerceSpree::Webhooks::CaptureUpsertedV2).not_to(receive(:store_payment_capture)) | ||
expect { job.perform(order.number, anything) }.to raise_error 'Order has no payments' | ||
end | ||
end | ||
end | ||
end |