Class: AmazonMarketplace::Services::Marketplace

Inherits:
AmazonMarketplace::Service show all
Defined in:
lib/AmazonMarketplace/services/marketplace.rb

Overview

The Amazon Simple Pay Marketplace service is used to facilitate payments for others. Use it to charge a commission fee for brokering the exchange between buyers and sellers.

Note that sellers must accept your marketplace fee policy before the payment buttons for their products can be generated. This can be accomplished using the MarketplacePolicy service with the form helper (see examples).

Simple Pay Marketplace Fields

Required Fields

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

amount

The dollar value you’d like to collect.

description

A summary of the reason for the payment, this is displayed to your customer during checkout.

recipient_email

The e-mail address of the seller (important and must be correct).

fixed_marketplace_fee

The fixed marketplace fee to add to each transaction.

variable_marketplace_fee

The variable percentage fee to add to each transaction.

Optional Fields

abandon_url

The fully-qualified URL to send your custom if they cancel during payment.

cobranding_style

Defines the type of cobranding to use during the checkout process.

collect_shipping_address

Tells Amazon whether or not to ask for shipping address and contact information.

immediate_return

Immediately returns the customer to your return_url directly after payment.

ipn_url

Fully-qualified URL to which Amazon will POST instant payment notifications.

process_immediately

Instructs Amazon to immediately process the payment.

reference_id

A custom string your can set to identify this transaction, it will be returned with the IPNs and other returned data.

return_url

Fully-qualified URL for where to send your customer following payment.

Example

(in your view, sellers need to accept the marketplace fee policy using the form helper)

<%= AmazonMarketplace_form_for(:marketplacePolicy, {
  :max_fixed_fee    => 10.00,
  :max_variable_fee => 5,
  :return_url       => 'http://yourservice.com'
}) %>

(in your view, payment form generated for end users using the form helper)

<%= AmazonMarketplace_form_for(:standard, {
  :amount                   => 34.95,
  :description              => "Mutual profit!",
  :recipient_email          => '[email protected]',
  :fixed_marketplace_fee    => 10.00,
  :variable_marketplace_fee => 5
}) %>

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from AmazonMarketplace::Service

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

Class Attribute Details

.abandon_urlObject

Returns the value of attribute abandon_url.



66
67
68
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 66

def abandon_url
  @abandon_url
end

.amountObject

Loaded from YML config



63
64
65
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 63

def amount
  @amount
end

.collect_shipping_addressObject

Returns the value of attribute collect_shipping_address.



71
72
73
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 71

def collect_shipping_address
  @collect_shipping_address
end

.descriptionObject

Returns the value of attribute description.



64
65
66
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 64

def description
  @description
end

.environmentObject

Returns the value of attribute environment.



75
76
77
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 75

def environment
  @environment
end

.fixed_marketplace_feeObject

Returns the value of attribute fixed_marketplace_fee.



73
74
75
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 73

def fixed_marketplace_fee
  @fixed_marketplace_fee
end

.immediate_returnObject

Returns the value of attribute immediate_return.



68
69
70
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 68

def immediate_return
  @immediate_return
end

.ipn_urlObject

Returns the value of attribute ipn_url.



70
71
72
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 70

def ipn_url
  @ipn_url
end

.process_immediateObject

Returns the value of attribute process_immediate.



69
70
71
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 69

def process_immediate
  @process_immediate
end

.recipient_emailObject

Returns the value of attribute recipient_email.



72
73
74
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 72

def recipient_email
  @recipient_email
end

.reference_idObject

Returns the value of attribute reference_id.



65
66
67
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 65

def reference_id
  @reference_id
end

.return_urlObject

Returns the value of attribute return_url.



67
68
69
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 67

def return_url
  @return_url
end

.variable_marketplace_feeObject

Returns the value of attribute variable_marketplace_fee.



74
75
76
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 74

def variable_marketplace_fee
  @variable_marketplace_fee
end

Class Method Details

.generate_form(attributes) ⇒ Object

Parameters:

  • accessKey
    • Put your Access Key here

  • secretKey
    • Put your Secret Key here

  • amount
    • Enter the amount you want to collect for the item

  • description
    • description - Enter a description of the item

  • referenceId
    • Optionally enter an ID that uniquely identifies this transaction for your records

  • abandonUrl
    • Optionally, enter the URL where senders should be redirected if they cancel their transaction

  • returnUrl
    • Optionally enter the URL where buyers should be redirected after they complete the transaction

  • immediateReturn
    • Optionally, enter “1” if you want to skip the final status page in Amazon Payments,

  • processImmediate
    • Optionally, enter “1” if you want to settle the transaction immediately else “0”. Default value is “1”

  • ipnUrl
    • Optionally, type the URL of your host page to which Amazon Payments should send the IPN transaction information.

  • collectShippingAddress
    • Optionally, enter “1” if you want Amazon Payments to return the buyer’s shipping address as part of the transaction information.

  • signatureMethod
    • Valid values are HmacSHA256 and HmacSHA1

  • recipientEmail
    • Enter the e-mail address for the seller.

  • fixedMarketplaceFee
    • Optionally, enter the fixed market place fee

  • variableMarketplaceFee
    • Optionally, enter the variable market place fee

  • environment
    • Valid values are “sandbox” or “prod”



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 191

