Class: TBK::Commerce
- Inherits:
-
Object
- Object
- TBK::Commerce
- Defined in:
- lib/tbk/commerce.rb
Overview
Represents a commerce registered with Transbank
Constant Summary collapse
Instance Attribute Summary collapse
-
#environment ⇒ Symbol
readonly
The commerce environment.
-
#id ⇒ Integer
readonly
The registered commerce id.
-
#key ⇒ OpenSSL::PKey::RSA
readonly
The commerce secret RSA key.
Class Method Summary collapse
-
.default_commerce ⇒ TBK::Commerce
The default commerce.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Commerce
constructor
Initializes a new commerce.
-
#key_bytes ⇒ Integer
RSA key bytes.
-
#production? ⇒ Boolean
Whether or not the commerce is in production mode.
-
#test? ⇒ Boolean
Whether or not the commerce is in test mode.
Constructor Details
#initialize(attributes) ⇒ Commerce
Initializes a new commerce
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tbk/commerce.rb', line 23 def initialize(attributes) @environment = (attributes[:environment] || :production).to_sym raise TBK::CommerceError, "Invalid commerce environment" unless [:production,:test].include? @environment @id = attributes[:id] raise TBK::CommerceError, "Missing commerce id" if self.id.nil? @key = case attributes[:key] when String OpenSSL::PKey::RSA.new(attributes[:key]) when OpenSSL::PKey::RSA attributes[:key] when nil TEST_COMMERCE_KEY if self.test? end raise TBK::CommerceError, "Missing commerce key" if self.key.nil? raise TBK::CommerceError, "Commerce key must be a RSA private key" unless self.key.private? end |
Instance Attribute Details
#environment ⇒ Symbol (readonly)
Returns the commerce environment.
16 17 18 |
# File 'lib/tbk/commerce.rb', line 16 def environment @environment end |
#id ⇒ Integer (readonly)
The registered commerce id
8 9 10 |
# File 'lib/tbk/commerce.rb', line 8 def id @id end |
#key ⇒ OpenSSL::PKey::RSA (readonly)
The commerce secret RSA key
12 13 14 |
# File 'lib/tbk/commerce.rb', line 12 def key @key end |
Class Method Details
.default_commerce ⇒ TBK::Commerce
Returns The default commerce.
59 60 61 62 63 64 65 |
# File 'lib/tbk/commerce.rb', line 59 def self.default_commerce @default_commerce ||= Commerce.new({ :id => TBK.config.commerce_id, :key => TBK.config.commerce_key, :environment => TBK.config.environment }) unless TBK.config.commerce_id.nil? end |
Instance Method Details
#key_bytes ⇒ Integer
Returns RSA key bytes.
54 55 56 |
# File 'lib/tbk/commerce.rb', line 54 def key_bytes self.key.n.num_bytes end |
#production? ⇒ Boolean
Returns whether or not the commerce is in production mode.
49 50 51 |
# File 'lib/tbk/commerce.rb', line 49 def production? self.environment == :production end |
#test? ⇒ Boolean
Returns whether or not the commerce is in test mode.
44 45 46 |
# File 'lib/tbk/commerce.rb', line 44 def test? self.environment == :test end |