Sha256: f1ce327541c97554f2fcef142db33d31a088bd1caf6f57e460bb85f26f26afa4
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
module Pxpay class Request attr_accessor :post # Create a new instance of Pxpay::Request # Pxpay::Request.new( id, amount, options = {} ) # Current available options are: # :currency, currency for transaction, default is NZD, can be any of Pxpay::Base.currency_types # :reference, a reference field, default is the id # :email, email address of user, default is nil def initialize( id , price, options = {} ) @post = build_xml( id, price, options ) end # Get the redirect URL from Payment Express def url require 'rest_client' response = ::RestClient.post("https://sec2.paymentexpress.com/pxpay/pxaccess.aspx", post ) url = Hash.from_xml(response)['Request']['URI'] return URI::extract(url).first.gsub("&", "&") end private # Internal method to build the xml to send to Payment Express def build_xml( id, price, options ) xml = Builder::XmlMarkup.new xml.GenerateRequest do xml.PxPayUserId PXPAY_CONFIG[:pxpay][:pxpay_user_id] xml.PxPayKey PXPAY_CONFIG[:pxpay][:pxpay_key] xml.AmountInput sprintf("%.2f", price) xml.CurrencyInput options[:currency] || "NZD" xml.MerchantReference options[:reference] || id.to_s xml.EmailAddress options[:email] xml.TxnType "Purchase" xml.TxnId id xml.UrlSuccess PXPAY_CONFIG[:pxpay][:success_url] xml.UrlFail PXPAY_CONFIG[:pxpay][:failure_url] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pxpay-0.1.1 | lib/pxpay/request.rb |