class MercuryPay

Public Class Methods

new(merchant_id, password) click to toggle source
# File lib/mercurypay.rb, line 8
def initialize(merchant_id, password)
        self.class.basic_auth merchant_id, password
end

Public Instance Methods

charge_with_card(options) click to toggle source

options = {

   card_number: 5499990123456781,
   cvc: 123,
   expir_month: 8,
   expir_year: 2016,
amount: 5.55,
invoice_id: "214dsfav331"

}

# File lib/mercurypay.rb, line 20
def charge_with_card(options)
        res = self.class.post("/Sale", body: {
                :InvoiceNo=> options[:invoice_id],
                :RecordNo=> "RecordNumberRequested",
                :Frequency=> "OneTime", # OneTime or Recurring
                :AcctNo=> options[:card_number].to_s,
                :ExpDate=> options[:expir_month].to_s.rjust(2, "0")+options[:expir_year].to_s[2..3],
                :Purchase=>options[:amount].to_s,
                :CVVData=> options[:cvc].to_s,
                :OperatorID=> "money2020"
        })

        response = parse_response res
end
charge_with_token(options) click to toggle source

options = {

   token: '',
amount: 5.55,
invoice_id: "214dsfav331"

}

# File lib/mercurypay.rb, line 40
def charge_with_token(options)
        res = self.class.post("/SaleByRecordNo", body: {
                :InvoiceNo=> options[:invoice_id],
                :RecordNo=> options[:token],
                :Frequency=> "OneTime", # OneTime or Recurring
                :Purchase=>options[:amount].to_s,
                :OperatorID=> "money2020"
        })

        response = parse_response res
end
validate_card(options) click to toggle source

options = {

card_number: 5499990123456781,
cvc: 123,
expir_month: 8,
expir_year: 2016

} Response: CmdStatus ::= Approved | Declined | Error

# File lib/mercurypay.rb, line 59
def validate_card(options)
        res = self.class.post("/ZeroAuth", body: {
                :InvoiceNo=> "1",
                :RecordNo=> "RecordNumberRequested",
                :Frequency=> "OneTime", # OneTime or Recurring
                :AcctNo=> options[:card_number].to_s,
                :ExpDate=> options[:expir_month].to_s.rjust(2, "0")+options[:expir_year].to_s[2..3],
                # "Purchase":"1.00",
                :CVVData=> options[:cvc].to_s,
                :OperatorID=> "money2020"
        })

        response = parse_response res
end

Private Instance Methods

parse_response(res) click to toggle source
# File lib/mercurypay.rb, line 75
def parse_response(res)
        temp_hash = {}
        res.body.split('&').each { |i| temp_hash[i.split('=')[0].to_sym] = i.split('=')[1] }
        return temp_hash
end