Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for simplepay marketplace
- Loading branch information
Showing
5 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
module Simplepay | ||
module Services | ||
|
||
## | ||
# 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 +Simplepay::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) | ||
# | ||
# <%= simplepay_form_for(:marketplace_policy, { | ||
# :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) | ||
# | ||
# <%= simplepay_form_for(:standard, { | ||
# :amount => 34.95, | ||
# :description => "Mutual profit!", | ||
# :recipient_email => 'seller@gmail.com', | ||
# :fixed_marketplace_fee => 10.00, | ||
# :variable_marketplace_fee => 5 | ||
# }) %> | ||
# | ||
class Marketplace < Service | ||
|
||
required_field :access_key | ||
required_field :signature | ||
required_field :account_id, :as => :amazon_payments_account_id | ||
|
||
required_field :description | ||
required_field :amount, :class => Support::Amount | ||
required_field :fixed_marketplace_fee, :class => Support::Amount | ||
required_field :variable_marketplace_fee | ||
required_field :cobranding_style, :value => 'logo' | ||
required_field :recipient_email | ||
|
||
field :reference_id | ||
field :immediate_return, :class => Support::Boolean | ||
field :collect_shipping_address, :class => Support::Boolean | ||
field :process_immediately, :class => Support::Boolean, | ||
:as => :process_immediate | ||
|
||
field :return_url | ||
field :ipn_url | ||
field :abandon_url | ||
|
||
# These fields are not currently utilized by the service | ||
field :donation_widget, :as => :is_donation_widget, | ||
:value => '0' | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Simplepay | ||
module Services | ||
|
||
## | ||
# 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 +Simplepay::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. | ||
# return_url:: Fully-qualified URL for where to send they buyer following payment. | ||
# reference_id:: A custom string used to identify this transaction, it will be returned with return data. | ||
# | ||
# === Optional Fields | ||
# | ||
# recipient_pays_fee:: Set to True if Amazon fees should be deducted from recipient earnings (default behavior is marketplace owner pays) | ||
# | ||
# === Example | ||
# | ||
# (in your view, using the form helper) | ||
# | ||
# <%= simplepay_form_for(:marketplace_policy, { | ||
# :max_fixed_fee => 10.00, | ||
# :max_variable_fee => 5, | ||
# :return_url => 'http://yourservice.com', | ||
# :reference_id => '123456789' | ||
# }) %> | ||
# | ||
class MarketplacePolicy < Service | ||
|
||
# Fully-qualified URL for the production endpoint for the service. | ||
ENDPOINT_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start' | ||
|
||
# Fully-qualified URL for the sandbox (test) endpoint for the service. | ||
SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start' | ||
|
||
required_field :access_key, :as => :caller_key | ||
required_field :signature, :as => :aws_signature | ||
required_field :account_id, :as => :caller_account_id | ||
|
||
required_field :max_fixed_fee | ||
required_field :max_variable_fee | ||
required_field :return_url | ||
|
||
required_field :reference_id, :as => :caller_reference | ||
required_field :recipient_pays_fee, :value => 'False' | ||
required_field :collect_email_address, :value => 'True' | ||
required_field :pipeline_name, :value => 'Recipient' | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require File.dirname(__FILE__) + '/../../test_helper' | ||
require 'simplepay/services/marketplace' | ||
|
||
class Simplepay::Services::TestMarketplace < Test::Unit::TestCase | ||
|
||
def self.model_class; Simplepay::Services::Marketplace; end | ||
|
||
context 'Simplepay::Services::Marketplace' do | ||
|
||
should_have_service_field :access_key, | ||
:as => 'accessKey', | ||
:required => true | ||
|
||
should_have_service_field :signature, | ||
:as => 'signature', | ||
:required => true | ||
|
||
should_have_service_field :account_id, | ||
:as => 'amazonPaymentsAccountId', | ||
:required => true | ||
|
||
should_have_service_field :description, | ||
:as => 'description', | ||
:required => true | ||
|
||
should_have_service_field :amount, | ||
:as => 'amount', | ||
:required => true, | ||
:class => Simplepay::Support::Amount | ||
|
||
should_have_service_field :recipient_email, | ||
:as => 'recipientEmail', | ||
:required => true | ||
|
||
should_have_service_field :fixed_marketplace_fee, | ||
:as => 'fixedMarketplaceFee', | ||
:required => true, | ||
:class => Simplepay::Support::Amount | ||
|
||
should_have_service_field :variable_marketplace_fee, | ||
:as => 'variableMarketplaceFee', | ||
:required => true | ||
|
||
should_have_service_field :cobranding_style, | ||
:as => 'cobrandingStyle', | ||
:required => true | ||
|
||
should_have_service_field :reference_id, | ||
:as => 'referenceId', | ||
:required => false | ||
|
||
should_have_service_field :immediate_return, | ||
:as => 'immediateReturn', | ||
:required => false, | ||
:class => Simplepay::Support::Boolean | ||
|
||
should_have_service_field :collect_shipping_address, | ||
:as => 'collectShippingAddress', | ||
:required => false, | ||
:class => Simplepay::Support::Boolean | ||
|
||
should_have_service_field :process_immediately, | ||
:as => 'processImmediate', | ||
:required => false, | ||
:class => Simplepay::Support::Boolean | ||
|
||
should_have_service_field :return_url, | ||
:as => 'returnUrl', | ||
:required => false | ||
|
||
should_have_service_field :abandon_url, | ||
:as => 'abandonUrl', | ||
:required => false | ||
|
||
should_have_service_field :ipn_url, | ||
:as => 'ipnUrl', | ||
:required => false | ||
|
||
should_have_service_field :donation_widget, | ||
:as => 'isDonationWidget', | ||
:required => false | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.dirname(__FILE__) + '/../../test_helper' | ||
require 'simplepay/services/marketplace_policy' | ||
|
||
class Simplepay::Services::TestMarketplacePolicy < Test::Unit::TestCase | ||
|
||
def self.model_class; Simplepay::Services::MarketplacePolicy; end | ||
|
||
context 'Simplepay::Services::MarketplacePolicy' do | ||
|
||
should_have_service_field :access_key, | ||
:as => 'callerKey', | ||
:required => true | ||
|
||
should_have_service_field :signature, | ||
:as => 'awsSignature', | ||
:required => true | ||
|
||
should_have_service_field :account_id, | ||
:as => 'callerAccountId', | ||
:required => true | ||
|
||
should_have_service_field :max_fixed_fee, | ||
:as => 'maxFixedFee', | ||
:required => true | ||
|
||
should_have_service_field :max_variable_fee, | ||
:as => 'maxVariableFee', | ||
:required => true | ||
|
||
should_have_service_field :return_url, | ||
:as => 'returnUrl', | ||
:required => true | ||
|
||
should_have_service_field :recipient_pays_fee, | ||
:as => 'recipientPaysFee', | ||
:required => true | ||
|
||
should_have_service_field :reference_id, | ||
:as => 'callerReference', | ||
:required => true | ||
|
||
should_have_service_field :collect_email_address, | ||
:as => 'collectEmailAddress', | ||
:required => true | ||
|
||
should_have_service_field :pipeline_name, | ||
:as => 'pipelineName', | ||
:required => true | ||
|
||
end | ||
|
||
end |