Module: Vpago::PaymentMethodDecorator

Defined in:
app/models/vpago/payment_method_decorator.rb

Constant Summary collapse

TYPE_PAYWAY =
'Spree::Gateway::Payway'.freeze
TYPE_PAYWAY_V2 =
'Spree::Gateway::PaywayV2'.freeze
TYPE_WINGSDK =
'Spree::Gateway::WingSdk'.freeze
TYPE_ACLEDA =
'Spree::Gateway::Acleda'.freeze
TYPE_ACLEDA_MOBILE =
'Spree::Gateway::AcledaMobile'.freeze
TYPE_TRUE_MONEY =
'Spree::Gateway::TrueMoney'.freeze
TYPE_VATTANAC =
'Spree::Gateway::Vattanac'.freeze
TYPE_VATTANAC_MINI_APP =
'Spree::Gateway::VattanacMiniApp'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/vpago/payment_method_decorator.rb', line 12

def self.prepended(base)
  base.preference :icon_name, :string, default: 'cheque'
  base.preference :app_scheme, :string
  base.belongs_to :vendor, class_name: 'Spree::Vendor', optional: true, inverse_of: :payment_methods

  def base.vpago_payments
    [
      Spree::PaymentMethod::TYPE_PAYWAY_V2,
      Spree::PaymentMethod::TYPE_PAYWAY,
      Spree::PaymentMethod::TYPE_WINGSDK,
      Spree::PaymentMethod::TYPE_ACLEDA,
      Spree::PaymentMethod::TYPE_ACLEDA_MOBILE,
      Spree::PaymentMethod::TYPE_VATTANAC,
      Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP,
      Spree::PaymentMethod::TYPE_TRUE_MONEY
    ]
  end
end

Instance Method Details

#can_redirect_to_app?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/vpago/payment_method_decorator.rb', line 108

def can_redirect_to_app?
  preferred_app_scheme.present?
end

#default_payout_profileObject



42
43
44
# File 'app/models/vpago/payment_method_decorator.rb', line 42

def default_payout_profile
  nil
end

#enable_payout?Boolean

Returns:

  • (Boolean)


31
# File 'app/models/vpago/payment_method_decorator.rb', line 31

def enable_payout? = support_payout?

#enable_pre_auth?Boolean

Returns:

  • (Boolean)


32
# File 'app/models/vpago/payment_method_decorator.rb', line 32

def enable_pre_auth? = support_pre_auth? && self[:enable_pre_auth]

#payment_icon_pathString

Returns the image asset path, e.g. “payment_logos/payway-abapay-khqr.png”.

Returns:

  • (String)

    the image asset path, e.g. “payment_logos/payway-abapay-khqr.png”



113
114
115
# File 'app/models/vpago/payment_method_decorator.rb', line 113

def payment_icon_path
  "payment_logos/#{preferred_icon_name.tr('_', ' ').parameterize}.png"
end

#payment_request_updaterObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/vpago/payment_method_decorator.rb', line 62

def payment_request_updater
  if type_payway?
    ::Vpago::Payway::PaymentRequestUpdater
  elsif type_payway_v2?
    ::Vpago::PaywayV2::PaymentRequestUpdater
  elsif type_wingsdk?
    ::Vpago::WingSdk::PaymentRequestUpdater
  elsif type_acleda?
    ::Vpago::Acleda::PaymentRequestUpdater
  elsif type_acleda_mobile?
    ::Vpago::AcledaMobile::PaymentRequestUpdater
  end
end

#purchase(_amount, _source, _gateway_options = {}) ⇒ Object

TODO: we have already implement purchase for payway_v2. make sure to implement this on other payment method as well.



38
39
40
# File 'app/models/vpago/payment_method_decorator.rb', line 38

def purchase(_amount, _source, _gateway_options = {})
  ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Success')
end

#support_payout?Boolean

Returns:

  • (Boolean)


33
# File 'app/models/vpago/payment_method_decorator.rb', line 33

def support_payout? = false

#support_pre_auth?Boolean

Returns:

  • (Boolean)


34
# File 'app/models/vpago/payment_method_decorator.rb', line 34

def support_pre_auth? = false

#type_acleda?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/vpago/payment_method_decorator.rb', line 80

def type_acleda?
  type == Spree::PaymentMethod::TYPE_ACLEDA
end

#type_acleda_mobile?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/vpago/payment_method_decorator.rb', line 76

def type_acleda_mobile?
  type == Spree::PaymentMethod::TYPE_ACLEDA_MOBILE
end

#type_check?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/vpago/payment_method_decorator.rb', line 104

def type_check?
  type == 'Spree::PaymentMethod::Check'
end

#type_payway?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/vpago/payment_method_decorator.rb', line 84

def type_payway?
  type == Spree::PaymentMethod::TYPE_PAYWAY
end

#type_payway_v2?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/vpago/payment_method_decorator.rb', line 88

def type_payway_v2?
  type == Spree::PaymentMethod::TYPE_PAYWAY_V2
end

#type_true_money?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/models/vpago/payment_method_decorator.rb', line 100

def type_true_money?
  type == Spree::PaymentMethod::TYPE_TRUE_MONEY
end

#type_vattanac_mini_app?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/models/vpago/payment_method_decorator.rb', line 96

def type_vattanac_mini_app?
  type == Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
end

#type_wingsdk?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/vpago/payment_method_decorator.rb', line 92

def type_wingsdk?
  type == Spree::PaymentMethod::TYPE_WINGSDK
end

#vapgo_checkout_serviceObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/vpago/payment_method_decorator.rb', line 50

def vapgo_checkout_service
  if type_payway?
    ::Vpago::Payway::Checkout
  elsif type_payway_v2?
    ::Vpago::PaywayV2::Checkout
  elsif type_wingsdk?
    ::Vpago::WingSdk::Checkout
  elsif type_acleda?
    ::Vpago::Acleda::Checkout
  end
end

#vpago_payment?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/vpago/payment_method_decorator.rb', line 46

def vpago_payment?
  self.class.vpago_payments.include?(type)
end