Class: PayU::Plan

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/pay_u/plan.rb

Constant Summary collapse

ENDPOINT =
"rest/v#{PayU::API_VERSION}/plans".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#create_url, #delete, included, #save

Class Method Details

.new_from_api(params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pay_u/plan.rb', line 21

def self.new_from_api(params)
  plan = super(params)

  plan.code = params["planCode"]
  plan.currency = params["additionalValues"].first["currency"].to_s
  plan.data = params["additionalValues"].inject({}) do |memo, hash|
    memo.merge(hash["name"].to_s => hash["value"])
  end

  plan
end

Instance Method Details

#to_paramsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pay_u/plan.rb', line 34

def to_params
  {
    accountId: ,
    planCode: code,
    description: description,
    interval: interval,
    intervalCount: interval_count,
    maxPaymentsAllowed: max_payments_allowed,
    paymentAttemptsDelay: payment_attempts_delay,
    additionalValues: data.map do |name, value|
      {name: name, value: value, currency: currency.to_s}
    end,
  }
end

#to_update_paramsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pay_u/plan.rb', line 50

def to_update_params
  {
    planCode: code,
    description: description,
    paymentAttemptsDelay: payment_attempts_delay,
    maxPendingPayments: max_pending_payments,
    maxPaymentAttempts: max_payment_attempts,
    additionalValues: data.map do |name, value|
      {name: name, value: value, currency: currency.to_s}
    end,
  }
end