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
# 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

  # Add state machine event for payment retry
  base.state_machine.event :reset_for_retry do
    transition from: %i[failed], to: :checkout
  end
end

Instance Method Details

#can_redirect_to_app?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'app/models/vpago/payment_decorator.rb', line 114

def can_redirect_to_app?
  payment_method.can_redirect_to_app?
end

#capture!(amount = nil) ⇒ Object

override



55
56
57
58
59
# File 'app/models/vpago/payment_decorator.rb', line 55

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

  super
end

#check_payment?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/models/vpago/payment_decorator.rb', line 110

def check_payment?
  payment_method.type_check?
end

#pre_auth_cancelled?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/vpago/payment_decorator.rb', line 94

def pre_auth_cancelled?
  pre_auth_status == 'CANCELLED'
end

#pre_auth_completed?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/vpago/payment_decorator.rb', line 90

def pre_auth_completed?
  pre_auth_status == 'COMPLETED'
end

#pre_auth_statusObject

COMPLETED, CANCELLED



86
87
88
# File 'app/models/vpago/payment_decorator.rb', line 86

def pre_auth_status
  pre_auth_response['transaction_status']
end

#preload_payout_idsObject



43
44
45
# File 'app/models/vpago/payment_decorator.rb', line 43

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.



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

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

#process!Object

override



48
49
50
51
52
# File 'app/models/vpago/payment_decorator.rb', line 48

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.



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

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)


81
82
83
# File 'app/models/vpago/payment_decorator.rb', line 81

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

#true_money_payment?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/vpago/payment_decorator.rb', line 98

def true_money_payment?
  payment_method.type_true_money?
end

#url_constructorObject



77
78
79
# File 'app/models/vpago/payment_decorator.rb', line 77

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

#user_informerObject



73
74
75
# File 'app/models/vpago/payment_decorator.rb', line 73

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

#vattanac_mini_app_payment?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'app/models/vpago/payment_decorator.rb', line 106

def vattanac_mini_app_payment?
  payment_method.type_vattanac_mini_app?
end

#vattanac_payment?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/vpago/payment_decorator.rb', line 102

def vattanac_payment?
  payment_method.type_vattanac?
end