Class: ActiveMerchant::Billing::Shift4Gateway

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

Constant Summary collapse

RECURRING_TYPE_TRANSACTIONS =
%w(recurring installment)
TRANSACTIONS_WITHOUT_RESPONSE_CODE =
%w(accesstoken add)
SUCCESS_TRANSACTION_STATUS =
%w(A R)
URL_POSTFIX_MAPPING =
{
  'accesstoken' => 'credentials',
  'add' => 'tokens',
  'verify' => 'cards'
}
STANDARD_ERROR_CODE_MAPPING =
{
  'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
  'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
  'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
  'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
  'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
  'expired_card' => STANDARD_ERROR_CODE[:expired_card],
  'insufficient_funds' => STANDARD_ERROR_CODE[:card_declined],
  'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
  'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
  'card_declined' => STANDARD_ERROR_CODE[:card_declined],
  'processing_error' => STANDARD_ERROR_CODE[:processing_error],
  'lost_or_stolen' => STANDARD_ERROR_CODE[:card_declined],
  'suspected_fraud' => STANDARD_ERROR_CODE[:card_declined],
  'expired_token' => STANDARD_ERROR_CODE[:card_declined]
}

Constants inherited from Gateway

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

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #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 = {}) ⇒ Shift4Gateway

Returns a new instance of Shift4Gateway.


39
40
41
42
43
44
45
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 39

def initialize(options = {})
  requires!(options, :client_guid, :auth_token)
  @client_guid = options[:client_guid]
  @auth_token = options[:auth_token]
  super
  @access_token = setup_access_token
end

Instance Method Details

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


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 62

def authorize(money, payment_method, options = {})
  post = {}
  add_datetime(post, options)
  add_invoice(post, money, options)
  add_clerk(post, options)
  add_transaction(post, options)
  add_card(post, payment_method, options)
  add_card_present(post, options)
  add_three_d_secure(post, payment_method, options)
  add_customer(post, options)

  commit('authorization', post, options)
end

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


76
77
78
79
80
81
82
83
84
85
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 76

def capture(money, authorization, options = {})
  post = {}
  add_datetime(post, options)
  add_invoice(post, money, options)
  add_clerk(post, options)
  add_transaction(post, options)
  add_card(post, get_card_token(authorization), options)

  commit('capture', post, options)
end

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


47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 47

def purchase(money, payment_method, options = {})
  post = {}

  payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
  add_datetime(post, options)
  add_invoice(post, money, options)
  add_clerk(post, options)
  add_transaction(post, options)
  add_card(post, payment_method, options)
  add_card_present(post, options)
  add_three_d_secure(post, payment_method, options)

  commit('sale', post, options)
end

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


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 87

def refund(money, authorization, options = {})
  post = {}
  add_datetime(post, options)
  add_invoice(post, money, options)
  add_clerk(post, options)
  add_transaction(post, options)
  add_customer(post, options)
  add_card(post, get_card_token(authorization), options)

  commit('refund', post, options)
end

#scrub(transcript) ⇒ Object


125
126
127
128
129
130
131
132
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 125

def scrub(transcript)
  transcript.
    gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("expirationDate\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("FirstName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("LastName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("securityCode":{"[\w]+":"[\w]+","value":")[\d]*)i, '\1[FILTERED]')
end

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


111
112
113
114
115
116
117
118
119
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 111

def store(credit_card, options = {})
  post = {}
  add_datetime(post, options)
  add_clerk(post, options)
  add_transaction(post, options)
  add_card(post, credit_card, options)

  commit('add', post, options)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

121
122
123
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 121

def supports_scrubbing?
  true
end

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


104
105
106
107
108
109
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 104

def verify(credit_card, options = {})
  post = {}
  add_card(post, credit_card, options)

  commit('verify', post, options)
end

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


99
100
101
102
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 99

def void(authorization, options = {})
  options[:invoice] = get_invoice(authorization)
  commit('invoice', {}, options)
end