Class: Pxpay::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/pxpay/request.rb

Overview

The request object to send to Payment Express

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, price, options = {}) ⇒ Request

Create a new instance of Pxpay::Request Pxpay::Request.new( id, amount, options = {} ) Current available options are: :currency_input, currency for transaction, default is NZD, can be any of Pxpay::Base.currency_types :merchant_reference, a reference field, default is the id. :email_address, email address of user, optional. :token_billing, boolean value, set to true to enable token billing. :billing_id, optional billing_id field only used if token_billing is set to true. :txn_type, can be set to :auth for Auth transaction, defaults to Purchase :url_success, Success URL, can optionally be set globally via Pxpay::Base.url_success= :url_failure, Failure URL, can optionally be set globally via Pxpay::Base.url_failure= :txn_data1, Optional data :txn_data2, Optional data :txn_data3, Optional data :txn_data4, Optional data :opt, Optional data



28
29
30
31
# File 'lib/pxpay/request.rb', line 28

def initialize( id , price, options = {} )
  warn "Using :reference is deprecated, please use :merchant_reference instead" if options[:reference]
  @post = build_xml( id, price, options )
end

Instance Attribute Details

#postObject

Returns the value of attribute post.



9
10
11
# File 'lib/pxpay/request.rb', line 9

def post
  @post
end

Instance Method Details

#urlObject

Get the redirect URL from Payment Express



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pxpay/request.rb', line 34

def url
  response = ::RestClient.post(Pxpay::Base.pxpay_request_url, post )
  response_text = ::Nokogiri::XML(response)
  if response_text.at_css("Request").attributes["valid"].value == "1"
    url = response_text.at_css("URI").inner_html
  else
    if Pxpay::Base.pxpay_user_id && Pxpay::Base.pxpay_key
      raise Pxpay::Error, response_text.at_css("Request").inner_html
    else
      raise Pxpay::MissingKey, "Your Pxpay config is not set up properly, run rails generate pxpay:install"
    end
  end
  return URI::extract(url).first.gsub("&", "&")
end