Class: Gateway::CulqiGateway

Inherits:
Spree::PaymentMethod::CreditCard
  • Object
show all
Defined in:
app/models/solidus/gateway/culqi_gateway.rb

Instance Method Summary collapse

Instance Method Details

#authorize(amount, creditcard, gateway_options) ⇒ Object



20
21
22
23
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 20

def authorize(amount, creditcard, gateway_options)
  init_culqi
  commit(amount, creditcard, gateway_options, false)
end

#capture(_amount, response_code, _gateway_options) ⇒ Object



30
31
32
33
34
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 30

def capture(_amount, response_code, _gateway_options)
  init_culqi
  charge = Culqi::Charge.capture(response_code)
  parse_response(charge)
end

#create_profile(payment) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 57

def create_profile(payment)
  return unless payment.source.gateway_customer_profile_id.nil?

  init_culqi
  customer = get_customer(payment)
  token = payment.source.gateway_payment_profile_id
  card_token = generate_card(customer, token)
  unless customer.nil? || card_token.nil?
    payment.source.update(
      gateway_customer_profile_id: customer,
      gateway_payment_profile_id: card_token
    )
  end
end

#credit(amount, _creditcard, response_code, _gateway_options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 36

def credit(amount, _creditcard, response_code, _gateway_options)
  init_culqi
  # Culqi only accepts 'duplicado','fraudulento' o 'solicitud_comprador'
  # like reason's value
  refund = Culqi::Refund.create(
    amount: amount,
    charge_id: response_code,
    reason: "solicitud_comprador"
  )
  parse_response(refund)
end

#default_currencyObject



16
17
18
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 16

def default_currency
  "PEN"
end

#gateway_classObject



12
13
14
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 12

def gateway_class
  self.class
end

#partial_nameObject



8
9
10
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 8

def partial_name
  'culqi'
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 53

def payment_profiles_supported?
  true
end

#purchase(amount, creditcard, gateway_options) ⇒ Object



25
26
27
28
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 25

def purchase(amount, creditcard, gateway_options)
  init_culqi
  commit(amount, creditcard, gateway_options, true)
end

#void(response_code, creditcard, gateway_options) ⇒ Object



48
49
50
51
# File 'app/models/solidus/gateway/culqi_gateway.rb', line 48

def void(response_code, creditcard, gateway_options)
  amount = gateway_options[:subtotal].to_i
  credit(amount, creditcard, response_code, gateway_options)
end