Class: Workarea::Fulfillment::Policies::CreateGiftCard

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/fulfillment/policies/create_gift_card.rb

Instance Method Summary collapse

Instance Method Details

#process(order_item:, fulfillment: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/workarea/fulfillment/policies/create_gift_card.rb', line 5

def process(order_item:, fulfillment: nil)
  return unless Workarea::GiftCards.uses_system_cards?
  return unless order_item.gift_card?

  order_item.quantity.times do
    Payment::GiftCard.create!(
      amount: order_item.original_unit_price,
      order_id: order_item.order.id,
      to: order_item.customizations['email'],
      from: order_item.customizations['from'],
      message: order_item.customizations['message'],
      notify: true,
      purchased: true
    )
  end

  return unless fulfillment.present?
  fulfillment.mark_item_shipped(
    id: order_item.id.to_s,
    quantity: order_item.quantity
  )
end