Class: Debitech::ServerApi
- Inherits:
-
Object
- Object
- Debitech::ServerApi
- Defined in:
- lib/debitech/server_api.rb
Defined Under Namespace
Classes: ChargeResult, ValidUniqueReferenceRequired
Constant Summary collapse
- LEAST_NUMBER_OF_CHARACTERS_IN_UNIQUE_ID =
Don’t know about the upper bound, but we need it to be atleast 5 characters to be able to search for it in DIBS Manager.
5
Instance Method Summary collapse
- #charge(opts = {}) ⇒ Object
-
#initialize(config = {}) ⇒ ServerApi
constructor
A new instance of ServerApi.
Constructor Details
#initialize(config = {}) ⇒ ServerApi
Returns a new instance of ServerApi.
30 31 32 33 |
# File 'lib/debitech/server_api.rb', line 30 def initialize(config = {}) @config = config @soap_api = DebitechSoap::API.new(config[:soap_opts]) end |
Instance Method Details
#charge(opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/debitech/server_api.rb', line 35 def charge(opts = {}) if opts[:amount] && (opts[:amount] - opts[:amount].to_i) > 0 raise "The amount (#{opts[:amount]}) contains fractions (for example 10.44 instead of 10), amount should specified in cents." end if opts[:unique_reference].to_s.size < LEAST_NUMBER_OF_CHARACTERS_IN_UNIQUE_ID raise ValidUniqueReferenceRequired end data = "001:payment:1:#{opts[:amount].to_i}:" mac = Mac.build [ data, opts[:currency], opts[:unique_reference], @config[:secret_key] ] extra = "&method=#{@config[:method]}¤cy=#{opts[:currency]}&MAC=#{mac}&referenceNo=#{opts[:unique_reference]}" response = @soap_api.subscribe_and_settle(:verifyID => opts[:verify_id], :ip => opts[:ip], :data => data, :extra => extra) ChargeResult.new(response) end |