class PerfectMoneyMerchant::SCI
Attributes
baggage_fields[R]
nopayment_url[R]
nopayment_url_method[R]
payee_account[R]
payee_name[R]
payment_amount[R]
payment_id[R]
payment_purpose[R]
payment_units[R]
payment_url[R]
payment_url_method[R]
redirect_url[R]
status_url[R]
suggested_memo[R]
Public Class Methods
generate_verification_code(values)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 4 def generate_verification_code(values) sha2 = Digest::SHA2.new values.each { |value| sha2.update(value.to_s) } sha2.update(Configuration.config.verification_secret) sha2.to_s end
new(attributes = {})
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 27 def initialize(attributes = {}) set_defaults set_price(attributes[:price]) if attributes[:price] set_currency(attributes[:currency]) if attributes[:currency] set_commentary(attributes[:commentary]) if attributes[:commentary] set_payee(attributes[:payee]) if attributes[:payee] set_title(attributes[:title]) if attributes[:title] set_additional(attributes[:additional]) if attributes[:additional] set_verification(attributes[:verification]) if attributes[:verification] set_purpose(attributes[:purpose]) if attributes[:purpose] set_redirect_url(attributes[:redirect_url]) if attributes[:redirect_url] verify_fields! end
Public Instance Methods
set_additional(additional)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 65 def set_additional(additional) additional.each_pair { |attr_name, attr_value| set_field(attr_name, attr_value) } end
set_commentary(commentary)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 49 def set_commentary(commentary) @suggested_memo = commentary end
set_currency(currency)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 61 def set_currency(currency) @payment_units = currency end
set_field(name, value)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 79 def set_field(name, value) singleton_class.class_eval do attr_accessor name end instance_variable_set("@#{name}", value) set_baggage_field(name) end
set_payee(payee)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 53 def set_payee(payee) @payee_account = payee end
set_price(price)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 45 def set_price(price) @payment_amount = price end
set_purpose(purpose)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 69 def set_purpose(purpose) @payment_purpose = purpose set_baggage_field(:payment_purpose) end
set_redirect_url(url)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 74 def set_redirect_url(url) @redirect_url = url set_baggage_field(:redirect_url) end
set_title(title)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 57 def set_title(title) @payee_name = title end
set_verification(fields)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 87 def set_verification(fields) set_field(:verification_code, self.class.generate_verification_code(fields.map { |field| send(field).to_s })) set_field(:verification_fields, fields.join(' ')) end
to_hash()
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 92 def to_hash instance_variables.inject({}) { |hash, variable| hash.merge({ variable.to_s.delete('@').to_sym => instance_variable_get(variable) }) } end
Private Instance Methods
set_baggage_field(field_name)
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 125 def set_baggage_field(field_name) baggage_fields_tmp = baggage_fields.split(' ') baggage_fields_tmp << field_name @baggage_fields = baggage_fields_tmp.join(' ') end
set_defaults()
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 111 def set_defaults config = Configuration.config @payee_name = config.payee_name || 'Perfect Money Merchant' @suggested_memo = config.suggested_memo || 'Perfect Money Merchant Payment' @payment_units = config.payment_units || 'USD' @status_url = config.status_url || '/perfect_money_merchant/payment/status' @payment_url = config.payment_url || '/perfect_money_merchant/payment/success' @payment_url_method = config.payment_url_method || 'POST' @nopayment_url = config.nopayment_url || '/perfect_money_merchant/payment/error' @nopayment_url_method = config.nopayment_url_method || 'POST' @baggage_fields = '' end
verify_fields!()
click to toggle source
# File lib/perfect_money_merchant/sci.rb, line 98 def verify_fields! raise StandardError.new('payee_name is nil') if payee_name.nil? raise StandardError.new('suggested_memo is nil') if suggested_memo.nil? raise StandardError.new('payment_units is nil') if payment_units.nil? raise StandardError.new('payee_account is nil') if payee_account.nil? raise StandardError.new('status_url is nil') if status_url.nil? raise StandardError.new('payment_url is nil') if payment_url.nil? raise StandardError.new('payment_url_method is nil') if payment_url_method.nil? raise StandardError.new('nopayment_url is nil') if nopayment_url.nil? raise StandardError.new('nopayment_url_method is nil') if nopayment_url_method.nil? raise StandardError.new('payment_purpose is nil') if payment_purpose.nil? end