Module: Propay

Defined in:
lib/propay.rb,
lib/modules/fib.rb,
lib/propay/version.rb,
lib/generators/propay/install_generator.rb

Defined Under Namespace

Modules: Fixnum, Generators Classes: ResponseError

Constant Summary collapse

CARD_TYPES =
%w(Visa MasterCard AMEX Discover DinersClub JCB)
VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



12
13
14
# File 'lib/propay.rb', line 12

def configuration
  @configuration
end

Class Method Details

.add_payment_method(options = {}) ⇒ Object

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



36
37
38
# 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 = {}) ⇒ Object

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



57
58
59
# 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 = {}) ⇒ Object

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



62
63
64
# 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| ... } ⇒ Object

Yields:



14
15
16
17
18
19
# 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 = {}) ⇒ Object



21
22
23
# File 'lib/propay.rb', line 21

def create_merchant_profile(options = {})
  soap_action("CreateMerchantProfile", options)
end

.create_payer(options = {}) ⇒ Object



31
32
33
# 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 = {}) ⇒ Object

:payment_method_id :user_id || :payer_id



41
42
43
# 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 = {}) ⇒ Object



25
26
27
28
29
# 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 = {}) ⇒ Object



76
77
78
79
80
# 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 = {}) ⇒ Object

:user_id || payer_id



46
47
48
49
# 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 = {}) ⇒ Object

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



52
53
54
# 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 = {}) ⇒ Object

:amount, :transaction_id, :merchant_profile_id



72
73
74
# File 'lib/propay.rb', line 72

def refund_payment(options = {})
  soap_action("RefundPaymentV2", options)["RefundPaymentV2Response"]["RefundPaymentV2Result"]
end

.void_payment(options = {}) ⇒ Object

:transaction_id, :merchant_profile_id



67
68
69
# File 'lib/propay.rb', line 67

def void_payment(options = {})
  soap_action("VoidPaymentV2", options)["VoidPaymentV2Response"]["VoidPaymentV2Result"]
end