class PromisePay::Session

Attributes

amount[RW]
buyer_country[RW]
buyer_email[RW]
buyer_firstname[RW]
buyer_lastname[RW]
current_user_id[RW]
external_buyer_id[RW]
external_item_id[RW]
external_seller_id[RW]
fee_ids[RW]
item_name[RW]
payment_type_id[RW]
seller_country[RW]
seller_email[RW]
seller_firstname[RW]
seller_lastname[RW]
token[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/promise_pay/session.rb, line 25
def initialize(options = {})
  @current_user_id    = options.fetch(:current_user_id)     { nil }
  @item_name          = options.fetch(:item_name)           { nil }
  @amount             = options.fetch(:amount)              { nil }
  @seller_lastname    = options.fetch(:seller_lastname)     { nil }
  @seller_firstname   = options.fetch(:seller_firstname)    { nil }
  @buyer_lastname     = options.fetch(:buyer_lastname)      { nil }
  @buyer_firstname    = options.fetch(:buyer_firstname)     { nil }
  @seller_email       = options.fetch(:seller_email)        { nil }
  @buyer_email        = options.fetch(:buyer_email)         { nil }
  @external_item_id   = options.fetch(:external_item_id)    { nil }
  @external_seller_id = options.fetch(:external_seller_id)  { nil }
  @external_buyer_id  = options.fetch(:external_buyer_id)   { nil }
  @fee_ids            = options.fetch(:fee_ids)             { nil }
  @payment_type_id    = options.fetch(:payment_type_id)     { nil }
  @seller_country     = options.fetch(:seller_country)      { nil }
  @buyer_country      = options.fetch(:buyer_country)       { nil }
end

Public Instance Methods

request_token() click to toggle source
# File lib/promise_pay/session.rb, line 44
def request_token
  enforce_valid_params!

  request = PromisePay::Request.new(path: api_resource)
  response = request.execute

  @token = JSON.parse(response)["token"]
  token
end

Private Instance Methods

api_resource() click to toggle source
# File lib/promise_pay/session.rb, line 56
def api_resource
  "request_session_token?#{query_string}"
end
enforce_valid_params!() click to toggle source
# File lib/promise_pay/session.rb, line 81
def enforce_valid_params!
  required_params.each do |attr|
    if self.send(attr).blank?
      raise InvalidSessionRequest, "Missing #{attr} value"
    end
  end
end
query_string() click to toggle source
# File lib/promise_pay/session.rb, line 60
def query_string
  {
    current_user_id:    current_user_id,
    item_name:          item_name,
    amount:             amount,
    seller_lastname:    seller_lastname,
    seller_firstname:   seller_firstname,
    buyer_lastname:     buyer_lastname,
    buyer_firstname:    buyer_firstname,
    seller_email:       seller_email,
    buyer_email:        buyer_email,
    external_item_id:   external_item_id,
    external_seller_id: external_seller_id,
    external_buyer_id:  external_buyer_id,
    fee_ids:            fee_ids,
    payment_type_id:    payment_type_id,
    seller_country:     PromisePay::Country.code_for(seller_country),
    buyer_country:      PromisePay::Country.code_for(buyer_country)
  }.reject { |k,v| v.nil? }.to_param
end
required_params() click to toggle source
# File lib/promise_pay/session.rb, line 89
def required_params
  [
    :current_user_id,
    :item_name,
    :amount,
    :seller_firstname,
    :buyer_firstname,
    :seller_email,
    :buyer_email,
    :external_item_id,
    :external_seller_id,
    :external_buyer_id,
    :payment_type_id,
    :seller_country,
    :buyer_country
  ]
end