Class: Buckaroo::Ideal::RequestSignature

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/buckaroo-ideal/request_signature.rb

Overview

Digital signature generator for Buckaroo::Ideal::Order instances.

A digital signature is used to sign your request so the Buckaroo Payment Service can validate that the request was made by your application.

A digital signature is composed by generating a MD5 hash of the following values:

  • Merchant Key: The merchant_key that is provided by Buckaroo and set in Buckaroo::Ideal::Config.

  • Invoice Number: The invoice_number that is set in your Buckaroo::Ideal::Order instance.

  • Amount: The amount that is set in your Buckaroo::Ideal::Order instance in cents.

  • Currency: The currency that is set in your Buckaroo::Ideal::Order instance.

  • Mode: The test_mode that is set in Buckaroo::Ideal::Config.

To create a signature for an Buckaroo::Ideal::Order, instantiate a new Buckaroo::Ideal::RequestSignature and provide the order:

order = Buckaroo::Ideal::Order.new(amount: 100, invoice_number: 'EETNU-123')
signature = Buckaroo::Ideal::Signature.new(order)

Constant Summary

Constants included from Util

Util::STRIP_ACCENTS_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#compact, #from_cents, #from_numeric_boolean, #to_cents, #to_normalized_string, #to_numeric_boolean

Constructor Details

#initialize(order) ⇒ Buckaroo::Ideal::Signature

Initialize a new Buckaroo::Ideal::Signature instance for the given order.

Parameters:

  • The (Buckaroo::Ideal::Order)

    order that needs to be signed.

  • The (String)

    secret key that is used to sign the order. Defaults to the configured Buckaroo::Ideal::Config.secret_key.



51
52
53
# File 'lib/buckaroo-ideal/request_signature.rb', line 51

def initialize(order)
  @order  = order
end

Instance Attribute Details

#orderBuckaroo::Ideal::Order (readonly)

Returns The order that is being signed.

Returns:



32
33
34
# File 'lib/buckaroo-ideal/request_signature.rb', line 32

def order
  @order
end

Instance Method Details

#merchant_keyString

Returns The configured merchant_key in Buckaroo::Ideal::Config.

Returns:

  • (String)

    The configured merchant_key in Buckaroo::Ideal::Config



38
# File 'lib/buckaroo-ideal/request_signature.rb', line 38

delegate :merchant_key, :to => Config

#secret_keyString

Returns The configured secret_key in Buckaroo::Ideal::Config.

Returns:

  • (String)

    The configured secret_key in Buckaroo::Ideal::Config



41
# File 'lib/buckaroo-ideal/request_signature.rb', line 41

delegate :secret_key,   :to => Config

#signatureObject Also known as: to_s



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/buckaroo-ideal/request_signature.rb', line 55

def signature
  salt = [
    merchant_key,
    to_normalized_string(order.invoice_number),
    to_cents(order.amount),
    order.currency,
    to_numeric_boolean(test_mode),
    secret_key
  ].join
  
  Digest::MD5.hexdigest(salt)
end

#test_modeBoolean

Returns The configured test_mode in Buckaroo::Ideal::Config.

Returns:

  • (Boolean)

    The configured test_mode in Buckaroo::Ideal::Config



35
# File 'lib/buckaroo-ideal/request_signature.rb', line 35

delegate :test_mode,    :to => Config