Class: ActiveMerchant::Billing::Integrations::PayuIn::WebService

Inherits:
Hash
  • Object
show all
Includes:
PostsData
Defined in:
lib/active_merchant/payu_in/web_service.rb

Overview

PayU.in provides web services to help you with reconciliation of your transactions in real time.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_payment(payu_id) ⇒ Object

Makes check payment API call to PayU.in web service Params - PayU.in transaction id



63
64
65
66
# File 'lib/active_merchant/payu_in/web_service.rb', line 63

def self.check_payment( payu_id )
  checksum = PayuIn.checksum( 'check_payment', payu_id )
  new.web_service_call( :command => 'check_payment', :var1 => payu_id, :hash => checksum, :key => PayuIn.merchant_id )
end

.verify_payment(*invoice_ids) ⇒ Object

Makes verify payment API call to PayU.in web service Params - any number of invoice ids ( provided by the merchant )



55
56
57
58
59
# File 'lib/active_merchant/payu_in/web_service.rb', line 55

def self.verify_payment( *invoice_ids )
  invoice_string = invoice_ids.join( '|' )
  checksum = PayuIn.checksum( 'verify_payment', invoice_string )
  new.web_service_call( :command => 'verify_payment', :var1 => invoice_string, :hash => checksum, :key => PayuIn.merchant_id )
end

Instance Method Details

#amount_ok?(order_amount, order_discount = BigDecimal.new( '0.0' ), invoice_id = nil) ⇒ Boolean

Returns whether the order amount and order discount matches generally in third party shopping carts order discount is handle by the application and should generally by 0.0

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/active_merchant/payu_in/web_service.rb', line 36

def amount_ok?( order_amount, order_discount = BigDecimal.new( '0.0' ), invoice_id = nil )
  hash = ( invoice_id ? self[ invoice_id.to_s ] : self )
  ( BigDecimal.new( hash[ 'amt' ] ) == order_amount ) && ( BigDecimal.new( hash[ 'disc' ] ) == order_discount )
end

#complete?(invoice_id = nil) ⇒ Boolean

Whether the invoice is success or not Invoice id is required when multiple invoices are queried at once

Returns:

  • (Boolean)


17
18
19
# File 'lib/active_merchant/payu_in/web_service.rb', line 17

def complete?( invoice_id = nil )
  status( invoice_id ).to_s.downcase == 'success'
end

#nett_amount(invoice_id = nil) ⇒ Object

Returns whether the nett amount after reducing the discounts



42
43
44
45
# File 'lib/active_merchant/payu_in/web_service.rb', line 42

def nett_amount( invoice_id = nil )
  hash = ( invoice_id ? self[ invoice_id.to_s ] : self )
  BigDecimal.new( hash[ 'amt' ] ) - BigDecimal.new( hash[ 'disc' ] )
end

#pending?(invoice_id = nil) ⇒ Boolean

Whether the invoice is pending confirmation Invoice id is required when multiple invoices are queried at once

Returns:

  • (Boolean)


23
24
25
# File 'lib/active_merchant/payu_in/web_service.rb', line 23

def pending?( invoice_id = nil )
  status( invoice_id ).to_s.downcase == 'pending'
end

#status(invoice_id = nil) ⇒ Object

Returns the payment status of the invoice invoice_id is required if multiple invoices are queried at once



29
30
31
# File 'lib/active_merchant/payu_in/web_service.rb', line 29

def status( invoice_id = nil )
  ( invoice_id ? self[ invoice_id.to_s ] : self )[ 'status']
end

#transaction_id(invoice_id = nil) ⇒ Object

Returns the PayU.in transaction if for the invocie invoice_id is required if multiple invoices are queried at once



49
50
51
# File 'lib/active_merchant/payu_in/web_service.rb', line 49

def transaction_id( invoice_id = nil )
  ( invoice_id ? self[ invoice_id.to_s ] : self )[ 'mihpayid']
end

#web_service_call(params = {}) ⇒ Object

Utility method which makes the web service call and parse the response into WebService object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_merchant/payu_in/web_service.rb', line 70

def web_service_call( params = {} )
  payload_hash = ActiveMerchant::PostData.new
  payload_hash.merge!( params )
  payload = payload_hash.to_post_data
  response = PHP.unserialize(
    ssl_post(
      PayuIn.web_service_url, payload,
      'Content-Length' => "#{payload.size}",
      'User-Agent'     => "Active Merchant -- http://activemerchant.org",
      'service_provider' => "payu_paisa"
    )
  )
  merge!( response["transaction_details"] && response["transaction_details"].size == 1 ? response["transaction_details"].values.first : ( response["transaction_details"] || { :status => response['msg'] } ) )
end