Class: EZPaypal::Response

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/core/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ EZPaypal::Response < Hash] response will be encoded, content is same as param

Constructor for Response object, take string response from paypal api server as param

Parameters:

  • response (String/Hash)

    as a query string or hash including { “TOKEN”, “PAYERID”, “TIMESTAMP”, “CORRELATIONID”, “ACK”, “VERSION”, “BUILD”, “L_ERRORCODE0”, “L_SHORTMESSAGE0”, “L_LONGMESSAGE0”, “L_SEVERITYCODE0”, … }



15
16
17
18
# File 'lib/core/response.rb', line 15

def initialize (response)
  hash_response = EZPaypal::Helper.ConvertParamToHash(response)
  self.merge!(hash_response)
end

Instance Method Details

#confirmPurchaseHash

Confirm purchase, only works if token and payer_id is obtained

Returns:

  • (Hash)

    payment details associated with the given token and payer_id



71
72
73
# File 'lib/core/response.rb', line 71

def confirmPurchase
  EZPaypal::Request.ConfirmPurchase(self["TOKEN"], self["PAYERID"])
end

#errorsHash

Get current error message

Returns:

  • (Hash)

    the error messages and error codes in hash array example return obj: => [], “severity_codes”=[],

    "short_messages" =[], "long_messages" =[]
    


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/core/response.rb', line 30

def errors
  error_codes = []
  severity_codes = []
  short_messages = []
  long_messages = []

  self.each do |key, value|
    if key.match(/^L_ERRORCODE/)
      error_codes.push(value)
    end
    if key.match(/^L_SEVERITYCODE/)
      severity_codes.push(value)
    end
    if key.match(/^L_SHORTMESSAGE/)
      short_messages.push(value)
    end
    if key.match(/^L_LONGMESSAGE/)
      long_messages.push(value)
    end
  end

  error_messages = {"error_codes" => error_codes, "severity_codes" => severity_codes,
                    "short_messages" => short_messages, "long_messages" => long_messages}

  return error_messages
end

#getCheckoutDetailsHash

Get current checkout details, only works if token is obtained

Returns:

  • (Hash)

    checkout details associated with the given token



65
66
67
# File 'lib/core/response.rb', line 65

def getCheckoutDetails
  EZPaypal::Request.GetCheckoutDetails(self["TOKEN"])
end

#getCheckoutURLString

Get current checkout url to redirect user to, only works if token is obtained

Returns:

  • (String)

    paypal checkout url to redirect user to



59
60
61
# File 'lib/core/response.rb', line 59

def getCheckoutURL
  EZPaypal::Request.GetCheckoutURL(self["TOKEN"]) if success?
end

#success?Bool

Check current response is success or not

Returns:

  • (Bool)

    true/false



22
23
24
# File 'lib/core/response.rb', line 22

def success?
  return self["ACK"].downcase == "success"
end