Class: Simplepay::Service

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
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).

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)

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'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



74
75
76
# File 'lib/simplepay/service.rb', line 74

def output_buffer
  @output_buffer
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


39
40
41
42
43
44
# File 'lib/simplepay/service.rb', line 39

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

.fieldsObject

Returns the collection of fields defined by the service class.



60
61
62
# File 'lib/simplepay/service.rb', line 60

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.



53
54
55
# File 'lib/simplepay/service.rb', line 53

def required_field(name, options = {})
  field(name, options.merge(:required => true))
end

.set_submit_tag(value) ⇒ Object



64
65
66
# File 'lib/simplepay/service.rb', line 64

def set_submit_tag(value)
  @submit_tag = value
end

.submit_tagObject



68
69
70
# File 'lib/simplepay/service.rb', line 68

def submit_tag
  @submit_tag
end

Instance Method Details

#fieldsObject

Returns the fields for the service instance.



79
80
81
# File 'lib/simplepay/service.rb', line 79

def fields
  @fields ||= self.class.fields.collect { |f| f.clone_for(self) }
end

#form(attributes = {}, submit = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/simplepay/service.rb', line 91

def form(attributes = {}, submit = nil)
  self.output_buffer = ActionView::OutputBuffer.new
  set_accessor_fields
  set_fields(attributes)
  set_signature
  content = generate_input_fields
  content += submit ? submit.to_s : generate_submit_field()
  (:form, content.html_safe, 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.



87
88
89
# File 'lib/simplepay/service.rb', line 87

def url(sandbox = Simplepay.use_sandbox?)
  sandbox ? self.class.const_get(:SANDBOX_URL) : self.class.const_get(:ENDPOINT_URL)
end