Class: MercuryPay

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mercurypay.rb

Instance Method Summary collapse

Constructor Details

#initialize(merchant_id, password) ⇒ MercuryPay

Returns a new instance of MercuryPay.



8
9
10
# File 'lib/mercurypay.rb', line 8

def initialize(merchant_id, password)
  self.class.basic_auth merchant_id, password
end

Instance Method Details

#charge_with_card(options) ⇒ Object

options = { card_number: 5499990123456781, cvc: 123, expir_month: 8, expir_year: 2016,

amount: 5.55,
invoice_id: "214dsfav331"

}



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object

options = { token: ”,

amount: 5.55,
invoice_id: "214dsfav331"

}



40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object

options = { card_number: 5499990123456781, cvc: 123, expir_month: 8, expir_year: 2016 } Response: CmdStatus ::= Approved | Declined | Error



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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