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
TYPE_CASH_ON =
'Spree::PaymentMethod::CashOn'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



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

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,
      Spree::PaymentMethod::TYPE_CASH_ON
    ]
  end
end

Instance Method Details

#can_redirect_to_app?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/models/vpago/payment_method_decorator.rb', line 120

def can_redirect_to_app?
  preferred_app_scheme.present?
end

#default_payout_profileObject



50
51
52
# File 'app/models/vpago/payment_method_decorator.rb', line 50

def default_payout_profile
  nil
end

#enable_payout?Boolean

Returns:

  • (Boolean)


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

def enable_payout? = support_payout?

#enable_pre_auth?Boolean

Returns:

  • (Boolean)


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

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”



125
126
127
# File 'app/models/vpago/payment_method_decorator.rb', line 125

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

#payment_request_updaterObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/vpago/payment_method_decorator.rb', line 70

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.



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

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

#support_check_transaction_api?Boolean

The payment method must implement ‘check_transaction(payment)`. The returned object should respond to `.success?`, and optionally `.failed?` and `.pending?`.

Returns:

  • (Boolean)


40
41
42
# File 'app/models/vpago/payment_method_decorator.rb', line 40

def support_check_transaction_api?
  respond_to?(:check_transaction)
end

#support_payout?Boolean

Returns:

  • (Boolean)


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

def support_payout? = false

#support_pre_auth?Boolean

Returns:

  • (Boolean)


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

def support_pre_auth? = false

#type_acleda?Boolean

Returns:

  • (Boolean)


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

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

#type_acleda_mobile?Boolean

Returns:

  • (Boolean)


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

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

#type_cash_on?Boolean

Returns:

  • (Boolean)


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

def type_cash_on?
  type == Spree::PaymentMethod::TYPE_CASH_ON
end

#type_check?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/vpago/payment_method_decorator.rb', line 116

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

#type_payway?Boolean

Returns:

  • (Boolean)


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

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

#type_payway_v2?Boolean

Returns:

  • (Boolean)


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

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

#type_true_money?Boolean

Returns:

  • (Boolean)


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

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

#type_vattanac_mini_app?Boolean

Returns:

  • (Boolean)


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

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

#type_wingsdk?Boolean

Returns:

  • (Boolean)


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

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

#vapgo_checkout_serviceObject



58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/vpago/payment_method_decorator.rb', line 58

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)


54
55
56
# File 'app/models/vpago/payment_method_decorator.rb', line 54

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