Class: ActiveMerchant::Billing::WorldpayOnlinePaymentsGateway

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

Constant Summary

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, #scrub, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ WorldpayOnlinePaymentsGateway

Returns a new instance of WorldpayOnlinePaymentsGateway.



16
17
18
19
20
21
# File 'lib/active_merchant/billing/gateways/worldpay_online_payments.rb', line 16

def initialize(options={})
  requires!(options, :client_key, :service_key)
  @client_key = options[:client_key]
  @service_key = options[:service_key]
  super
end

Instance Method Details

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



23
24
25
26
27
28
29
30
31
# File 'lib/active_merchant/billing/gateways/worldpay_online_payments.rb', line 23

def authorize(money, credit_card, options={})
  response = create_token(true, credit_card.first_name+' '+credit_card.last_name, credit_card.month, credit_card.year, credit_card.number, credit_card.verification_value)
  if response.success?
    options[:authorizeOnly] = true
    post = create_post_for_auth_or_purchase(response.authorization, money, options)
    response = commit(:post, 'orders', post, {}, 'authorize')
  end
  response
end

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



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

def capture(money, authorization, options={})
  if authorization
    commit(:post, "orders/#{CGI.escape(authorization)}/capture", {'captureAmount'=>money}, options, 'capture')
  else
    Response.new(false,
      'FAILED',
      'FAILED',
      :test => test?,
      :authorization => false,
      :avs_result => {},
      :cvv_result => {},
      :error_code => false
    )
  end
end

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



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

def purchase(money, credit_card, options={})
  response = create_token(true, credit_card.first_name+' '+credit_card.last_name, credit_card.month, credit_card.year, credit_card.number, credit_card.verification_value)
  if response.success?
    post = create_post_for_auth_or_purchase(response.authorization, money, options)
    response = commit(:post, 'orders', post, options, 'purchase')
  end
  response
end

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



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

def refund(money, orderCode, options={})
  obj = money ? {'refundAmount' => money} : {}
  commit(:post, "orders/#{CGI.escape(orderCode)}/refund", obj, options, 'refund')
end

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



69
70
71
# File 'lib/active_merchant/billing/gateways/worldpay_online_payments.rb', line 69

def verify(credit_card, options={})
  authorize(0, credit_card, options)
end

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



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

def void(orderCode, options={})
  response = commit(:delete, "orders/#{CGI.escape(orderCode)}", nil, options, 'void')
  response = refund(nil, orderCode) if !response.success? && (response.params && response.params['customCode'] != 'ORDER_NOT_FOUND')
  response
end