Class: aspmarketplace::Services::MarketplacePolicy

Inherits:
aspmarketplace::Service show all
Defined in:
lib/aspmarketplace/services/marketplacePolicy.rb

Overview

The Amazon Simple Pay Marketplace Policy service is used to allow sellers to acknowledge marketplace policy fees. Only once a set policy has been agreed to will marketplace transactions be able to proceed.

Simple Pay Marketplace Policy Fields

Required Fields

The following attributes are required when creating a Simple Pay Marketplace policy fee acceptance form (in addition to those listed in aspmarketplace::Service):

max_fixed_fee

The maximum fixed fee that will be appended to transactions.

max_variable_fee

The maximum variable fee (%) that will be calculated and added to transactions.

reference_id

A custom string used to identify this transaction, it will be returned with return data.

Example

(in your view, using the form helper)

<%= aspmarketplace_form_for(:marketplacePolicy, {
  :max_fixed_fee => 10.00,
  :max_variable_fee => 5,
  :reference_id => '123456789'
}) %>

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from aspmarketplace::Service

field, fields, #fields, #form, required_field, set_submit_tag, submit_tag, #url

Class Attribute Details

.return_urlObject

Loaded from YML config



34
35
36
# File 'lib/aspmarketplace/services/marketplacePolicy.rb', line 34

def return_url
  @return_url
end

Class Method Details

.generate_form(attributes) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/aspmarketplace/services/marketplacePolicy.rb', line 98

def self.generate_form(attributes)
  if (Service.environment == "prod") then
    	endPoint = @@PROD_END_POINT;
    	imageLocation = @@PROD_MP_IMAGE_LOCATION;
  else
endPoint = @@SANDBOX_END_POINT;
imageLocation = @@SANDBOX_MP_IMAGE_LOCATION;	
  end 
  uri = URI.parse(endPoint)
  params = get_params(attributes)

  signature = SignatureUtils.sign_parameters({:parameters => params, 
                                          :aws_secret_key => Service.secret_key,
                                          :host => uri.host,
                                          :verb => @@CBUIhttp_method,
                                          :uri  => @@CBUI_REQUEST_URI,
			    :algorithm => Service.signature_method })
  params[@@SIGNATURE_KEYNAME] = signature
  accept_marketplace_fee_button_form = get_accept_marketplace_fee_button_form(params,uri.host,imageLocation,@@CBUI_REQUEST_URI)
  return accept_marketplace_fee_button_form
end

.get_accept_marketplace_fee_button_form(form_hidden_inputs, service_end_point, image_location, path) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/aspmarketplace/services/marketplacePolicy.rb', line 83

def self.get_accept_marketplace_fee_button_form(form_hidden_inputs,service_end_point,image_location,path)
  form = "<form target='_top' action=\"https://" + service_end_point + path + "\" method=\"" + @@CBUIhttp_method + "\">\n"
  form += "<input type=\"image\" src=\""+image_location+"\" border=\"0\">\n"
  form_hidden_inputs.each { |k,v|
      form += "<input type=\"hidden\" name=\"" + k + "\" value=\"" + v + "\" >\n"
  }
  form += "</form>\n"
end

.get_params(attributes) ⇒ 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
69
70
71
# File 'lib/aspmarketplace/services/marketplacePolicy.rb', line 40

def self.get_params(attributes)
  form_hidden_inputs = {}
  if (Service.access_key== nil) then
      raise ArgumentError, 'AccessKey is required parameter'
  else
      form_hidden_inputs["callerKey"] = Service.access_key.to_s
  end
  if (Service.signature_method == nil) then
      raise ArgumentError, 'Signature Method is required parameter' 
  else
      form_hidden_inputs[@@SIGNATURE_METHOD_KEYNAME] = Service.signature_method.to_s 
  end 
  if (self.return_url == nil) then
      raise ArgumentError, 'Return_url is required parameter' 
  else
     form_hidden_inputs["returnUrl"] = self.return_url.to_s
  end

  form_hidden_inputs["pipelineName"] = "Recipient"
  form_hidden_inputs["recipientPaysFee"] = "True"
  form_hidden_inputs["collectEmailAddress"] = "True"
  
  form_hidden_inputs["callerReference"] = attributes[:caller_reference].to_s
 
  form_hidden_inputs["maxFixedFee"] = attributes[:fixed_marketplace_fee].to_s unless attributes[:fixed_marketplace_fee].nil?
  form_hidden_inputs["maxvariableFee"] = attributes[:variable_marketplace_fee].to_s unless attributes[:variable_marketplace_fee].nil?

  form_hidden_inputs["cobrandingStyle"] = @@COBRANDING_STYLE
  form_hidden_inputs[@@SIGNATURE_VERSION_KEYNAME] = @@SIGNATURE_VERSION

  return form_hidden_inputs
end