Class: ActiveMerchant::Billing::WorldpayGateway

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

Constant Summary collapse

CARD_CODES =
{
  'visa'             => 'VISA-SSL',
  'master'           => 'ECMC-SSL',
  'discover'         => 'DISCOVER-SSL',
  'american_express' => 'AMEX-SSL',
  'jcb'              => 'JCB-SSL',
  'maestro'          => 'MAESTRO-SSL',
  'diners_club'      => 'DINERS-SSL',
  'elo'              => 'ELO-SSL',
  'naranja'          => 'NARANJA-SSL',
  'cabal'            => 'CABAL-SSL',
  'unknown'          => 'CARD-SSL'
}
AVS_CODE_MAP =
{
  'A' => 'M', # Match
  'B' => 'P', # Postcode matches, address not verified
  'C' => 'Z', # Postcode matches, address does not match
  'D' => 'B', # Address matched; postcode not checked
  'E' => 'I', # Address and postal code not checked
  'F' => 'A', # Address matches, postcode does not match
  'G' => 'C', # Address does not match, postcode not checked
  'H' => 'I', # Address and postcode not provided
  'I' => 'C', # Address not checked postcode does not match
  'J' => 'C', # Address and postcode does not match
}
CVC_CODE_MAP =
{
  'A' => 'M', # CVV matches
  'B' => 'P', # Not provided
  'C' => 'P', # Not checked
  'D' => 'N', # Does not match
}

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?, #supports_scrubbing?, #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 = {}) ⇒ WorldpayGateway

Returns a new instance of WorldpayGateway.



52
53
54
55
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 52

def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Instance Method Details

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



64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 64

def authorize(money, payment_method, options = {})
  requires!(options, :order_id)
  payment_details = payment_details_from(payment_method)
  authorize_request(money, payment_method, payment_details.merge(options))
end

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



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

def capture(money, authorization, options = {})
  authorization = order_id_from_authorization(authorization.to_s)
  MultiResponse.run do |r|
    r.process { inquire_request(authorization, options, 'AUTHORISED') } unless options[:authorization_validated]
    if r.params
      authorization_currency = r.params['amount_currency_code']
      options = options.merge(currency: authorization_currency) if authorization_currency.present?
    end
    r.process { capture_request(money, authorization, options) }
  end
end

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

Credits only function on a Merchant ID/login/profile flagged for Payouts

aka Credit Fund Transfers (CFT), whereas normal purchases, refunds,
and other transactions should be performed on a normal eCom-flagged
merchant ID.


109
110
111
112
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 109

def credit(money, payment_method, options = {})
  payment_details = payment_details_from(payment_method)
  credit_request(money, payment_method, payment_details.merge(credit: true, **options))
end

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



57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 57

def purchase(money, payment_method, options = {})
  MultiResponse.run do |r|
    r.process { authorize(money, payment_method, options) }
    r.process { capture(money, r.authorization, options.merge(authorization_validated: true)) }
  end
end

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



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 90

def refund(money, authorization, options = {})
  authorization = order_id_from_authorization(authorization.to_s)
  response = MultiResponse.run do |r|
    r.process { inquire_request(authorization, options, 'CAPTURED', 'SETTLED', 'SETTLED_BY_MERCHANT') } unless options[:authorization_validated]
    r.process { refund_request(money, authorization, options) }
  end

  if !response.success? && options[:force_full_refund_if_unsettled] &&
     response.params['last_event'] == 'AUTHORISED'
    void(authorization, options)
  else
    response
  end
end

#scrub(transcript) ⇒ Object



130
131
132
133
134
135
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 130

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((<cardNumber>)\d+(</cardNumber>)), '\1[FILTERED]\2').
    gsub(%r((<cvc>)[^<]+(</cvc>)), '\1[FILTERED]\2')
end

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



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

def store(credit_card, options={})
  requires!(options, :customer)
  store_request(credit_card, options)
end

#supports_scrubbingObject



126
127
128
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 126

def supports_scrubbing
  true
end

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



114
115
116
117
118
119
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 114

def verify(payment_method, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, payment_method, options) }
    r.process(:ignore_result) { void(r.authorization, options.merge(authorization_validated: true)) }
  end
end

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



82
83
84
85
86
87
88
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 82

def void(authorization, options = {})
  authorization = order_id_from_authorization(authorization.to_s)
  MultiResponse.run do |r|
    r.process { inquire_request(authorization, options, 'AUTHORISED') } unless options[:authorization_validated]
    r.process { cancel_request(authorization, options) }
  end
end