Class: Braspag::PaymentMethod
- Inherits:
-
Object
- Object
- Braspag::PaymentMethod
- Defined in:
- lib/rbraspag/payment_method.rb
Direct Known Subclasses
Class Method Summary collapse
- .check_params(params) ⇒ Object
- .normalize_params(params) ⇒ Object
- .payment_method_from_id(code) ⇒ Object
- .valid_order_id?(order_id) ⇒ Boolean
Class Method Details
.check_params(params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbraspag/payment_method.rb', line 15 def self.check_params(params) [:order_id, :amount, :payment_method].each do |param| raise IncompleteParams if params[param].nil? end raise InvalidOrderId unless self.valid_order_id?(params[:order_id]) if params[:customer_name] raise InvalidCustomerName unless (1..255).include?(params[:customer_name].to_s.size) end if params[:customer_id] raise InvalidCustomerId unless (11..18).include?(params[:customer_id].to_s.size) end unless params[:payment_method].is_a?(Symbol) && self::PAYMENT_METHODS[params[:payment_method]] raise InvalidPaymentMethod end end |
.normalize_params(params) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/rbraspag/payment_method.rb', line 7 def self.normalize_params(params) if params[:amount] && !params[:amount].is_a?(BigDecimal) params[:amount] = BigDecimal.new(params[:amount].to_s) end params end |
.payment_method_from_id(code) ⇒ Object
3 4 5 |
# File 'lib/rbraspag/payment_method.rb', line 3 def self.payment_method_from_id(code) self::PAYMENT_METHODS.invert.values_at(code).first end |
.valid_order_id?(order_id) ⇒ Boolean
35 36 37 |
# File 'lib/rbraspag/payment_method.rb', line 35 def self.valid_order_id?(order_id) (order_id.is_a?(String) || order_id.is_a?(Fixnum)) && (1..50).include?(order_id.to_s.size) end |