Class: Buckaroo::Gateway

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

Constant Summary collapse

LANGUAGE =
'nl'
CURRENCY =
'EUR'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.environmentObject

Holds the environment in which the run (default is test)



18
19
20
# File 'lib/buckaroo/gateway.rb', line 18

def environment
  @environment
end

.localeObject

Holds the users locale



28
29
30
# File 'lib/buckaroo/gateway.rb', line 28

def locale
  @locale
end

.secretObject

Holds the secret that should be used for the website key.



25
26
27
# File 'lib/buckaroo/gateway.rb', line 25

def secret
  @secret
end

.website_keyObject

Holds the global iDEAL merchant id. Make sure to use a string with leading zeroes if needed.



22
23
24
# File 'lib/buckaroo/gateway.rb', line 22

def website_key
  @website_key
end

Class Method Details

.test?Boolean

Returns whether we’re in test mode or not.

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/buckaroo/gateway.rb', line 35

def self.test?
  if self.environment.nil?
    self.environment = :test
  end
  self.environment == :test
end

Instance Method Details

#capture(transaction_id) ⇒ Object

Sends a status request for the specified transaction_id and returns an StatusResponse.

It is your responsibility as the merchant to check if the payment has been made until you receive a response with a finished status like: ‘Success’, ‘Cancelled’, ‘Expired’, everything else equals ‘Open’.

Example

capture_response = gateway.capture(@purchase.transaction_id)
if capture_response.success?
  @purchase.update_attributes!(:paid => true)
  flash[:notice] = "Congratulations, you are now the proud owner of a Dutch windmill!"
end

See the Gateway class description for a more elaborate example.



80
81
82
83
84
85
# File 'lib/buckaroo/gateway.rb', line 80

def capture(transaction_id)
  config_complete!

  a = build_status_request(transaction_id)
  post_data request_url('transactionstatus'), a, StatusResponse
end

#request_url(operation) ⇒ Object

Returns the endpoint for the request.

Automatically uses test or live URLs based on the configuration.



45
46
47
48
49
50
51
52
53
# File 'lib/buckaroo/gateway.rb', line 45

def request_url(operation)
  if self.class.test?
    url = URLS[:test_url]
  else
    url = URLS[:live_url]
  end
  return url if operation.nil?
  url + '?op=' + operation
end

#setup_purchase(money, options) ⇒ Object

TODO: Add comment here



56
57
58
59
60
61
62
# File 'lib/buckaroo/gateway.rb', line 56

def setup_purchase(money, options)
  config_complete!
  requires!(options, :order_id, :return_url, :description, :method)

  req = build_transaction_request(money, options)
  post_data request_url('transactionrequest'), req, TransactionResponse
end