Class: Prodamus::LinkConfig
- Inherits:
-
Object
- Object
- Prodamus::LinkConfig
- Defined in:
- lib/services/link_config.rb
Overview
Configure request wich be sent for get purchase link
Constant Summary collapse
- DEFAULT_PAYMENTS_LIMIT =
1
Instance Attribute Summary collapse
-
#available_payment_methods ⇒ Object
readonly
Returns the value of attribute available_payment_methods.
-
#currency ⇒ Object
rubocop:disable Naming/MethodName.
-
#customer_email ⇒ Object
rubocop:disable Naming/MethodName.
-
#customer_extra ⇒ Object
rubocop:disable Naming/MethodName.
-
#customer_phone ⇒ Object
rubocop:disable Naming/MethodName.
- #form_access_duration ⇒ Object
-
#order_id ⇒ Object
rubocop:disable Naming/MethodName.
-
#payment_method ⇒ Object
rubocop:disable Naming/MethodName.
-
#payments_limit ⇒ Object
rubocop:disable Naming/MethodName.
-
#products ⇒ Object
readonly
Returns the value of attribute products.
-
#sys ⇒ Object
rubocop:disable Naming/MethodName.
- #timezone ⇒ Object
-
#urlNotification ⇒ Object
rubocop:disable Naming/MethodName.
-
#urlReturn ⇒ Object
rubocop:disable Naming/MethodName.
-
#urlSuccess ⇒ Object
rubocop:disable Naming/MethodName.
Instance Method Summary collapse
- #add_available_payment_methods(*payment_methods) ⇒ Object
-
#add_product(name:, price:, quantity: 1, sku: nil) ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#format_result ⇒ Object
Transform payload to be sent rubocop:disable Metrics/MethodLength.
-
#initialize {|_self| ... } ⇒ LinkConfig
constructor
A new instance of LinkConfig.
- #installments_disabled ⇒ Object
- #installments_disabled=(disabled) ⇒ Object
- #link_expired ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ LinkConfig
Returns a new instance of LinkConfig.
23 24 25 26 |
# File 'lib/services/link_config.rb', line 23 def initialize @products = [] yield self if block_given? end |
Instance Attribute Details
#available_payment_methods ⇒ Object (readonly)
Returns the value of attribute available_payment_methods.
21 22 23 |
# File 'lib/services/link_config.rb', line 21 def available_payment_methods @available_payment_methods end |
#currency ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def currency @currency end |
#customer_email ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def customer_email @customer_email end |
#customer_extra ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def customer_extra @customer_extra end |
#customer_phone ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def customer_phone @customer_phone end |
#form_access_duration ⇒ Object
97 98 99 |
# File 'lib/services/link_config.rb', line 97 def form_access_duration @form_access_duration || 1.day end |
#order_id ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def order_id @order_id end |
#payment_method ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def payment_method @payment_method end |
#payments_limit ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def payments_limit @payments_limit end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
21 22 23 |
# File 'lib/services/link_config.rb', line 21 def products @products end |
#sys ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def sys @sys end |
#timezone ⇒ Object
101 102 103 |
# File 'lib/services/link_config.rb', line 101 def timezone @timezone || 'Moscow' end |
#urlNotification ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def urlNotification @urlNotification end |
#urlReturn ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def urlReturn @urlReturn end |
#urlSuccess ⇒ Object
rubocop:disable Naming/MethodName
14 15 16 |
# File 'lib/services/link_config.rb', line 14 def urlSuccess @urlSuccess end |
Instance Method Details
#add_available_payment_methods(*payment_methods) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/services/link_config.rb', line 69 def add_available_payment_methods(*payment_methods) payment_methods.flatten! raise 'payment_method is already defined' if @payment raise ArgumentError, 'Not avaible payment methods.' unless (payment_methods - ALL_AVAIBLE_PAYMENT_METHODS).empty? if @installments_disabled&.positive? && !(payment_methods - NON_INSTALLMENTS_PAYMENT_METHODS).empty? raise ArgumentError, 'Installments payment methods is not avaible when installments disabled.' end @available_payment_methods = [] if @available_payment_methods.nil? @available_payment_methods += payment_methods end |
#add_product(name:, price:, quantity: 1, sku: nil) ⇒ Object
rubocop:enable Metrics/MethodLength
65 66 67 |
# File 'lib/services/link_config.rb', line 65 def add_product(name:, price:, quantity: 1, sku: nil) @products << Product.new(name: name, price: price, quantity: quantity, sku: sku) end |
#format_result ⇒ Object
Transform payload to be sent rubocop:disable Metrics/MethodLength
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/services/link_config.rb', line 30 def format_result raise 'Product must be exists' if @products.empty? result = { 'do' => 'link', 'callbackType' => 'json', 'sys' => @sys, 'order_id' => @order_id, 'customer_phone' => @customer_phone, 'customer_email' => @customer_email, 'customer_extra' => @customer_extra, 'payment_method' => @payment_method, 'available_payment_methods' => (@available_payment_methods || NON_INSTALLMENTS_PAYMENT_METHODS).join('|'), 'urlReturn' => @urlReturn, 'urlSuccess' => @urlSuccess, 'urlNotification' => @urlNotification, 'installments_disabled' => (@installments_disabled || 1).to_s, 'currency' => @currency, 'payments_limit' => (@payments_limit || DEFAULT_PAYMENTS_LIMIT).to_s, 'link_expired' => link_expired }.compact! @products.each_with_index do |product, index| result.merge!({ "products[#{index}][name]" => product.name, "products[#{index}][sku]" => product.sku, "products[#{index}][price]" => product.price, "products[#{index}][quantity]" => product.quantity }) end result end |
#installments_disabled ⇒ Object
87 88 89 |
# File 'lib/services/link_config.rb', line 87 def installments_disabled !@installments_disabled.zero? end |
#installments_disabled=(disabled) ⇒ Object
83 84 85 |
# File 'lib/services/link_config.rb', line 83 def installments_disabled=(disabled) @installments_disabled = disabled ? 1 : 0 end |
#link_expired ⇒ Object
91 92 93 94 95 |
# File 'lib/services/link_config.rb', line 91 def link_expired tz = ActiveSupport::TimeZone.new(timezone) date = tz.now + form_access_duration.to_i.seconds date.strftime('%Y-%m-%d %H:%M') end |