Class: GpWebpay::PaymentAttributes
- Inherits:
-
Object
- Object
- GpWebpay::PaymentAttributes
- Defined in:
- lib/gp_webpay/payment_attributes.rb
Constant Summary collapse
- KEYS =
%i(merchant_number operation order_number amount_in_cents currency deposit_flag redirect_url description merchant_description user_param)
- WS_KEYS =
%i(message_id bank_id merchant_number order_number)
- REGULAR_PAYMENT_KEYS =
%i( message_id bank_id merchant_number order_number master_order_number merchant_order_number amount_in_cents capture_flag card_holder.name card_holder.email card_holder.phone_country card_holder.phone card_holder.mobile_phone_country card_holder.mobile_phone address_match billing.name billing.address1 billing.city billing.postal_code billing.country shipping.name shipping.address1 shipping.city shipping.postal_code shipping.country )
- OPTIONAL_KEYS =
%i(merchant_order_number description merchant_description)
- MASTER_KEYS =
%i(user_param)
- TRANSITIONS =
{ :merchant_number => 'MERCHANTNUMBER', :order_number => 'ORDERNUMBER', :master_order_number => 'MASTERORDERNUMBER', :amount_in_cents => 'AMOUNT', :deposit_flag => 'DEPOSITFLAG', :merchant_order_number => 'MERORDERNUM', :redirect_url => 'URL', :merchant_description => 'MD', :message_id => 'MESSAGEID', :bank_id => 'BANKID', :currency => 'CURRENCY', :operation => 'OPERATION', :user_param => 'USERPARAM1', }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(payment, ws_flag = false, type = "") ⇒ PaymentAttributes
constructor
A new instance of PaymentAttributes.
- #keys ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(payment, ws_flag = false, type = "") ⇒ PaymentAttributes
Returns a new instance of PaymentAttributes.
35 36 37 38 39 |
# File 'lib/gp_webpay/payment_attributes.rb', line 35 def initialize(payment, ws_flag = false, type = "") @payment = payment @ws_flag = ws_flag @type = type end |
Class Method Details
.map_to_keys(hash) ⇒ Object
74 75 76 77 78 |
# File 'lib/gp_webpay/payment_attributes.rb', line 74 def self.map_to_keys(hash) hash.each_with_object({}) do |(method, value), transformed| transformed[TRANSITIONS[method]] = value end end |
Instance Method Details
#keys ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gp_webpay/payment_attributes.rb', line 41 def keys case @payment.payment_type when "master" return (@ws_flag ? WS_KEYS : KEYS) when "recurring" case @type when "processRegularSubscriptionPayment" return REGULAR_PAYMENT_KEYS else return WS_KEYS end else return KEYS.reject { |k| MASTER_KEYS.include?(k) } end end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gp_webpay/payment_attributes.rb', line 57 def to_h keys.each_with_object({}) do |method, hash| method_chain = method.to_s.split(".").map(&:to_sym) if @payment.respond_to?(*method_chain) if method == :message_id hash[method] = @payment.public_send(method, @type) else hash[method] = method_chain.inject(@payment, :public_send) end elsif !OPTIONAL_KEYS.include?(method) method_missing(method) end hash end end |