module Propay

Constants

CARD_TYPES
VERSION

Attributes

configuration[RW]

Public Class Methods

add_payment_method(options = {}) click to toggle source

:name :card_number :address :address2 :country :state :zip :description :expiration :payer_id :card_type

# File lib/propay.rb, line 36
def add_payment_method(options = {})
  soap_action("CreatePaymentMethod", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))
end
authorize_payment(options = {}) click to toggle source

:payment_method_id :amount :comment :comment2 :merchant_profile_id :payer_id || :user_id

# File lib/propay.rb, line 57
def authorize_payment(options = {})
  soap_action("AuthorizePaymentMethodTransaction", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))["AuthorizePaymentMethodTransactionResponse"]["AuthorizePaymentMethodTransactionResult"]
end
capture_payment(options = {}) click to toggle source

:amount :comment :comment2 :merchant_profile_id :transaction_id :payer_id || :user_id

# File lib/propay.rb, line 62
def capture_payment(options = {})
  soap_action("CapturePayment", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))["CapturePaymentResponse"]["CapturePaymentResult"]
end
configure() { |configuration| ... } click to toggle source
# File lib/propay.rb, line 14
def configure
  self.configuration ||= OpenStruct.new
  yield(configuration)
  current_path = File.expand_path(File.dirname(__FILE__))
  Dir["#{current_path}/modules/*.rb"].each {|file| require file }
end
create_merchant_profile(options = {}) click to toggle source
# File lib/propay.rb, line 21
def create_merchant_profile(options = {})
  soap_action("CreateMerchantProfile", options)
end
create_payer(options = {}) click to toggle source
# File lib/propay.rb, line 31
def create_payer(options = {})
  payer_id = soap_action("CreatePayerWithData", options)["CreatePayerWithDataResponse"]["CreatePayerWithDataResult"]["ExternalAccountID"] unless payer_id
end
delete_payment_method(options = {}) click to toggle source

:payment_method_id :user_id || :payer_id

# File lib/propay.rb, line 41
def delete_payment_method(options = {})
  soap_action("DeletePaymentMethod", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))
end
find_or_create_payer(options = {}) click to toggle source
# File lib/propay.rb, line 25
def find_or_create_payer(options = {})
  payer_id = soap_action("GetPayers", options)["GetPayersResponse"]["GetPayersResult"]["Payers"]["PayerInfo"].first["payerAccountId"] rescue false
  payer_id = soap_action("CreatePayerWithData", options)["CreatePayerWithDataResponse"]["CreatePayerWithDataResult"]["ExternalAccountID"] unless payer_id
  return payer_id
end
get_temp_token(options = {}) click to toggle source
# File lib/propay.rb, line 76
def get_temp_token(options = {})
  result = soap_action('GetTempToken', options)
  raise result["GetTempTokenResponse"]["GetTempTokenResult"]["RequestResult"]["ResultMessage"] if result["GetTempTokenResponse"]["GetTempTokenResult"]["RequestResult"]["ResultValue"] == "FAILURE"
  result
end
list_payment_methods(options = {}) click to toggle source

:user_id || payer_id

# File lib/propay.rb, line 46
def list_payment_methods(options = {})
  response = soap_action("GetAllPayerPaymentMethods", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))["GetAllPayerPaymentMethodsResponse"]["GetAllPayerPaymentMethodsResult"]["PaymentMethods"]["PaymentMethodInformation"] rescue nil
  return response.class == Hash ? [response] : response
end
process_payment(options = {}) click to toggle source

:payment_method_id :amount :comment :comment2 :merchant_profile_id :payer_id || :user_id

# File lib/propay.rb, line 52
def process_payment(options = {})
  soap_action("ProcessPaymentMethodTransaction", options.merge(:payer_id => (options[:payer_id] || find_or_create_payer(options))))["ProcessPaymentMethodTransactionResponse"]["ProcessPaymentMethodTransactionResult"]
end
refund_payment(options = {}) click to toggle source

:amount, :transaction_id, :merchant_profile_id

# File lib/propay.rb, line 72
def refund_payment(options = {})
  soap_action("RefundPaymentV2", options)["RefundPaymentV2Response"]["RefundPaymentV2Result"]
end
void_payment(options = {}) click to toggle source

:transaction_id, :merchant_profile_id

# File lib/propay.rb, line 67
def void_payment(options = {})
  soap_action("VoidPaymentV2", options)["VoidPaymentV2Response"]["VoidPaymentV2Result"]
end

Private Class Methods

post_soap(xml, action) click to toggle source
# File lib/propay.rb, line 93
def post_soap(xml, action)
  Rails.logger.info "SENT: #{xml}"
  host = (Rails.env == 'production' ? "protectpay.propay.com" : "protectpaytest.propay.com")
  resp = Typhoeus::Request.post("https://#{host}/api/sps.svc", :body => xml, :headers => {'Host' => host, 'Content-Type' => "text/xml; charset=utf-8", "SOAPAction" => "http://propay.com/SPS/contracts/SPSService/#{action}"})
  Rails.logger.info "RECEIVED: #{resp.body}"
  return Hash.from_xml(resp.body)["Envelope"]["Body"]
end
soap_action(action, options = {}) click to toggle source
# File lib/propay.rb, line 84
def soap_action(action, options = {})
  @options = options
  @partial = ERB.new(File.new("#{File.dirname(__FILE__)}/soap_actions/_auth.erb").read, nil, true).result(binding)
  xml = ERB.new(File.new("#{File.dirname(__FILE__)}/soap_actions/#{action}.erb").read, nil, true).result(binding)
  response = post_soap(xml, action)
  puts xml, ">>\n", response.inspect if options[:show_xml]
  return response
end