Class: ActiveMerchant::Billing::CulqiGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/culqi.rb

Overview

Important note:

Culqi merchant accounts are configured for either purchase or auth/capture modes. This is configured by Culqi when setting up a merchant account and largely depends on the transaction acquiring bank. Be sure to understand how your account was configured prior to using this gateway.

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ CulqiGateway


23
24
25
26
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 23

def initialize(options={})
  requires!(options, :merchant_id, :terminal_id, :secret_key)
  super
end

Instance Method Details

#authorize(amount, payment_method, options = {}) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 32

def authorize(amount, payment_method, options={})
  if payment_method.is_a?(String)
    action = :tokenpay
  else
    action = :authorize
  end
  post = {}
  add_credentials(post)
  add_invoice(action, post, amount, options)
  add_payment_method(post, payment_method, action, options)
  add_customer_data(post, options)
  add_checksum(action, post)

  commit(action, post)
end

#capture(amount, authorization, options = {}) ⇒ Object


48
49
50
51
52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 48

def capture(amount, authorization, options={})
  action = :capture
  post = {}
  add_credentials(post)
  add_invoice(action, post, amount, options)
  add_reference(post, authorization)
  add_checksum(action, post)

  commit(action, post)
end

#invalidate(authorization, options = {}) ⇒ Object


106
107
108
109
110
111
112
113
114
115
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 106

def invalidate(authorization, options={})
  action = :invalidate
  post = {}
  post[:partnerid] = options[:partner_id] if options[:partner_id]
  add_credentials(post)
  post[:token] = authorization
  add_checksum(action, post)

  commit(action, post)
end

#purchase(amount, payment_method, options = {}) ⇒ Object


28
29
30
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 28

def purchase(amount, payment_method, options={})
  authorize(amount, payment_method, options)
end

#refund(amount, authorization, options = {}) ⇒ Object


70
71
72
73
74
75
76
77
78
79
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 70

def refund(amount, authorization, options={})
  action = :refund
  post = {}
  add_credentials(post)
  add_invoice(action, post, amount, options)
  add_reference(post, authorization)
  add_checksum(action, post)

  commit(action, post)
end

#scrub(transcript) ⇒ Object


121
122
123
124
125
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 121

def scrub(transcript)
  transcript.
    gsub(%r((cardnumber=)\d+), '\1[FILTERED]').
    gsub(%r((cvv=)\d+), '\1[FILTERED]')
end

#store(credit_card, options = {}) ⇒ Object


93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 93

def store(credit_card, options={})
  action = :tokenize
  post = {}
  post[:partnerid] = options[:partner_id] if options[:partner_id]
  post[:cardholderid] = options[:cardholder_id] if options[:cardholder_id]
  add_credentials(post)
  add_payment_method(post, credit_card, action, options)
  add_customer_data(post, options)
  add_checksum(action, post)

  commit(action, post)
end

#supports_scrubbing?Boolean


117
118
119
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 117

def supports_scrubbing?
  true
end

#verify(credit_card, options = {}) ⇒ Object


81
82
83
84
85
86
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 81

def verify(credit_card, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(1000, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#verify_credentialsObject


88
89
90
91
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 88

def verify_credentials
  response = void("0", order_id: "0")
  response.message.include? "Transaction not found"
end

#void(authorization, options = {}) ⇒ Object


59
60
61
62
63
64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/culqi.rb', line 59

def void(authorization, options={})
  action = :void
  post = {}
  add_credentials(post)
  add_invoice(action, post, nil, options)
  add_reference(post, authorization)
  add_checksum(action, post)

  commit(action, post)
end