def self.generate_form(attributes)
  if (Service.environment == "prod") then
   endPoint = @@PROD_END_POINT;
   imageLocation = @@PROD_IMAGE_LOCATION;
  else
   endPoint = @@SANDBOX_END_POINT;
   imageLocation = @@SANDBOX_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 => "POST",
                                             :uri  => uri.path,
        					    :algorithm => Service.signature_method  })
  params[@@SIGNATURE_KEYNAME] = signature
  marketplace_pay_button_form = get_marketplace_pay_button_form(params,endPoint,imageLocation)
  return marketplace_pay_button_form
end

.generate_url(attributes) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 215

def self.generate_url(attributes)
  if (Service.environment == "prod") then
   endPoint = @@PROD_END_POINT;
   imageLocation = @@PROD_IMAGE_LOCATION;
  else
   endPoint = @@SANDBOX_END_POINT;
   imageLocation = @@SANDBOX_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 => "POST",
                                             :uri  => uri.path,
        					    :algorithm => Service.signature_method  })
  params[@@SIGNATURE_KEYNAME] = signature
  return get_marketplace_pay_button_url(params,endPoint,imageLocation)
  
end

.get_marketplace_pay_button_form(form_hidden_inputs, service_end_point, image_location) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 150

def self.get_marketplace_pay_button_form(form_hidden_inputs,service_end_point,image_location)
  form = "<form target='_top' action=\"" + service_end_point + "\" method=\"" + "POST" + "\">\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_marketplace_pay_button_url(form_hidden_inputs, service_end_point, image_location) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 159

def self.get_marketplace_pay_button_url(form_hidden_inputs,service_end_point,image_location)
 

 url = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start?'
 form_hidden_inputs.each { |k,v|
     url += k + "=" + v + '&'
 }
 return url

  # Uncomment this if you want output in a file
  # File.open('out.htm', 'w') { |f| f.write x.body }
  
end

.get_params(attributes) ⇒ Object

Returns - A map of key of key-value pair for all non null parameters.

Returns:

    • A map of key of key-value pair for all non null parameters



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/AmazonMarketplace/services/marketplace.rb', line 96

def self.get_params(attributes)
  form_hidden_inputs = {}
   if (Service.access_key== nil) then
      raise ArgumentError, 'AccessKey is required parameter'
  else
  form_hidden_inputs["accessKey"] = Service.access_key
  end
  if (attributes[:amount] == nil) then
      raise ArgumentError, 'Amount is required parameter'
  else                         
  form_hidden_inputs["amount"] = attributes[:amount].to_s
  end 
  if (attributes[:description] == nil) then        
  raise ArgumentError, 'Description is required parameter'
  else
       form_hidden_inputs["description"] = attributes[:description].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 ( attributes[:recipient_email] == nil) then
      raise ArgumentError, 'Recipient Email is required parameter'
  else
  	form_hidden_inputs["recipientEmail"] = attributes[:recipient_email].to_s
  end
  form_hidden_inputs["referenceId"] = attributes[:reference_id].to_s unless attributes[:reference_id].nil?
  form_hidden_inputs["immediateReturn"] = self.immediate_return.to_s unless self.immediate_return.nil?
  form_hidden_inputs["returnUrl"] = self.return_url.to_s unless self.return_url.nil?
  form_hidden_inputs["abandonUrl"] = self.abandon_url.to_s unless self.abandon_url.nil?
  form_hidden_inputs["processImmediate"] = self.process_immediate.to_s unless self.process_immediate.nil?
  form_hidden_inputs["ipnUrl"] = self.ipn_url.to_s unless self.ipn_url.nil?
  form_hidden_inputs["collectShippingAddress"] = self.collect_shipping_address.to_s unless self.collect_shipping_address.nil?

  form_hidden_inputs["fixedMarketplaceFee"] = attributes[:fixed_marketplace_ee].to_s unless attributes[:fixed_marketplace_fee].nil?
  form_hidden_inputs["variableMarketplaceFee"] = 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