Class: ZoozPayments::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/zooz_payments/api.rb

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



6
7
8
9
# File 'lib/zooz_payments/api.rb', line 6

def initialize
  @errors = []
  @params = {}
end

Instance Method Details

#open_transaction(cmd, amount, currency_code, optional_args = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zooz_payments/api.rb', line 11

def open_transaction(cmd,amount,currency_code,optional_args = {})
  return false unless self.valid?

  args = {'cmd' => cmd, 'amount' => amount, 'currencyCode' => currency_code}.merge(optional_args)
  http_response = HTTParty.post(ZoozPayments.url,
                                :format => :plain,
                                :query => args,
                                :headers => {
                                    'ZooZ-Unique-ID' => ZoozPayments.unique_id,
                                    'ZooZ-App-Key' => ZoozPayments.app_key,
                                    'ZooZ-Response-Type' => ZoozPayments.response_type,
                                })
  CGI.parse(http_response.body)
end

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/zooz_payments/api.rb', line 40

def valid?
  @errors = []
  @errors << 'unique_id is required' if ZoozPayments.unique_id.nil?
  @errors << 'app_key is required' if ZoozPayments.app_key.nil?
  @errors << 'response_type is required' if ZoozPayments.response_type.nil?
  @errors.empty?
end

#verify_transaction(cmd, transaction_id, transaction_display_id, optional_args = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zooz_payments/api.rb', line 26

def verify_transaction(cmd, transaction_id,transaction_display_id,optional_args={})
  return false unless self.valid?

  args = {'cmd' => cmd, 'transactionID' => transaction_id, 'transactionDisplayID' => transaction_display_id}.merge(optional_args)
  http_response = HTTParty.post(ZoozPayments.url, :format => :plain,
                                :query => args,
                                :headers => {
                                    'ZooZ-Unique-ID' => ZoozPayments.unique_id,
                                    'ZooZ-App-Key' => ZoozPayments.app_key,
                                    'ZooZ-Response-Type' => ZoozPayments.response_type,
                                })
  CGI.parse(http_response.body)
end