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',
  'laser'            => 'LASER-SSL',
  'diners_club'      => 'DINERS-SSL',
  'switch'           => 'MAESTRO-SSL'
}

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?, #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.



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

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

Instance Method Details

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



39
40
41
42
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 39

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

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 44

def capture(money, authorization, options = {})
  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

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



32
33
34
35
36
37
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 32

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



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

def refund(money, authorization, options = {})
  MultiResponse.run do |r|
    r.process{inquire_request(authorization, options, "CAPTURED", "SETTLED", "SETTLED_BY_MERCHANT")}
    r.process{refund_request(money, authorization, options)}
  end
end

#scrub(transcript) ⇒ Object



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

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

#supports_scrubbingObject



76
77
78
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 76

def supports_scrubbing
  true
end

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



69
70
71
72
73
74
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 69

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

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



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

def void(authorization, options = {})
  MultiResponse.run do |r|
    r.process{inquire_request(authorization, options, "AUTHORISED")}
    r.process{cancel_request(authorization, options)}
  end
end