Module: Vpago::PaymentDecorator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/vpago/payment_decorator.rb', line 17

def self.prepended(base)
  base.has_many :payouts, class_name: 'Spree::Payout', inverse_of: :payment
  base.after_create -> { Vpago::PayoutsGenerator.new(self).call }, if: :should_generate_payouts?

  base.delegate :checkout_url,
                :web_checkout_url,
                :processing_url,
                :success_url,
                :success_deeplink_url,
                :check_transaction_url,
                :process_payment_url,
                to: :url_constructor

  # State machine event for payment retry / admin reprocess.
  # `failed` is auto-reset by process!/capture! below (Sidekiq retry);
  # void/invalid/processing are reset only by the admin reprocess action.
  base.state_machine.event :reset_for_retry do
    transition from: %i[failed void invalid processing], to: :checkout
  end
end

Instance Method Details

#can_redirect_to_app?Boolean

Returns:

  • (Boolean)


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

def can_redirect_to_app?
  payment_method.can_redirect_to_app?
end

#capture!(amount = nil) ⇒ Object

override



57
58
59
60
61
# File 'app/models/vpago/payment_decorator.rb', line 57

def capture!(amount = nil)
  reset_for_retry! if failed?

  super
end

#check_payment?Boolean

Returns:

  • (Boolean)


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

def check_payment?
  payment_method.type_check?
end

#pre_auth_cancelled?Boolean

Returns:

  • (Boolean)


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

def pre_auth_cancelled?
  pre_auth_status == 'CANCELLED'
end

#pre_auth_completed?Boolean

Returns:

  • (Boolean)


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

def pre_auth_completed?
  pre_auth_status == 'COMPLETED'
end

#pre_auth_statusObject

COMPLETED, CANCELLED



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

def pre_auth_status
  pre_auth_response['transaction_status']
end

#preload_payout_idsObject



45
46
47
# File 'app/models/vpago/payment_decorator.rb', line 45

def preload_payout_ids
  self.&.fetch('preload_payout_ids', []) || []
end

#preload_payout_ids=(ids) ⇒ Object

Stores preloaded payout IDs in private_metadata to avoid N+1 queries when checking whether payouts exist for this payment.



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

def preload_payout_ids=(ids)
  self. ||= {}
  self.['preload_payout_ids'] = ids
end

#process!Object

override



50
51
52
53
54
# File 'app/models/vpago/payment_decorator.rb', line 50

def process!
  reset_for_retry! if failed?

  super
end

#protect_from_connection_errorObject

override: to allow capture faraday connection error. gateway_error method already write rails log for this.



65
66
67
68
69
70
71
72
73
# File 'app/models/vpago/payment_decorator.rb', line 65

def protect_from_connection_error
  yield
rescue ActiveMerchant::ConnectionError => e
  failure!
  gateway_error(e)
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
  failure!
  gateway_error(ActiveMerchant::ConnectionError.new(e.message, e))
end

#should_generate_payouts?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/vpago/payment_decorator.rb', line 83

def should_generate_payouts?
  payment_method.enable_payout? && payouts.empty?
end

#true_money_payment?Boolean

Returns:

  • (Boolean)


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

def true_money_payment?
  payment_method.type_true_money?
end

#url_constructorObject



79
80
81
# File 'app/models/vpago/payment_decorator.rb', line 79

def url_constructor
  @url_constructor ||= Vpago::PaymentUrlConstructor.new(self)
end

#user_informerObject



75
76
77
# File 'app/models/vpago/payment_decorator.rb', line 75

def user_informer
  @user_informer ||= ::Vpago::UserInformers::Firebase.new(order)
end

#vattanac_mini_app_payment?Boolean

Returns:

  • (Boolean)


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

def vattanac_mini_app_payment?
  payment_method.type_vattanac_mini_app?
end

#vattanac_payment?Boolean

Returns:

  • (Boolean)


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

def vattanac_payment?
  payment_method.type_vattanac?
end