Class: FlowcommerceSpree::Webhooks::CaptureUpsertedV2
- Inherits:
-
Object
- Object
- FlowcommerceSpree::Webhooks::CaptureUpsertedV2
- Defined in:
- app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
(also: #full_messages)
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ CaptureUpsertedV2
constructor
A new instance of CaptureUpsertedV2.
- #process ⇒ Object
- #store_payment_capture(order, capture) ⇒ Object
Constructor Details
#initialize(data) ⇒ CaptureUpsertedV2
Returns a new instance of CaptureUpsertedV2.
13 14 15 16 |
# File 'app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb', line 13 def initialize(data) @data = data @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly) Also known as: full_messages
Returns the value of attribute errors.
6 7 8 |
# File 'app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb', line 6 def errors @errors end |
Class Method Details
.process(data) ⇒ Object
9 10 11 |
# File 'app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb', line 9 def self.process(data) new(data).process end |
Instance Method Details
#process ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb', line 18 def process errors << { message: 'Capture param missing' } && (return self) unless (capture = @data['capture']&.to_hash) order_number = capture.dig('authorization', 'order', 'number') errors << { message: 'Order number param missing' } && (return self) unless order_number if (order = Spree::Order.find_by(number: order_number)) if order.payments.any? store_payment_capture(order, capture) else FlowcommerceSpree::UpdatePaymentCaptureWorker.perform_in(1.minute, order.number, capture) order end else errors << { message: "Order #{order_number} not found" } self end end |
#store_payment_capture(order, capture) ⇒ Object
37 38 39 40 41 |
# File 'app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb', line 37 def store_payment_capture(order, capture) upsert_order_captures(order, capture) map_payment_captures_to_spree(order) order end |