Sha256: 1c6c533003cab0ddf675c3e8474931e368de1759ad30c92bda00b488f6b79e0f

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Pxpay
  # The response object received from Payment Express
  class Response
    attr_accessor :post
    
    # Create a new Payment Express response object by passing in the return parameters provided to the success/failure URL
    
    def initialize(params)
      @result = params[:result]
      @user_id = params[:userid]
      @post = build_xml( params[:result] )
    end
    
    # Retrieving the transaction details from Payment Express as an instance of Pxpay::Notification
    def response
      require 'rest_client'
      response = ::RestClient.post( 'https://www.paymentexpress.com/pxpay/pxaccess.aspx',  self.post )
      return ::Pxpay::Notification.new( response )
    end
  
    private
    # Internal method to build the xml to send to Payment Express
    def build_xml( result )
      xml = ::Builder::XmlMarkup.new
    
      xml.ProcessResponse do 
        xml.PxPayUserId PXPAY_CONFIG[:pxpay][:pxpay_user_id]
        xml.PxPayKey PXPAY_CONFIG[:pxpay][:pxpay_key]
        xml.Response result
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pxpay-0.1.5 lib/pxpay/response.rb
pxpay-0.1.3 lib/pxpay/response.rb
pxpay-0.1.2 lib/pxpay/response.rb