Class: Gateway::VattanacMiniApp

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

Instance Method Summary collapse

Instance Method Details

#auto_capture?Boolean

force to purchase instead of authorize



15
16
17
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 15

def auto_capture?
  true
end

#cancel(_response_code, _payment) ⇒ Object



62
63
64
65
66
67
68
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 62

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

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

#method_typeObject



6
7
8
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 6

def method_type
  'vattanac_mini_app'
end

#payment_source_classObject



10
11
12
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 10

def payment_source_class
  Spree::VpagoPaymentSource
end

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

override purchase is used when pre auth disabled



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 21

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

  params = {}

  params[:payment_response] = payment.transaction_response

  if payment.transaction_response['status'] == 'SUCCESS'
    ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Purchased', params)
  else
    ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Purchasing Failed', params)
  end
end

#vattanac_mini_app_refund(payment) ⇒ Object



55
56
57
58
59
60
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 55

def vattanac_mini_app_refund(payment)
  refund_issuer = Vpago::VattanacMiniApp::RefundIssuer.new(payment, {})
  refund_issuer.call

  [refund_issuer.success?, refund_issuer.response]
end

#void(_response_code, gateway_options) ⇒ Object

override



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/spree/gateway/vattanac_mini_app.rb', line 37

def void(_response_code, gateway_options)
  _, payment_number = gateway_options[:order_id].split('-')
  payment = Spree::Payment.find_by(number: payment_number)

  if payment.vattanac_mini_app_payment?
    params = {}
    success, params[:refund_response] = vattanac_mini_app_refund(payment)

    if success
      ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: successfully canceled.', params)
    else
      ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Failed to canceleed', params)
    end
  else
    ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been voided.')
  end
end