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



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/models/vpago/payment_decorator.rb', line 3

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,
                :process_payment_url,
                :success_deeplink_url,
                to: :url_constructor
end

Instance Method Details

#can_redirect_to_app?Boolean

Returns:

  • (Boolean)


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

def can_redirect_to_app?
  payment_method.can_redirect_to_app?
end

#check_payment?Boolean

Returns:

  • (Boolean)


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

def check_payment?
  payment_method.type_check?
end

#pre_auth_cancelled?Boolean

Returns:

  • (Boolean)


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

def pre_auth_cancelled?
  pre_auth_status == 'CANCELLED'
end

#pre_auth_completed?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/vpago/payment_decorator.rb', line 53

def pre_auth_completed?
  pre_auth_status == 'COMPLETED'
end

#pre_auth_statusObject

COMPLETED, CANCELLED



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

def pre_auth_status
  pre_auth_response['transaction_status']
end

#process!Object

override: to give payment another chance to re-process, even if it failed.



18
19
20
21
22
# File 'app/models/vpago/payment_decorator.rb', line 18

def process!
  update!(state: :checkout) if processing? || send(:has_invalid_state?)

  super
end

#protect_from_connection_errorObject

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



26
27
28
29
30
31
32
33
34
# File 'app/models/vpago/payment_decorator.rb', line 26

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)


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

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

#true_money_payment?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/vpago/payment_decorator.rb', line 61

def true_money_payment?
  payment_method.type_true_money?
end

#url_constructorObject



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

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

#user_informerObject



36
37
38
# File 'app/models/vpago/payment_decorator.rb', line 36

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

#vattanac_mini_app_payment?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/vpago/payment_decorator.rb', line 69

def vattanac_mini_app_payment?
  payment_method.type_vattanac_mini_app?
end

#vattanac_payment?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/vpago/payment_decorator.rb', line 65

def vattanac_payment?
  payment_method.type_vattanac?
end