Class: Datatrans::Config
- Inherits:
-
Object
- Object
- Datatrans::Config
- Defined in:
- lib/datatrans/config.rb
Constant Summary collapse
- ENVIRONMENTS =
[:development, :production].freeze
- DEFAULT_ENVIRONMENT =
:development
- DEFAULT_SIGN_KEY =
false
- SUBDOMAINS =
{ payment_page: "pay", server_to_server_api: "api" }
- DOMAIN =
"datatrans.com"
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#merchant_id ⇒ Object
readonly
Returns the value of attribute merchant_id.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#sign_key ⇒ Object
readonly
Returns the value of attribute sign_key.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
Configure with following options * :merchant_id (required) * :password (required) * :sign_key (defaults to false) * :environment (defaults to :development, available environments are defined in ENVIRONMENTS) * :proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass).
- #json_transaction(*args) ⇒ Object
-
#url(what, options = {}) ⇒ Object
Access a url, is automatically scoped to environment.
- #web_transaction(*args) ⇒ Object
- #xml_transaction(*args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Configure with following options
-
:merchant_id (required)
-
:password (required)
-
:sign_key (defaults to false)
-
:environment (defaults to :development, available environments are defined in ENVIRONMENTS)
-
:proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass)
22 23 24 25 26 27 28 29 30 |
# File 'lib/datatrans/config.rb', line 22 def initialize( = {}) @merchant_id = [:merchant_id] raise ArgumentError.new(":merchant_id is required") unless merchant_id self.environment = [:environment] || DEFAULT_ENVIRONMENT @password = [:password] raise ArgumentError.new(":password is required") unless password @sign_key = [:sign_key] || DEFAULT_SIGN_KEY @proxy = [:proxy] || {} end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
14 15 16 |
# File 'lib/datatrans/config.rb', line 14 def environment @environment end |
#merchant_id ⇒ Object (readonly)
Returns the value of attribute merchant_id.
14 15 16 |
# File 'lib/datatrans/config.rb', line 14 def merchant_id @merchant_id end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
14 15 16 |
# File 'lib/datatrans/config.rb', line 14 def password @password end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
14 15 16 |
# File 'lib/datatrans/config.rb', line 14 def proxy @proxy end |
#sign_key ⇒ Object (readonly)
Returns the value of attribute sign_key.
14 15 16 |
# File 'lib/datatrans/config.rb', line 14 def sign_key @sign_key end |
Instance Method Details
#json_transaction(*args) ⇒ Object
96 97 98 |
# File 'lib/datatrans/config.rb', line 96 def json_transaction(*args) JSON::Transaction.new(self, *args) end |
#url(what, options = {}) ⇒ Object
Access a url, is automatically scoped to environment
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/datatrans/config.rb', line 42 def url(what, = {}) case what when :web_authorize_url warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead." subdomain = SUBDOMAINS[:payment_page] path = "/upp/jsp/upStart.jsp" when :xml_authorize_url warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead." subdomain = SUBDOMAINS[:server_to_server_api] path = "/upp/jsp/XML_authorize.jsp" when :xml_settlement_url warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead." subdomain = SUBDOMAINS[:server_to_server_api] path = "/upp/jsp/XML_processor.jsp" when :xml_status_url warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead." subdomain = SUBDOMAINS[:server_to_server_api] path = "/upp/jsp/XML_status.jsp" when :init_transaction subdomain = SUBDOMAINS[:server_to_server_api] path = "/v1/transactions" when :authorize_transaction subdomain = SUBDOMAINS[:server_to_server_api] path = "/v1/transactions/authorize" when :start_json_transaction subdomain = SUBDOMAINS[:payment_page] path = "/v1/start/#{[:transaction_id]}" when :json_status_url # https://api.sandbox.datatrans.com/v1/transactions/{transactionId} subdomain = SUBDOMAINS[:server_to_server_api] path = "/v1/transactions/#{[:transaction_id]}" when :json_settle_url # https://api.sandbox.datatrans.com/v1/transactions/{transactionId}/settle subdomain = SUBDOMAINS[:server_to_server_api] path = "/v1/transactions/#{[:transaction_id]}/settle" else raise "Unknown wanted action '#{what}'." end subdomain += ".sandbox" unless environment == :production "https://#{subdomain}.#{DOMAIN}#{path}" end |
#web_transaction(*args) ⇒ Object
88 89 90 |
# File 'lib/datatrans/config.rb', line 88 def web_transaction(*args) Web::Transaction.new(self, *args) end |
#xml_transaction(*args) ⇒ Object
92 93 94 |
# File 'lib/datatrans/config.rb', line 92 def xml_transaction(*args) XML::Transaction.new(self, *args) end |