Class Simplepay::Service
In: lib/simplepay/service.rb
Parent: Object
RuntimeError Error Service Standard Marketplace Donation Subscription MarketplacePolicy Interval SubscriptionPeriod BillingFrequency Comparable Field Service Epoch Currency Amount Boolean ResponseStatusCode Services Authentication FormHelper NotificationHelper RailsHelper Helpers Interval Currency Support Boolean Simplepay dot/f_2.png

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)

Methods

Constants

ENDPOINT_URL = 'https://authorize.payments.amazon.com/pba/paypipeline'   Fully-qualified URL for the production endpoint for the service.
SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/pba/paypipeline'   Fully-qualified URL for the sandbox (test) endpoint for the service.

Public Class methods

Defines a field for the service.

Usage

    class Foo < Service
      field :access_key
      field :amount,    :class => Amount, :map_to => :value
    end

[Source]

# File lib/simplepay/service.rb, line 35
      def field(name, options = {})
        field = Support::Field.new(self, name, options)
        define_method("#{name.to_s.underscore}=", Proc.new { |value| self.fields.detect { |f| f.name == name }.value = value })
        self.fields << field
        field
      end

Returns the collection of fields defined by the service class.

[Source]

# File lib/simplepay/service.rb, line 56
      def fields
        @fields ||= []
      end

Optional convenience method for:

    field :field_name, :required => true

Any other options given will be still be passed through.

[Source]

# File lib/simplepay/service.rb, line 49
      def required_field(name, options = {})
        field(name, options.merge(:required => true))
      end

[Source]

# File lib/simplepay/service.rb, line 60
      def set_submit_tag(value)
        @submit_tag = value
      end

[Source]

# File lib/simplepay/service.rb, line 64
      def submit_tag
        @submit_tag
      end

Public Instance methods

Returns the fields for the service instance.

[Source]

# File lib/simplepay/service.rb, line 74
    def fields
      @fields ||= self.class.fields.collect { |f| f.clone_for(self) }
    end

[Source]

# 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

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.

[Source]

# 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

[Validate]