Class: Gateway::Vattanac

Inherits:
PaymentMethod
  • Object
show all
Defined in:
app/models/spree/gateway/vattanac.rb

Instance Method Summary collapse

Instance Method Details

#auto_capture?Boolean

force to purchase instead of authorize

Returns:

  • (Boolean)


22
23
24
# File 'app/models/spree/gateway/vattanac.rb', line 22

def auto_capture?
  true
end

#cancel(_response_code, _payment) ⇒ Object



46
47
48
49
50
51
52
# File 'app/models/spree/gateway/vattanac.rb', line 46

def cancel(_response_code, _payment)
  # we can use this to send request to payment gateway api to cancel the payment ( void )
  # currently Vattanac does not support to cancel the gateway

  # in our case don't do anything
  ActiveMerchant::Billing::Response.new(true, '')
end

#method_typeObject



13
14
15
# File 'app/models/spree/gateway/vattanac.rb', line 13

def method_type
  'vattanac'
end

#payment_source_classObject



17
18
19
# File 'app/models/spree/gateway/vattanac.rb', line 17

def payment_source_class
  Spree::VpagoPaymentSource
end

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

override



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/spree/gateway/vattanac.rb', line 27

def purchase(_amount, _source, gateway_options = {})
  _, payment_number = gateway_options[:order_id].split('-')
  payment = Spree::Payment.find_by(number: payment_number)

  checker = check_transaction(payment)
  payment.update(transaction_response: checker.json_response)

  success = checker.success?
  params = {}

  params[:payment_response] = payment.transaction_response

  if success
    ActiveMerchant::Billing::Response.new(true, 'Vattanac Gateway: Purchased', params)
  else
    ActiveMerchant::Billing::Response.new(false, 'Vattanac Gateway: Purchasing Failed', params)
  end
end