Class: ProcessingKz::StartTransaction

Inherits:
Object
  • Object
show all
Defined in:
lib/processing_kz/start_transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ StartTransaction

Returns a new instance of StartTransaction.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/processing_kz/start_transaction.rb', line 23

def initialize(args = {})
  @merchant_id = args[:merchant_id] || Config.merchant_id
  @currency_code = args[:currency_code] || Config.currency_code
  @language_code = args[:language_code] || Config.language_code
  @terminal_id = args[:terminal_id]
  @order_id = args[:order_id]
  @description = args[:description]
  @purchaser_name = args[:purchaser_name]
  @return_url = args[:return_url]
  @purchaser_email = args[:purchaser_email]
  @purchaser_phone = args[:purchaser_phone]
  @customer_reference = args[:customer_reference]
  self.goods_list = args[:goods_list]
  self.merchant_local_date_time = args[:merchant_local_date_time] || Time.now
  request!
end

Instance Attribute Details

#billing_addressObject (readonly)

Returns the value of attribute billing_address.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def billing_address
  @billing_address
end

#currency_codeObject (readonly)

Returns the value of attribute currency_code.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def currency_code
  @currency_code
end

#customer_referenceObject (readonly)

Returns the value of attribute customer_reference.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def customer_reference
  @customer_reference
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def description
  @description
end

#error_descriptionObject (readonly)

Returns the value of attribute error_description.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def error_description
  @error_description
end

#goods_listObject

Returns the value of attribute goods_list.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def goods_list
  @goods_list
end

#language_codeObject (readonly)

Returns the value of attribute language_code.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def language_code
  @language_code
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def merchant_id
  @merchant_id
end

#merchant_local_date_timeObject

Returns the value of attribute merchant_local_date_time.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def merchant_local_date_time
  @merchant_local_date_time
end

#order_idObject (readonly)

Returns the value of attribute order_id.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def order_id
  @order_id
end

#purchaser_emailObject (readonly)

Returns the value of attribute purchaser_email.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def purchaser_email
  @purchaser_email
end

#purchaser_nameObject (readonly)

Returns the value of attribute purchaser_name.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def purchaser_name
  @purchaser_name
end

#purchaser_phoneObject (readonly)

Returns the value of attribute purchaser_phone.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def purchaser_phone
  @purchaser_phone
end

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def redirect_url
  @redirect_url
end

#return_urlObject (readonly)

Returns the value of attribute return_url.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def return_url
  @return_url
end

#successObject (readonly)

Returns the value of attribute success.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def success
  @success
end

#terminal_idObject (readonly)

Returns the value of attribute terminal_id.



5
6
7
# File 'lib/processing_kz/start_transaction.rb', line 5

def terminal_id
  @terminal_id
end

Instance Method Details

#hashed_goods_listObject

Raises:



61
62
63
64
65
66
# File 'lib/processing_kz/start_transaction.rb', line 61

def hashed_goods_list
  raise NoGoodsError unless goods_list
  hash = []
  goods_list.each { |good| hash << good.to_hash }
  hash
end

#request!Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/processing_kz/start_transaction.rb', line 68

def request!
  client = Savon.client(wsdl: Config.wsdl, soap_version: 2, endpoint: Config.host)
  request = client.call(:start_transaction, message: { 
    transaction: {
      merchant_id: merchant_id,
      currency_code: currency_code,
      language_code: language_code,
      order_id: order_id,
      goods_list: hashed_goods_list,
      merchant_local_date_time: merchant_local_date_time,
      return_u_r_l: return_url,
      total_amount: total_amount.to_i
      }
    }
  )
  response(request.body[:start_transaction_response][:return])
end

#response(args = {}) ⇒ Object



86
87
88
89
90
91
# File 'lib/processing_kz/start_transaction.rb', line 86

def response(args = {})
  @success = args[:success]
  @redirect_url = args[:redirect_url]
  @error_description = args[:error_description]
  @customer_reference = args[:customer_reference]
end

#total_amountObject

Raises:



52
53
54
55
56
57
58
59
# File 'lib/processing_kz/start_transaction.rb', line 52

def total_amount
  raise NoGoodsError unless goods_list
  total = 0
  goods_list.each do |good|
    total += good.amount
  end
  total
end