Class: Simplepay::Service
- Inherits:
-
Object
- Object
- Simplepay::Service
- Defined in:
- lib/simplepay/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 Simplepay.aws_access_key_id).
- account_id
-
Your Amazon Payments account identifier (automatically filled from Simplepay.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
Simplepay::Services::Donation, Simplepay::Services::Marketplace, Simplepay::Services::MarketplacePolicy, Simplepay::Services::Standard, Simplepay::Services::Subscription
Constant Summary collapse
- ENDPOINT_URL =
Fully-qualified URL for the production endpoint for the service.
'https://authorize.payments.amazon.com/pba/paypipeline'
- SANDBOX_URL =
Fully-qualified URL for the sandbox (test) endpoint for the service.
'https://authorize.payments-sandbox.amazon.com/pba/paypipeline'
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 = Simplepay.use_sandbox?) ⇒ Object
Returns the URL for the service endpoint to use.
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
35 36 37 38 39 40 |
# File 'lib/simplepay/service.rb', line 35 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.
56 57 58 |
# File 'lib/simplepay/service.rb', line 56 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.
49 50 51 |
# File 'lib/simplepay/service.rb', line 49 def required_field(name, = {}) field(name, .merge(:required => true)) end |
.set_submit_tag(value) ⇒ Object
60 61 62 |
# File 'lib/simplepay/service.rb', line 60 def set_submit_tag(value) @submit_tag = value end |
.submit_tag ⇒ Object
64 65 66 |
# File 'lib/simplepay/service.rb', line 64 def submit_tag @submit_tag end |
Instance Method Details
#fields ⇒ Object
Returns the fields for the service instance.
74 75 76 |
# File 'lib/simplepay/service.rb', line 74 def fields @fields ||= self.class.fields.collect { |f| f.clone_for(self) } end |
#form(attributes = {}, submit = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/simplepay/service.rb', line 86 def form(attributes = {}, submit = nil) set_accessor_fields set_fields(attributes) set_signature content = generate_input_fields + generate_submit_field(submit) Simplepay::Helpers::FormHelper.content_tag(:form, content, {:method => 'post', :action => url}) end |
#url(sandbox = Simplepay.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.
82 83 84 |
# File 'lib/simplepay/service.rb', line 82 def url(sandbox = Simplepay.use_sandbox?) sandbox ? self.class.const_get(:SANDBOX_URL) : self.class.const_get(:ENDPOINT_URL) end |