Class: Buckaruby::Gateway

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/buckaruby/gateway.rb

Overview

Implementation of the BPE 3.0 NVP Gateway.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Gateway

Returns a new instance of Gateway.



12
13
14
# File 'lib/buckaruby/gateway.rb', line 12

def initialize(options = {})
  @options = options
end

Instance Method Details

#cancel_transaction(options = {}) ⇒ Object

Cancel a transaction.



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/buckaruby/gateway.rb', line 123

def cancel_transaction(options = {})
  logger.debug("[cancel_transaction] options=#{options.inspect}")

  validate_required_params!(options, :transaction_id)

  response = execute_request(:status, options)
  unless response.cancellable?
    raise NonCancellableTransactionException, options[:transaction_id]
  end

  execute_request(:cancel, options)
end

#cancellable_transaction?(options = {}) ⇒ Boolean

Checks if a transaction is cancellable.

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
# File 'lib/buckaruby/gateway.rb', line 113

def cancellable_transaction?(options = {})
  logger.debug("[cancellable_transaction?] options=#{options.inspect}")

  validate_required_params!(options, :transaction_id)

  response = execute_request(:status, options)
  response.cancellable?
end

#issuers(payment_method) ⇒ Object

Get a list with payment issuers (currently only iDEAL).



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/buckaruby/gateway.rb', line 27

def issuers(payment_method)
  if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING
    raise ArgumentError, 'Invalid payment method, only iDEAL is supported.'
  end

  response = execute_request(:specify_transaction, payment_method: payment_method)

  service = response.services.first
  description = service[:actiondescription].find { |action| action[:description].casecmp(Action::PAY).zero? } if service
  params = description[:requestparameters].find { |param| param[:name].casecmp('issuer').zero? } if description
  items = params[:listitemdescription] if params

  items&.map { |item| [item[:value], item[:description]] }.to_h
end

#parse_push(response) ⇒ Object

Parse and verify the push response.



137
138
139
140
141
142
143
# File 'lib/buckaruby/gateway.rb', line 137

def parse_push(response)
  if response.nil? || response.empty?
    raise ArgumentError, 'No push parameters found'
  end

  PushResponse.new(response, config)
end

#payment_methodsObject

Returns the payment methods enabled by Buckaroo and supported by this library.



17
18
19
20
21
22
23
24
# File 'lib/buckaruby/gateway.rb', line 17

def payment_methods
  valid_payment_methods = PaymentMethod.all - [PaymentMethod::TRANSFER]

  response = execute_request(:specify_transaction)
  services = response.services.map { |service| service[:name] }

  services & valid_payment_methods
end

#recurrent_transaction(options = {}) ⇒ Object

Setup a recurrent transaction.



54
55
56
57
58
59
60
# File 'lib/buckaruby/gateway.rb', line 54

def recurrent_transaction(options = {})
  logger.debug("[recurrent_transaction] options=#{options.inspect}")

  validate_recurrent_transaction_params!(options)

  execute_request(:recurrent_transaction, options)
end

#refund_transaction(options = {}) ⇒ Object

Refund a transaction.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/buckaruby/gateway.rb', line 80

def refund_transaction(options = {})
  logger.debug("[refund_transaction] options=#{options.inspect}")

  validate_refund_transaction_params!(options)

  response = execute_request(:refund_info, options)
  unless response.refundable?
    raise NonRefundableTransactionException, options[:transaction_id]
  end

  # Pick maximum refundable amount if amount is not supplied.
  options[:amount] = response.maximum_amount unless options[:amount]

  # Fill required parameters with data from refund info request.
  options.merge!(
    payment_method: response.payment_method,
    invoicenumber: response.invoicenumber,
    currency: response.currency
  )

  execute_request(:refund_transaction, options)
end

#refundable_transaction?(options = {}) ⇒ Boolean

Checks if a transaction is refundable.

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
# File 'lib/buckaruby/gateway.rb', line 70

def refundable_transaction?(options = {})
  logger.debug("[refundable_transaction?] options=#{options.inspect}")

  validate_required_params!(options, :transaction_id)

  response = execute_request(:refund_info, options)
  response.refundable?
end

#setup_transaction(options = {}) ⇒ Object

Setup a new transaction.



43
44
45
46
47
48
49
50
51
# File 'lib/buckaruby/gateway.rb', line 43

def setup_transaction(options = {})
  logger.debug("[setup_transaction] options=#{options.inspect}")

  validate_setup_transaction_params!(options)

  normalize_consumer_iban!(options) if options[:payment_method] == PaymentMethod::SEPA_DIRECT_DEBIT

  execute_request(:setup_transaction, options)
end

#specify_transaction(options = {}) ⇒ Object

Retrieve the specification for setting up a transaction.



63
64
65
66
67
# File 'lib/buckaruby/gateway.rb', line 63

def specify_transaction(options = {})
  logger.debug("[specify_transaction] options=#{options.inspect}")

  execute_request(:specify_transaction, options)
end

#status(options = {}) ⇒ Object

Get transaction status.



104
105
106
107
108
109
110
# File 'lib/buckaruby/gateway.rb', line 104

def status(options = {})
  logger.debug("[status] options=#{options.inspect}")

  validate_status_params!(options)

  execute_request(:status, options)
end