Module: Wizypay::CardMethods

Includes:
SimpleHmac::Helper
Included in:
DebitCard, GiftCard
Defined in:
lib/wizypay/card_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#base_pathObject



41
42
43
# File 'lib/wizypay/card_methods.rb', line 41

def base_path
  self.class.base_path
end

#cancelObject



45
46
47
# File 'lib/wizypay/card_methods.rb', line 45

def cancel
  ApiClient.post("#{base_path}/#{URI::encode_www_form_component reference}/cancel")
end

#created_atObject



76
77
78
79
# File 'lib/wizypay/card_methods.rb', line 76

def created_at
  return nil unless super.present?
  Time.parse(super)
end

#operationsObject



81
82
83
# File 'lib/wizypay/card_methods.rb', line 81

def operations
  Collection.new(VdcOperation, super['data'], super['meta'])
end

#refund(amount) ⇒ Object



49
50
51
# File 'lib/wizypay/card_methods.rb', line 49

def refund(amount)
  ApiClient.post("#{base_path}/#{URI::encode_www_form_component reference}/refund", amount: amount)
end

#refundsObject



85
86
87
# File 'lib/wizypay/card_methods.rb', line 85

def refunds
  Collection.new(Refund, super['data'], super['meta'])
end

#saveObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/wizypay/card_methods.rb', line 65

def save
  reinitialize ApiClient.post(base_path, to_h)
rescue => e
  begin
    cancel
  rescue RestClient::Exception
    #no-op
  end
  raise e
end

#urlObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wizypay/card_methods.rb', line 53

def url
  timestamp    = Time.now.utc.httpdate
  security     = sign_string("#{reference}\n#{timestamp}", ApiClient.api_secret)
  query_string = {
      key:       ApiClient.api_key,
      timestamp: timestamp,
      reference: reference,
      security:  security
  }.map { |k, v| "#{k}=#{URI::encode_www_form_component(v)}" }.join('&')
  "#{ApiClient.api_endpoint}/widget?#{query_string}"
end