Class: Paypal::AdaptivePaymentsResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/paypal_api/apis/adaptive_payments.rb

Instance Attribute Summary

Attributes inherited from Response

#error_code, #parsed_response, #paypal_error_field, #raw_response

Instance Method Summary collapse

Methods inherited from Response

#[], #error_field, #error_input, #error_message, #method_missing?, #success?

Constructor Details

#initialize(stringio) ⇒ AdaptivePaymentsResponse

Returns a new instance of AdaptivePaymentsResponse.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/paypal_api/apis/adaptive_payments.rb', line 9

def initialize(stringio)
  @raw_response = stringio.class == StringIO ? stringio.read : stringio
  @parsed_response = CGI.parse(@raw_response)

  @success = @parsed_response["responseEnvelope.ack"] == ["Success"]

  unless @success
    # "responseEnvelope.timestamp"=>["2012-02-29T13:35:28.528-08:00"],
    # "responseEnvelope.ack"=>["Failure"],
    # "responseEnvelope.correlationId"=>["ca0befbd1fe0b"],
    # "responseEnvelope.build"=>["2486531"],
    # "error(0).errorId"=>["560022"],
    # "error(0).domain"=>["PLATFORM"],
    # "error(0).subdomain"=>["Application"],
    # "error(0).severity"=>["Error"],
    # "error(0).category"=>["Application"],
    # "error(0).message"=>["The X-PAYPAL-APPLICATION-ID header contains an invalid value"],
    # "error(0).parameter(0)"=>["X-PAYPAL-APPLICATION-ID"]

    @error_message = @parsed_response["error(0).message"][0]
    @error_code = @parsed_response["error(0).errorId"][0]
    @paypal_error_field = @parsed_response["error(0).parameter(0)"][0]
  end
end

Instance Method Details

#embedded_urlObject

requires www.paypalobjects.com/js/external/dg.js (lightbox)

  or https://www.paypalobjects.com/js/external/apdg.js (minibrowser)

to be added to the page



41
42
43
# File 'lib/paypal_api/apis/adaptive_payments.rb', line 41

def embedded_url
  "#{self.base_url}/webapps/adaptivepayment/flow/pay?payKey=#{self[:pay_key]}#{"&preapprovalkey=#{self[:preapproval_key]}" if command == :preapproval}" if webscr?
end

#redirect_urlObject



34
35
36
# File 'lib/paypal_api/apis/adaptive_payments.rb', line 34

def redirect_url
  "#{self.base_url}/webscr?cmd=_ap-#{command}&#{command_key}=#{command_value}" if webscr?
end