lib/active_merchant/billing/gateways/payu_in.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/payu_in.rb in activemerchant-1.80.0
- old
+ new
@@ -1,15 +1,15 @@
# encoding: utf-8
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PayuInGateway < Gateway
- self.test_url = "https://test.payu.in/_payment"
- self.live_url = "https://secure.payu.in/_payment"
+ self.test_url = 'https://test.payu.in/_payment'
+ self.live_url = 'https://secure.payu.in/_payment'
- TEST_INFO_URL = "https://test.payu.in/merchant/postservice.php?form=2"
- LIVE_INFO_URL = "https://info.payu.in/merchant/postservice.php?form=2"
+ TEST_INFO_URL = 'https://test.payu.in/merchant/postservice.php?form=2'
+ LIVE_INFO_URL = 'https://info.payu.in/merchant/postservice.php?form=2'
self.supported_countries = ['IN']
self.default_currency = 'INR'
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :maestro]
@@ -30,32 +30,32 @@
add_addresses(post, options)
add_customer_data(post, options)
add_auth(post)
MultiResponse.run do |r|
- r.process{commit(url("purchase"), post)}
- if(r.params["enrolled"].to_s == "0")
- r.process{commit(r.params["post_uri"], r.params["form_post_vars"])}
+ r.process{commit(url('purchase'), post)}
+ if(r.params['enrolled'].to_s == '0')
+ r.process{commit(r.params['post_uri'], r.params['form_post_vars'])}
else
r.process{handle_3dsecure(r)}
end
end
end
def refund(money, authorization, options={})
- raise ArgumentError, "Amount is required" unless money
+ raise ArgumentError, 'Amount is required' unless money
post = {}
- post[:command] = "cancel_refund_transaction"
+ post[:command] = 'cancel_refund_transaction'
post[:var1] = authorization
post[:var2] = generate_unique_id
post[:var3] = amount(money)
add_auth(post, :command, :var1)
- commit(url("refund"), post)
+ commit(url('refund'), post)
end
def supports_scrubbing?
true
end
@@ -80,21 +80,21 @@
post[:key] = @options[:key]
post[:txn_s2s_flow] = 1
digest_keys = PAYMENT_DIGEST_KEYS if digest_keys.empty?
digest = Digest::SHA2.new(512)
- digest << @options[:key] << "|"
+ digest << @options[:key] << '|'
digest_keys.each do |key|
- digest << (post[key.to_sym] || "") << "|"
+ digest << (post[key.to_sym] || '') << '|'
end
digest << @options[:salt]
post[:hash] = digest.hexdigest
end
def add_customer_data(post, options)
- post[:email] = clean(options[:email] || "unknown@example.com", nil, 50)
- post[:phone] = clean((options[:billing_address] && options[:billing_address][:phone]) || "11111111111", :numeric, 50)
+ post[:email] = clean(options[:email] || 'unknown@example.com', nil, 50)
+ post[:phone] = clean((options[:billing_address] && options[:billing_address][:phone]) || '11111111111', :numeric, 50)
end
def add_addresses(post, options)
if options[:billing_address]
post[:address1] = clean(options[:billing_address][:address1], :text, 100)
@@ -107,11 +107,11 @@
if options[:shipping_address]
if options[:shipping_address][:name]
first, *rest = options[:shipping_address][:name].split(/\s+/)
post[:shipping_firstname] = clean(first, :name, 60)
- post[:shipping_lastname] = clean(rest.join(" "), :name, 20)
+ post[:shipping_lastname] = clean(rest.join(' '), :name, 20)
end
post[:shipping_address1] = clean(options[:shipping_address][:address1], :text, 100)
post[:shipping_address2] = clean(options[:shipping_address][:address2], :text, 100)
post[:shipping_city] = clean(options[:shipping_address][:city], :text, 50)
post[:shipping_state] = clean(options[:shipping_address][:state], :text, 50)
@@ -123,26 +123,26 @@
def add_invoice(post, money, options)
post[:amount] = amount(money)
post[:txnid] = clean(options[:order_id], :alphanumeric, 30)
- post[:productinfo] = clean(options[:description] || "Purchase", nil, 100)
+ post[:productinfo] = clean(options[:description] || 'Purchase', nil, 100)
- post[:surl] = "http://example.com"
- post[:furl] = "http://example.com"
+ post[:surl] = 'http://example.com'
+ post[:furl] = 'http://example.com'
end
BRAND_MAP = {
- visa: "VISA",
- master: "MAST",
- american_express: "AMEX",
- diners_club: "DINR",
- maestro: "MAES"
+ visa: 'VISA',
+ master: 'MAST',
+ american_express: 'AMEX',
+ diners_club: 'DINR',
+ maestro: 'MAES'
}
def add_payment(post, payment)
- post[:pg] = "CC"
+ post[:pg] = 'CC'
post[:firstname] = clean(payment.first_name, :name, 60)
post[:lastname] = clean(payment.last_name, :name, 20)
post[:bankcode] = BRAND_MAP[payment.brand.to_sym]
post[:ccnum] = payment.number
@@ -151,20 +151,20 @@
post[:ccexpmon] = format(payment.month, :two_digits)
post[:ccexpyr] = format(payment.year, :four_digits)
end
def clean(value, format, maxlength)
- value ||= ""
+ value ||= ''
value = case format
when :alphanumeric
- value.gsub(/[^A-Za-z0-9]/, "")
+ value.gsub(/[^A-Za-z0-9]/, '')
when :name
- value.gsub(/[^A-Za-z ]/, "")
+ value.gsub(/[^A-Za-z ]/, '')
when :numeric
- value.gsub(/[^0-9]/, "")
+ value.gsub(/[^0-9]/, '')
when :text
- value.gsub(/[^A-Za-z0-9@\-_\/\. ]/, "")
+ value.gsub(/[^A-Za-z0-9@\-_\/\. ]/, '')
when nil
value
else
raise "Unknown format #{format} for #{value}"
end
@@ -172,37 +172,37 @@
end
def parse(body)
top = JSON.parse(body)
- if result = top.delete("result")
- result.split("&").inject({}) do |hash, string|
- key, value = string.split("=")
- hash[CGI.unescape(key).downcase] = CGI.unescape(value || "")
+ if result = top.delete('result')
+ result.split('&').inject({}) do |hash, string|
+ key, value = string.split('=')
+ hash[CGI.unescape(key).downcase] = CGI.unescape(value || '')
hash
end.each do |key, value|
if top[key]
top["result_#{key}"] = value
else
top[key] = value
end
end
end
- if response = top.delete("response")
+ if response = top.delete('response')
top.merge!(response)
end
top
rescue JSON::ParserError
{
- "error" => "Invalid response received from the PayU API. (The raw response was `#{body}`)."
+ 'error' => "Invalid response received from the PayU API. (The raw response was `#{body}`)."
}
end
def commit(url, parameters)
- response = parse(ssl_post(url, post_data(parameters), "Accept-Encoding" => "identity"))
+ response = parse(ssl_post(url, post_data(parameters), 'Accept-Encoding' => 'identity'))
Response.new(
success_from(response),
message_from(response),
response,
@@ -211,38 +211,38 @@
)
end
def url(action)
case action
- when "purchase"
+ when 'purchase'
(test? ? test_url : live_url)
else
(test? ? TEST_INFO_URL : LIVE_INFO_URL)
end
end
def success_from(response)
- if response["result_status"]
- (response["status"] == "success" && response["result_status"] == "success")
+ if response['result_status']
+ (response['status'] == 'success' && response['result_status'] == 'success')
else
- (response["status"] == "success" || response["status"].to_s == "1")
+ (response['status'] == 'success' || response['status'].to_s == '1')
end
end
def message_from(response)
- (response["error_message"] || response["error"] || response["msg"])
+ (response['error_message'] || response['error'] || response['msg'])
end
def authorization_from(response)
- response["mihpayid"]
+ response['mihpayid']
end
def post_data(parameters = {})
PostData.new.merge!(parameters).to_post_data
end
def handle_3dsecure(response)
- Response.new(false, "3D-secure enrolled cards are not supported.")
+ Response.new(false, '3D-secure enrolled cards are not supported.')
end
end
end
end