Class: AmazonMarketplace::Service
- Inherits:
-
Object
- Object
- AmazonMarketplace::Service
- Defined in:
- lib/AmazonMarketplace/service.rb
Overview
This is a base class from which to inherit functionality for all Amazon Simple Pay services (Subscriptions, Marketplace Buttons, etc.)
Required Fields
The following fields are required for all Simple Pay services:
- access_key
-
Your Amazon Web Service (AWS) access key (automatically filled from AmazonMarketplace.aws_access_key_id).
- account_id
-
Your Amazon Payments account identifier (automatically filled from AmazonMarketplace.account_id)
- signature
-
The validation string, guaranteeing that you are the one generating the request and that the values were not tampered with enroute (automatically generated by the form generators)
Direct Known Subclasses
AmazonMarketplace::Services::Marketplace, AmazonMarketplace::Services::MarketplacePolicy
Constant Summary collapse
- @@app_name =
"ASP"
- @@ASPhttp_method =
"POST"
- @@CBUIhttp_method =
"POST"
- @@CBUI_REQUEST_URI =
"/cobranded-ui/actions/start"
- @@SANDBOX_END_POINT =
"https://authorize.payments-sandbox.amazon.com/pba/paypipeline"
- @@SANDBOX_IMAGE_LOCATION =
"https://authorize.payments-sandbox.amazon.com/pba/images/payNowButton.png"
- @@SANDBOX_MP_IMAGE_LOCATION =
"https://authorize.payments-sandbox.amazon.com/pba/images/MarketPlaceFeeWithLogo.png"
- @@PROD_END_POINT =
"https://authorize.payments.amazon.com/pba/paypipeline"
- @@PROD_IMAGE_LOCATION =
"https://authorize.payments.amazon.com/pba/images/payNowButton.png"
- @@PROD_MP_IMAGE_LOCATION =
"https://authorize.payments.amazon.com/pba/images/MarketPlaceFeeWithLogo.png"
- @@SIGNATURE_KEYNAME =
"signature"
- @@SIGNATURE_METHOD_KEYNAME =
"signatureMethod"
- @@SIGNATURE_VERSION_KEYNAME =
"signatureVersion"
- @@SIGNATURE_VERSION =
"2"
- @@COBRANDING_STYLE =
"logo"
- @@HMAC_SHA256_ALGORITHM =
"HmacSHA256"
- @@HMAC_SHA1_ALGORITHM =
"HmacSHA1"
Class Attribute Summary collapse
-
.access_key ⇒ Object
Returns the value of attribute access_key.
-
.environment ⇒ Object
Returns the value of attribute environment.
-
.secret_key ⇒ Object
Returns the value of attribute secret_key.
-
.signature_method ⇒ Object
Returns the value of attribute signature_method.
Class Method Summary collapse
-
.field(name, options = {}) ⇒ Object
Defines a field for the service.
-
.fields ⇒ Object
Returns the collection of fields defined by the service class.
-
.required_field(name, options = {}) ⇒ Object
Optional convenience method for:.
- .set_submit_tag(value) ⇒ Object
- .submit_tag ⇒ Object
Instance Method Summary collapse
-
#fields ⇒ Object
Returns the fields for the service instance.
- #form(attributes = {}, submit = nil) ⇒ Object
-
#url(sandbox = AmazonMarketplace.use_sandbox?) ⇒ Object
Returns the URL for the service endpoint to use.
Class Attribute Details
.access_key ⇒ Object
Returns the value of attribute access_key.
21 22 23 |
# File 'lib/AmazonMarketplace/service.rb', line 21 def access_key @access_key end |
.environment ⇒ Object
Returns the value of attribute environment.
20 21 22 |
# File 'lib/AmazonMarketplace/service.rb', line 20 def environment @environment end |
.secret_key ⇒ Object
Returns the value of attribute secret_key.
22 23 24 |
# File 'lib/AmazonMarketplace/service.rb', line 22 def secret_key @secret_key end |
.signature_method ⇒ Object
Returns the value of attribute signature_method.
23 24 25 |
# File 'lib/AmazonMarketplace/service.rb', line 23 def signature_method @signature_method end |
Class Method Details
.field(name, options = {}) ⇒ Object
Defines a field for the service.
Usage
class Foo < Service
field :access_key
field :amount, :class => Amount, :map_to => :value
end
61 62 63 64 65 66 |
# File 'lib/AmazonMarketplace/service.rb', line 61 def field(name, = {}) field = Support::Field.new(self, name, ) define_method("#{name.to_s.underscore}=", Proc.new { |value| self.fields.detect { |f| f.name == name }.value = value }) self.fields << field field end |
.fields ⇒ Object
Returns the collection of fields defined by the service class.
82 83 84 |
# File 'lib/AmazonMarketplace/service.rb', line 82 def fields @fields ||= [] end |
.required_field(name, options = {}) ⇒ Object
Optional convenience method for:
field :field_name, :required => true
Any other options
given will be still be passed through.
75 76 77 |
# File 'lib/AmazonMarketplace/service.rb', line 75 def required_field(name, = {}) field(name, .merge(:required => true)) end |
.set_submit_tag(value) ⇒ Object
86 87 88 |
# File 'lib/AmazonMarketplace/service.rb', line 86 def set_submit_tag(value) @submit_tag = value end |
.submit_tag ⇒ Object
90 91 92 |
# File 'lib/AmazonMarketplace/service.rb', line 90 def submit_tag @submit_tag end |
Instance Method Details
#fields ⇒ Object
Returns the fields for the service instance.
100 101 102 |
# File 'lib/AmazonMarketplace/service.rb', line 100 def fields @fields ||= self.class.fields.collect { |f| f.clone_for(self) } end |
#form(attributes = {}, submit = nil) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/AmazonMarketplace/service.rb', line 112 def form(attributes = {}, submit = nil) set_accessor_fields set_fields(attributes) set_signature content = generate_input_fields + generate_submit_field(submit) AmazonMarketplace::Helpers::FormHelper.content_tag(:form, content, {:method => 'post', :action => url}) end |
#url(sandbox = AmazonMarketplace.use_sandbox?) ⇒ Object
Returns the URL for the service endpoint to use. If sandbox
is true, the SANDBOX_URL will be used. Otherwise, the ENDPOINT_URL will be used.
108 109 110 |
# File 'lib/AmazonMarketplace/service.rb', line 108 def url(sandbox = AmazonMarketplace.use_sandbox?) sandbox ? self.class.const_get(:SANDBOX_URL) : self.class.const_get(:ENDPOINT_URL) end |