Friday, April 12, 2013

Common wealth bank payment

To make a credit card payment in Australia there is one bank named as common wealth bank. which accepts credit cards payments..
To accepts a payment i do the following steps
# Send requests to the gateway's test servers
# #first set everything in test mode. later just need to change this environment to production.but for that we need to talk with bank service center to get the details of current live account and its credentials mapped with this account
  
cardexpdate=Date.civil(params["credit_card"]["expiring_date(1i)"].to_i,params["credit_card"]["expiring_date(2i)"].to_i) amount_in_cents = amount_in_cents 

uri = URI.parse("https://migs.mastercard.com.au/vpcdps?vpc_Version=1&vpc_Command=pay&vpc_AccessCode=tttttttttt&vpc_MerchTxnRef=#{params[:credit_card][:user_id]}&vpc_Merchant=Ttttttttttttt&vpc_OrderInfo=#{params[:credit_card][:user_id]}&vpc_Amount=#{amount_in_cents.to_i}&vpc_CardNum=#{no}&vpc_cardExp=#{cardexpdate.strftime('%y%m')}&vpc_locale=en")  

  http = Net::HTTP.new(uri.host, uri.port)
#http.use_ssl = true
#http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
response = http.request(request)
responsearray=response.body.split("&")
responsearray.each do |res|
if res.split("=")[0] == "vpc_Message"
if res.split("=")[1] =="Approved"
              self.state = 'online_validated'
                    self.save
              #invoice.validating
   elsif res.split("=")[1] =="Declined"
       self.state = 'Declined'
                   self.save
      elsif res.split("=")[1] =="Unspecified+Failure"
self.state = "Unspecified+Failure"
                          self.save
              elsif res.split("=")[1] =="Referred"
                               self.state = "Referred"
                                self.save
            elsif res.split("=")[1] =="Timed+Out"
self.state = "Timed+Out"
                  self.save
            elsif res.split("=")[1] =="Expired+Card"
            self.state = "Expired+Card"
                    self.save
          elsif res.split("=")[1] =="Insufficient+Funds"
self.state = "Insufficient+Funds"
                    self.save
else
self.state = res.split("=")[1]
                    self.save
end
end
end

No comments:

Post a Comment