Class: Gateway::TrueMoney

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

Instance Method Summary collapse

Instance Method Details

#auto_capture?Boolean

force to purchase instead of authorize

Returns:

  • (Boolean)


24
25
26
# File 'app/models/spree/gateway/true_money.rb', line 24

def auto_capture?
  true
end

#cancel(_response_code, _payment) ⇒ Object



75
76
77
78
79
80
81
# File 'app/models/spree/gateway/true_money.rb', line 75

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

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

#method_typeObject



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

def method_type
  'true_money'
end

#payment_source_classObject



19
20
21
# File 'app/models/spree/gateway/true_money.rb', line 19

def payment_source_class
  Spree::VpagoPaymentSource
end

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

override purchase is used when pre auth disabled



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/spree/gateway/true_money.rb', line 30

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, 'Payway Gateway: Purchased', params)
  else
    ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Purchasing Failed', params)
  end
end

#true_money_refund(payment) ⇒ Object



68
69
70
71
72
73
# File 'app/models/spree/gateway/true_money.rb', line 68

def true_money_refund(payment)
  refund_issuer = Vpago::TrueMoney::RefundIssuer.new(payment, {})
  refund_issuer.call

  [refund_issuer.success?, refund_issuer.parsed_response]
end

#void(_response_code, gateway_options) ⇒ Object

override



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/spree/gateway/true_money.rb', line 50

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

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

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