Class: VSafe::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vsafe/client.rb

Constant Summary collapse

SANDBOX_FINGERPRINT_PATH =
"ThreatMetrixUIRedirector".freeze
FINGERPRINT_PATH =
"PaySafeUIRedirector".freeze
REQUEST_CONTENT_TYPE =
"application/json; charset=utf-8".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



23
24
25
26
27
28
# File 'lib/vsafe/client.rb', line 23

def initialize
  # dup config in case we need to override default settings
  @config = VSafe.config.dup

  yield config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



21
22
23
# File 'lib/vsafe/client.rb', line 21

def config
  @config
end

Instance Method Details

#charge_authorize(params) ⇒ Object



38
39
40
# File 'lib/vsafe/client.rb', line 38

def charge_authorize(params)
  VSafe::Responses::ChargeAuthorize.new(request(service_url("ChargeAuthorize"), params))
end

#charge_confirm(params) ⇒ Object



42
43
44
# File 'lib/vsafe/client.rb', line 42

def charge_confirm(params)
  VSafe::Responses::ChargeConfirm.new(request(service_url("ChargeConfirm"), params))
end

#charge_sale(params) ⇒ Object



54
55
56
# File 'lib/vsafe/client.rb', line 54

def charge_sale(params)
  VSafe::Responses::ChargeSale.new(request(service_url("ChargeSale"), params))
end

#fingerprint_urlObject



71
72
73
74
# File 'lib/vsafe/client.rb', line 71

def fingerprint_url
  base_uri = URI.join(config.jsonp_url, '/')
  @_fingerprint_url ||= URI.join(base_uri, config.sandbox ? SANDBOX_FINGERPRINT_PATH : FINGERPRINT_PATH).to_s
end

#get_payment_status(params) ⇒ Object



62
63
64
# File 'lib/vsafe/client.rb', line 62

def get_payment_status(params)
  VSafe::Responses::GetPaymentStatus.new(request(service_url("GetPaymentStatus"), params))
end

#get_session_tagsObject



30
31
32
33
34
35
36
# File 'lib/vsafe/client.rb', line 30

def get_session_tags
  params = {
    TransactionID: SecureRandom.uuid
  }

  VSafe::Responses::GetSessionTags.new(request(service_url("GetSessionTags"), params))
end

#heartbeatObject



50
51
52
# File 'lib/vsafe/client.rb', line 50

def heartbeat
  VSafe::Response.new(request(service_url("HeartBeat")))
end

#reverse_payment(params) ⇒ Object



46
47
48
# File 'lib/vsafe/client.rb', line 46

def reverse_payment(params)
  VSafe::Responses::ReversePayment.new(request(service_url("ReversePayment"), params))
end

#service_url(endpoint = nil, jsonp = false) ⇒ Object



66
67
68
69
# File 'lib/vsafe/client.rb', line 66

def service_url(endpoint = nil, jsonp = false)
  base_uri = jsonp ? config.jsonp_url : config.url
  endpoint.nil? ? base_uri : File.join(base_uri, endpoint)
end

#validate_charge_account(params) ⇒ Object



58
59
60
# File 'lib/vsafe/client.rb', line 58

def (params)
  VSafe::Responses::ValidateChargeAccount.new(request(service_url("ValidateChargeAccount"), params))
end