Class: GoogleCheckout::Command
- Inherits:
-
Object
- Object
- GoogleCheckout::Command
- Defined in:
- lib/google-checkout/command.rb
Overview
Abstract class for commands.
https://sandbox.google.com/checkout/cws/v2/Merchant/1234567890/request
https://checkout.google.com/cws/v2/Merchant/1234567890/request
Direct Known Subclasses
Constant Summary collapse
- SANDBOX_REQUEST_URL =
"https://sandbox.google.com/checkout/cws/v2/Merchant/%s/request"
- PRODUCTION_REQUEST_URL =
"https://checkout.google.com/cws/v2/Merchant/%s/request"
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
-
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
Class Method Summary collapse
-
.x509_store ⇒ Object
Class method to return the OpenSSL::X509::Store instance for the CA certificates.
Instance Method Summary collapse
-
#initialize(merchant_id, merchant_key) ⇒ Command
constructor
A new instance of Command.
-
#post ⇒ Object
Sends the Command’s XML to GoogleCheckout via HTTPS with Basic Auth.
-
#url ⇒ Object
Returns the appropriate sandbox or production url for posting API requests.
Constructor Details
#initialize(merchant_id, merchant_key) ⇒ Command
Returns a new instance of Command.
21 22 23 24 25 26 |
# File 'lib/google-checkout/command.rb', line 21 def initialize(merchant_id, merchant_key) @merchant_id = merchant_id @merchant_key = merchant_key @currency = "USD" end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
16 17 18 |
# File 'lib/google-checkout/command.rb', line 16 def currency @currency end |
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
16 17 18 |
# File 'lib/google-checkout/command.rb', line 16 def merchant_id @merchant_id end |
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
16 17 18 |
# File 'lib/google-checkout/command.rb', line 16 def merchant_key @merchant_key end |
Class Method Details
.x509_store ⇒ Object
Class method to return the OpenSSL::X509::Store instance for the CA certificates.
NOTE May not be thread-safe.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/google-checkout/command.rb', line 76 def self.x509_store return @@x509_store if defined?(@@x509_store) cacert_path = File.(File.dirname(__FILE__) + '/../../support/cacert.pem') @@x509_store = OpenSSL::X509::Store.new @@x509_store.add_file(cacert_path) return @@x509_store end |
Instance Method Details
#post ⇒ Object
Sends the Command’s XML to GoogleCheckout via HTTPS with Basic Auth.
Returns a GoogleCheckout::RequestReceived or a GoogleCheckout::Error object.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/google-checkout/command.rb', line 40 def post # Create HTTP(S) POST command and set up Basic Authentication. uri = URI.parse(url) request = Net::HTTP::Post.new(uri.path) request.basic_auth(@merchant_id, @merchant_key) # Set up the HTTP connection object and the SSL layer. https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.cert_store = self.class.x509_store https.verify_mode = OpenSSL::SSL::VERIFY_PEER https.verify_depth = 5 # Send the request to Google. response = https.request(request, self.to_xml) # NOTE Because Notification.parse() is used, the content of objects # will be correctly parsed no matter what the HTTP response code # is from the server. case response when Net::HTTPSuccess, Net::HTTPClientError Notification.parse(response.body) when Net::HTTPRedirection, Net::HTTPServerError, Net::HTTPInformation ApiError.new("Unexpected response code (#{response.class}): #{response.code} - #{response.}") else ApiError.new("Unknown response code: #{response.code} - #{response.}") end end |
#url ⇒ Object
Returns the appropriate sandbox or production url for posting API requests.
31 32 33 |
# File 'lib/google-checkout/command.rb', line 31 def url GoogleCheckout.sandbox? ? (SANDBOX_REQUEST_URL % @merchant_id) : (PRODUCTION_REQUEST_URL % @merchant_id) end |