Class: ActiveMerchant::Billing::PayexGateway

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

Constant Summary collapse

TRANSACTION_STATUS =
{
  sale:       '0',
  initialize: '1',
  credit:     '2',
  authorize:  '3',
  cancel:     '4',
  failure:    '5',
  capture:    '6',
}
SOAP_ACTIONS =
{
  initialize: { name: 'Initialize8', url: 'pxorder/pxorder.asmx', xmlns: 'http://external.payex.com/PxOrder/' },
  purchasecc: { name: 'PurchaseCC', url: 'pxconfined/pxorder.asmx', xmlns: 'http://confined.payex.com/PxOrder/', confined: true},
  cancel: { name: 'Cancel2', url: 'pxorder/pxorder.asmx', xmlns: 'http://external.payex.com/PxOrder/' },
  capture: { name: 'Capture5', url: 'pxorder/pxorder.asmx', xmlns: 'http://external.payex.com/PxOrder/' },
  credit: { name: 'Credit5', url: 'pxorder/pxorder.asmx', xmlns: 'http://external.payex.com/PxOrder/' },
  create_agreement: { name: 'CreateAgreement3', url: 'pxagreement/pxagreement.asmx', xmlns: 'http://external.payex.com/PxAgreement/' },
  delete_agreement: { name: 'DeleteAgreement', url: 'pxagreement/pxagreement.asmx', xmlns: 'http://external.payex.com/PxAgreement/' },
  autopay: { name: 'AutoPay3', url: 'pxagreement/pxagreement.asmx', xmlns: 'http://external.payex.com/PxAgreement/' },
}

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

#card_brand, card_brand, #generate_unique_id, inherited, #scrub, 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 = {}) ⇒ PayexGateway

Returns a new instance of PayexGateway.



42
43
44
45
# File 'lib/active_merchant/billing/gateways/payex.rb', line 42

def initialize(options = {})
  requires!(options, :account, :encryption_key)
  super
end

Instance Method Details

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

Public: Send an authorize Payex request

amount - The monetary amount of the transaction in cents. payment_method - The Active Merchant payment method or the store authorization for stored transactions. options - A standard ActiveMerchant options hash:

:currency          - Three letter currency code for the transaction (default: "EUR")
:order_id          - The unique order ID for this transaction (required).
:product_number    - The merchant product number (default: '1').
:description       - The merchant description for this product (default: The :order_id).
:ip                - The client IP address (default: '127.0.0.1').
:vat               - The vat amount (optional).

Returns an ActiveMerchant::Billing::Response object



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

def authorize(amount, payment_method, options = {})
  requires!(options, :order_id)
  amount = amount(amount)
  if payment_method.respond_to?(:number)
    # credit card authorization
    MultiResponse.new.tap do |r|
      r.process {send_initialize(amount, true, options)}
      r.process {send_purchasecc(payment_method, r.params['orderref'])}
    end
  else
    # stored authorization
    send_autopay(amount, payment_method, true, options)
  end
end

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

Public: Capture money from a previously authorized transaction

money - The amount to capture authorization - The authorization token from the authorization request

Returns an ActiveMerchant::Billing::Response object



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

def capture(money, authorization, options = {})
  amount = amount(money)
  send_capture(amount, authorization)
end

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

Public: Send a purchase Payex request

amount - The monetary amount of the transaction in cents. payment_method - The Active Merchant payment method or the store authorization for stored transactions. options - A standard ActiveMerchant options hash:

:currency          - Three letter currency code for the transaction (default: "EUR")
:order_id          - The unique order ID for this transaction (required).
:product_number    - The merchant product number (default: '1').
:description       - The merchant description for this product (default: The :order_id).
:ip                - The client IP address (default: '127.0.0.1').
:vat               - The vat amount (optional).

Returns an ActiveMerchant::Billing::Response object



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

def purchase(amount, payment_method, options = {})
  requires!(options, :order_id)
  amount = amount(amount)
  if payment_method.respond_to?(:number)
    # credit card purchase
    MultiResponse.new.tap do |r|
      r.process {send_initialize(amount, false, options)}
      r.process {send_purchasecc(payment_method, r.params['orderref'])}
    end
  else
    # stored purchase
    send_autopay(amount, payment_method, false, options)
  end
end

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

Public: Refunds a purchase transaction

money - The amount to refund authorization - The authorization token from the purchase request. options - A standard ActiveMerchant options hash:

:order_id          - The unique order ID for this transaction (required).
:vat_amount        - The vat amount (optional).

Returns an ActiveMerchant::Billing::Response object



133
134
135
136
137
# File 'lib/active_merchant/billing/gateways/payex.rb', line 133

def refund(money, authorization, options = {})
  requires!(options, :order_id)
  amount = amount(money)
  send_credit(authorization, amount, options)
end

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

Public: Stores a credit card and creates a Payex agreement with a customer

creditcard - The credit card to store. options - A standard ActiveMerchant options hash:

:order_id          - The unique order ID for this transaction (required).
:merchant_ref      - A reference that links this agreement to something the merchant takes money for (default: '1')
:currency          - Three letter currency code for the transaction (default: "EUR")
:product_number    - The merchant product number (default: '1').
:description       - The merchant description for this product (default: The :order_id).
:ip                - The client IP address (default: '127.0.0.1').
:max_amount        - The maximum amount to allow to be charged (default: 100000).
:vat               - The vat amount (optional).

Returns an ActiveMerchant::Billing::Response object where the authorization is set to the agreement_ref which is used for stored payments.



153
154
155
156
157
158
159
160
161
162
# File 'lib/active_merchant/billing/gateways/payex.rb', line 153

def store(creditcard, options = {})
  requires!(options, :order_id)
  amount = amount(1) # 1 cent for authorization
  MultiResponse.run(:first) do |r|
    r.process {send_create_agreement(options)}
    r.process {send_initialize(amount, true, options.merge({agreement_ref: r.authorization}))}
    order_ref = r.params['orderref']
    r.process {send_purchasecc(creditcard, order_ref)}
  end
end

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

Public: Unstores a customer’s credit card and deletes their Payex agreement.

authorization - The authorization token from the store request.

Returns an ActiveMerchant::Billing::Response object



169
170
171
# File 'lib/active_merchant/billing/gateways/payex.rb', line 169

def unstore(authorization, options = {})
  send_delete_agreement(authorization)
end

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

Public: Voids an authorize transaction

authorization - The authorization returned from the successful authorize transaction. options - A standard ActiveMerchant options hash

Returns an ActiveMerchant::Billing::Response object



120
121
122
# File 'lib/active_merchant/billing/gateways/payex.rb', line 120

def void(authorization, options={})
  send_cancel(authorization)
end