Class: ActiveMerchant::Billing::PayexGateway

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

Constant Summary collapse

TEST_CONFINED_URL =

NOTE: the PurchaseCC uses a different url for test transactions

'https://test-confined.payex.com/'
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::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from CreditCardFormatting

#format

Constructor Details

#initialize(options = {}) ⇒ PayexGateway

Returns a new instance of PayexGateway.



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

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



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

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



107
108
109
110
# File 'lib/active_merchant/billing/gateways/payex.rb', line 107

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



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

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



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

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.



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

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



167
168
169
# File 'lib/active_merchant/billing/gateways/payex.rb', line 167

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



118
119
120
# File 'lib/active_merchant/billing/gateways/payex.rb', line 118

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