Class: Spree::PaymentMethod::NpAtobarai

Inherits:
Spree::PaymentMethod
  • Object
show all
Defined in:
app/models/spree/payment_method/np_atobarai.rb

Constant Summary collapse

INVOICE_SENDING_OPTIONS =
[ :postal, :email ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.destroy_np_atobarai_adjustments(order) ⇒ Object



61
62
63
# File 'app/models/spree/payment_method/np_atobarai.rb', line 61

def destroy_np_atobarai_adjustments(order)
  order.adjustments.where(label: np_atobarai_fee_label).destroy_all
end

.invoice_sending_optionsObject



69
70
71
# File 'app/models/spree/payment_method/np_atobarai.rb', line 69

def invoice_sending_options
  Spree::Payment.invoice_sendings.slice(*INVOICE_SENDING_OPTIONS)
end

.np_atobarai_fee_labelObject



65
66
67
# File 'app/models/spree/payment_method/np_atobarai.rb', line 65

def np_atobarai_fee_label
  Spree.t('np_atobarai_fee_adjustment')
end

Instance Method Details

#actionsObject



8
9
10
# File 'app/models/spree/payment_method/np_atobarai.rb', line 8

def actions
  %w[capture void]
end

#can_capture?(payment) ⇒ Boolean

Indicates whether its possible to capture the payment

Returns:

  • (Boolean)


13
14
15
# File 'app/models/spree/payment_method/np_atobarai.rb', line 13

def can_capture?(payment)
  [ 'checkout', 'pending' ].include?(payment.state)
end

#can_void?(payment) ⇒ Boolean

Indicates whether its possible to void the payment.

Returns:

  • (Boolean)


18
19
20
# File 'app/models/spree/payment_method/np_atobarai.rb', line 18

def can_void?(payment)
  payment.state != 'void'
end

#cancelObject



30
31
32
# File 'app/models/spree/payment_method/np_atobarai.rb', line 30

def cancel(*)
  ActiveMerchant::Billing::Response.new(true, "", {}, {})
end

#captureObject



26
27
28
# File 'app/models/spree/payment_method/np_atobarai.rb', line 26

def capture(*)
  ActiveMerchant::Billing::Response.new(true, "", {}, {})
end

#create_np_atobarai_fee_adjustment!(order) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/models/spree/payment_method/np_atobarai.rb', line 50

def create_np_atobarai_fee_adjustment!(order)
  adjustment = order.adjustments.new
  adjustment.source = self
  adjustment.order = order
  adjustment.amount = preferred_np_atobarai_fee
  adjustment.label = np_atobarai_fee_label
  adjustment.save!
  adjustment
end

#custom_form_fields_partial_nameObject



22
23
24
# File 'app/models/spree/payment_method/np_atobarai.rb', line 22

def custom_form_fields_partial_name
  'np_atobarai_form_fields'
end

#np_atobarai_fee_adjustment_applicable?(order, payment) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'app/models/spree/payment_method/np_atobarai.rb', line 42

def np_atobarai_fee_adjustment_applicable?(order, payment)
  return false if preferred_np_atobarai_fee.blank? || order.blank? || payment&.invoice_sending_email?

  return true if preferred_np_atobarai_no_fee_same_month.blank?

  !has_np_atobarai_orders_this_month?(order.billing_address&.phone)
end

#source_required?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/spree/payment_method/np_atobarai.rb', line 38

def source_required?
  false
end

#voidObject



34
35
36
# File 'app/models/spree/payment_method/np_atobarai.rb', line 34

def void(*)
  ActiveMerchant::Billing::Response.new(true, "", {}, {})
end