Class: SaferpayRuby::PaymentGatewayApi

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PaymentGatewayApi

Returns a new instance of PaymentGatewayApi.



11
12
13
14
15
16
17
18
19
# File 'lib/saferpay_ruby.rb', line 11

def initialize(options = {})
  options.delete(:endpoint)
  options.delete_if { |k, v| v.nil? }
  @options = SaferpayRuby.options.merge(options)

  @options.each_pair do |key, val|
    send "#{key}=", val
  end
end

Instance Method Details

#initialize_payment_api(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/saferpay_ruby.rb', line 21

def initialize_payment_api(options = {})
  http = Net::HTTP.new(endpoint.host, endpoint.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  
  request = Net::HTTP::Post.new(endpoint)
  request["content-type"] = 'application/json; charset=utf-8'
  request["accept"] = 'application/json'
  request["authorization"] = authentication

  request.body = {
    "RequestHeader": {
      "SpecVersion": "1.7",
      "CustomerId": customer_id,
      "RequestId": options[:request_id],
      "RetryIndicator": 0
    },
    "TerminalId": terminal_id,
    "Payment": {
      "Amount": {
        "Value": options[:amount],
        "CurrencyCode": options[:currency]
      },
      "OrderId": options[:order_id],
      "Description": options[:description]
    },
    "PaymentMethods": options[:payment_methods],
    "ReturnUrls": {
      "Success": success_url,
      "Fail": failure_url
    }
  }.to_json
  http.request(request)
end

#initialize_payment_assert_api(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/saferpay_ruby.rb', line 56

def initialize_payment_assert_api(options = {})
  http = Net::HTTP.new(assert_endpoint.host, assert_endpoint.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Post.new(assert_endpoint)
  request["content-type"] = 'application/json; charset=utf-8'
  request["accept"] = 'application/json'
  request["authorization"] = authentication
  request.body = {
    "RequestHeader": {
      "SpecVersion": "1.15",
      "CustomerId": customer_id,
      "RequestId": options[:request_id],
      "RetryIndicator": 0
    },
    "Token": options[:token]
  }.to_json
  http.request(request)
end