Permalink
Browse files

Update standard service for FPS API V.2008-09-17

  • Loading branch information...
1 parent 7efa404 commit d1faf3ef3c59cc46d45908e2d2bb05171d9977f7 @elskwid elskwid committed Aug 17, 2009
View
@@ -24,6 +24,7 @@ lib/simplepay/support/currency.rb
lib/simplepay/support/epoch.rb
lib/simplepay/support/field.rb
lib/simplepay/support/interval.rb
+lib/simplepay/support/simple_amount.rb
lib/simplepay/support/subscription_period.rb
script/console
script/destroy
@@ -41,6 +42,7 @@ test/simplepay/support/test_boolean.rb
test/simplepay/support/test_epoch.rb
test/simplepay/support/test_field.rb
test/simplepay/support/test_interval.rb
+test/simplepay/support/test_simple_amount.rb
test/simplepay/support/test_subscription_period.rb
test/simplepay/test_authentication.rb
test/simplepay/test_service.rb
View
@@ -16,9 +16,30 @@ module Interval
end
Intervals = [Interval::Day, Interval::Week, Interval::Month, Interval::Year]
-
+
+ ##
+ # Amazon Status Codes (FPS Basic)
+ # SA Success status for the ABT payment method.
+ # SB Success status for the ACH (bank account) payment method.
+ # SC Success status for the credit card payment method.
+ # SE System error.
+ # A Buyer abandoned the pipeline.
+ # CE Specifies a caller exception.
+ # PE Payment Method Mismatch Error: Specifies that the buyer does not have the payment method you requested.
+ # NP This account type does not support the specified payment method.
+ # NM You are not registered as a third-party caller to make this transaction. Contact Amazon Payments for more information.
+ #
module ResponseStatusCode
+ SuccessfulABT = 'SA'
+ SuccessfulACH = 'SB'
+ SuccessfulCC = 'SC'
Abandoned = 'A'
+ CallerException = 'CE'
+ PaymentMismatch = 'PE'
+ NotSupported = 'NP'
+ NotRegistered = 'NM'
+
+ # These haven't been verified so I'll leave them in for the time being
HtmlError = 'ME'
PaymentFailed = 'PF'
PaymentInitiated = 'PI'
@@ -28,8 +49,8 @@ module ResponseStatusCode
SubscriptionFailed = 'SF'
SubscriptionSuccessful = 'SS'
- Successful = [PaymentSuccessful, SubscriptionSuccessful]
- Failure = [Abandoned, HtmlError, PaymentFailed, SystemError, SubscriptionFailed]
+ Successful = [SuccessfulABT, SuccessfulACH, SuccessfulCC, PaymentSuccessful, SubscriptionSuccessful]
+ Failure = [Abandoned, CallerException, PaymentMismatch, NotSupported, NotRegistered, HtmlError, PaymentFailed, SystemError, SubscriptionFailed]
Pending = [PaymentInitiated, PaymentReserved]
All = [Successful, Failure, Pending].flatten
end
@@ -35,30 +35,41 @@ module Services
# }) %>
#
class Standard < 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 :cobranding_style, :value => 'logo'
-
- 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
+ # common service fields
+ required_field :signature, :as => :aws_signature
+ required_field :access_key, :as => :caller_key
+ required_field :pipeline_name, :value => 'SingleUse' # Valid Values: SingleUse | MultiUse | Recurring | Recipient | SetupPrepaid | SetupPostpaid | EditToken
+ required_field :return_url
+ required_field :version, :value => '2009-01-09'
+
+ field :cobranding_style, :value => 'logo'
+ field :cobranding_url
+ field :website_description
+
+ # standard service fields
+ required_field :reference_id, :as => 'callerReference'
+ required_field :transaction_amount, :class => Support::SimpleAmount
- # These fields are not currently utilized by the service
- field :variable_marketplace_fee, :value => ''
- field :donation_widget, :as => :is_donation_widget,
- :value => '0'
- field :fixed_marketplace_fee, :value => ''
+ field :address_name
+ field :address_line1
+ field :address_line2
+ field :city
+ field :state
+ field :zip
+ field :phone_number
+ field :collect_shipping_address, :class => Support::Boolean
+ field :currency_code, :value => "USD"
+ field :discount
+ field :gift_wrapping
+ field :handling, :class => Support::SimpleAmount
+ field :item_total, :class => Support::SimpleAmount
+ field :payment_method
+ field :payment_reason
+ field :reserve
+ field :shipping, :class => Support::SimpleAmount
+ field :tax, :class => Support::SimpleAmount
+ field :ipn_url
end
View
@@ -5,6 +5,7 @@
require 'simplepay/support/epoch'
require 'simplepay/support/field'
require 'simplepay/support/interval'
+require 'simplepay/support/simple_amount'
require 'simplepay/support/subscription_period'
module Simplepay
@@ -0,0 +1,37 @@
+require 'bigdecimal'
+
+module Simplepay
+ module Support
+
+ ##
+ # In new Amazon API requests the amount does not include the currency, SimpleAmount is used for this, for now.
+ #
+ # At the present time, Amazon only uses USD.
+ #
+ class SimpleAmount
+
+ attr_reader :amount
+
+ def initialize(amount)
+ self.amount = amount
+ end
+
+
+ ##
+ # Sets the amount of the currency value, such as "1" for 1 USD. This
+ # amount cannot be negative.
+ #
+ def amount=(amount)
+ raise(ArgumentError, "Amount cannot be nil") unless amount
+ raise(ArgumentError, "Amount cannot be negative") if amount < 0
+ @amount = BigDecimal.new(amount.to_s)
+ end
+
+ def to_s
+ "#{'%0.2f' % amount}"
+ end
+
+ end
+
+ end
+end
View
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.description = %q{This gem provides a Rails interface to the Amazon Simple Pay payment service.}
s.email = ["gem@nathanielbibler.com"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/simplepay.rb", "lib/simplepay/authentication.rb", "lib/simplepay/constants.rb", "lib/simplepay/errors.rb", "lib/simplepay/helpers/form_helper.rb", "lib/simplepay/helpers/notification_helper.rb", "lib/simplepay/helpers/rails_helper.rb", "lib/simplepay/rails.rb", "lib/simplepay/service.rb", "lib/simplepay/services/donation.rb", "lib/simplepay/services/marketplace.rb", "lib/simplepay/services/marketplace_policy.rb", "lib/simplepay/services/standard.rb", "lib/simplepay/services/subscription.rb", "lib/simplepay/support.rb", "lib/simplepay/support/amount.rb", "lib/simplepay/support/billing_frequency.rb", "lib/simplepay/support/boolean.rb", "lib/simplepay/support/currency.rb", "lib/simplepay/support/epoch.rb", "lib/simplepay/support/field.rb", "lib/simplepay/support/interval.rb", "lib/simplepay/support/subscription_period.rb", "script/console", "script/destroy", "script/generate", "simplepay.gemspec", "test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_donation.rb", "test/simplepay/services/test_marketplace.rb", "test/simplepay/services/test_marketplace_policy.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "lib/simplepay.rb", "lib/simplepay/authentication.rb", "lib/simplepay/constants.rb", "lib/simplepay/errors.rb", "lib/simplepay/helpers/form_helper.rb", "lib/simplepay/helpers/notification_helper.rb", "lib/simplepay/helpers/rails_helper.rb", "lib/simplepay/rails.rb", "lib/simplepay/service.rb", "lib/simplepay/services/donation.rb", "lib/simplepay/services/marketplace.rb", "lib/simplepay/services/marketplace_policy.rb", "lib/simplepay/services/standard.rb", "lib/simplepay/services/subscription.rb", "lib/simplepay/support.rb", "lib/simplepay/support/amount.rb", "lib/simplepay/support/billing_frequency.rb", "lib/simplepay/support/boolean.rb", "lib/simplepay/support/currency.rb", "lib/simplepay/support/epoch.rb", "lib/simplepay/support/field.rb", "lib/simplepay/support/interval.rb", "lib/simplepay/support/simple_amount.rb", "lib/simplepay/support/subscription_period.rb", "script/console", "script/destroy", "script/generate", "simplepay.gemspec", "test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_donation.rb", "test/simplepay/services/test_marketplace.rb", "test/simplepay/services/test_marketplace_policy.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
s.has_rdoc = true
s.homepage = %q{http://simplepay.rubyforge.org}
s.rdoc_options = ["--main", "README.rdoc"]
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.2}
s.signing_key = %q{/Users/nathan/.gem/gem-private_key.pem}
s.summary = %q{This gem provides a Rails interface to the Amazon Simple Pay payment service.}
- s.test_files = ["test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_donation.rb", "test/simplepay/services/test_marketplace.rb", "test/simplepay/services/test_marketplace_policy.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
+ s.test_files = ["test/simplepay/helpers/test_notifier.rb", "test/simplepay/services/test_donation.rb", "test/simplepay/services/test_marketplace.rb", "test/simplepay/services/test_marketplace_policy.rb", "test/simplepay/services/test_standard.rb", "test/simplepay/services/test_subscription.rb", "test/simplepay/support/test_amount.rb", "test/simplepay/support/test_billing_frequency.rb", "test/simplepay/support/test_boolean.rb", "test/simplepay/support/test_epoch.rb", "test/simplepay/support/test_field.rb", "test/simplepay/support/test_interval.rb", "test/simplepay/support/test_simple_amount.rb", "test/simplepay/support/test_subscription_period.rb", "test/simplepay/test_authentication.rb", "test/simplepay/test_service.rb", "test/test_helper.rb", "test/test_simplepay.rb"]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -6,73 +6,129 @@ class Simplepay::Services::TestStandard < Test::Unit::TestCase
def self.model_class; Simplepay::Services::Standard; end
context 'Simplepay::Services::Standard' do
+
+ # these 'old' fields shouldn't be there anymore
+ should_not_have_service_field :account_id
+
+ # fields the service should have
+
+ # common fields to all services
+ should_have_service_field :signature,
+ :as => 'awsSignature',
+ :required => true
should_have_service_field :access_key,
- :as => 'accessKey',
+ :as => 'callerKey',
:required => true
- should_have_service_field :signature,
- :as => 'signature',
+ should_have_service_field :cobranding_style,
+ :as => 'cobrandingStyle',
+ :required => false
+
+ should_have_service_field :cobranding_url,
+ :as => 'cobrandingUrl',
+ :required => false
+
+ should_have_service_field :pipeline_name,
+ :as => 'pipelineName',
:required => true
- should_have_service_field :account_id,
- :as => 'amazonPaymentsAccountId',
+ should_have_service_field :return_url,
+ :as => 'returnUrl',
:required => true
-
- should_have_service_field :description,
- :as => 'description',
+
+ should_have_service_field :version,
:required => true
+
+ should_have_service_field :website_description,
+ :as => 'websiteDescription',
+ :required => false
- should_have_service_field :amount,
- :as => 'amount',
- :required => true,
- :class => Simplepay::Support::Amount
+ # standard service fields
+ should_have_service_field :address_name,
+ :as => 'addressName',
+ :required => false
+
+ should_have_service_field :address_line1,
+ :as => 'addressLine1',
+ :required => false
+
+ should_have_service_field :address_line2,
+ :as => 'addressLine2',
+ :required => false
- should_have_service_field :cobranding_style,
- :as => 'cobrandingStyle',
- :required => true
+ should_have_service_field :city,
+ :as => 'city',
+ :required => false
- should_have_service_field :reference_id,
- :as => 'referenceId',
+ should_have_service_field :state,
+ :as => 'state',
:required => false
- should_have_service_field :immediate_return,
- :as => 'immediateReturn',
- :required => false,
- :class => Simplepay::Support::Boolean
+ should_have_service_field :zip,
+ :as => 'zip',
+ :required => false
+
+ should_have_service_field :phone_number,
+ :as => 'phoneNumber',
+ :required => false
+
+ should_have_service_field :reference_id,
+ :as => 'callerReference',
+ :required => true
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 :currency_code,
+ :as => 'currencyCode',
+ :required => false
- should_have_service_field :return_url,
- :as => 'returnUrl',
+ should_have_service_field :discount,
:required => false
- should_have_service_field :abandon_url,
- :as => 'abandonUrl',
+ should_have_service_field :gift_wrapping,
+ :as => 'giftWrapping',
:required => false
- should_have_service_field :ipn_url,
- :as => 'ipnUrl',
+ should_have_service_field :handling,
+ :required => false,
+ :class => Simplepay::Support::SimpleAmount
+
+ should_have_service_field :item_total,
+ :as => 'itemTotal',
+ :required => false,
+ :class => Simplepay::Support::SimpleAmount
+
+ # Default ABT (CC | ACH | ABT)
+ should_have_service_field :payment_method,
+ :as => 'paymentMethod',
:required => false
- should_have_service_field :variable_marketplace_fee,
- :as => 'variableMarketplaceFee',
+ should_have_service_field :payment_reason,
+ :as => 'paymentReason',
:required => false
- should_have_service_field :fixed_marketplace_fee,
- :as => 'fixedMarketplaceFee',
+ should_have_service_field :reserve,
:required => false
- should_have_service_field :donation_widget,
- :as => 'isDonationWidget',
+ should_have_service_field :shipping,
+ :required => false,
+ :class => Simplepay::Support::SimpleAmount
+
+ should_have_service_field :tax,
+ :required => false,
+ :class => Simplepay::Support::SimpleAmount
+
+ should_have_service_field :transaction_amount,
+ :as => 'transactionAmount',
+ :required => true,
+ :class => Simplepay::Support::SimpleAmount
+
+ should_have_service_field :ipn_url,
+ :as => 'ipnUrl',
:required => false
end
@@ -0,0 +1,28 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+require 'simplepay/support/simple_amount'
+
+class Simplepay::Support::TestSimpleAmount < Test::Unit::TestCase
+
+ context 'Simplepay::Support::SimpleAmount' do
+
+ should 'convert to Amazon formatted string' do
+ assert_equal '5.00', new_amount(5).to_s
+ assert_equal '6.10', new_amount(6.1).to_s
+ assert_equal '5.25', new_amount(5.25).to_s
+ end
+
+ should 'raise an error for negative amounts' do
+ assert_raise(ArgumentError) { new_amount(-1) }
+ end
+
+ end
+
+
+ private
+
+
+ def new_amount(amount)
+ Simplepay::Support::SimpleAmount.new(amount)
+ end
+
+end
Oops, something went wrong.

0 comments on commit d1faf3e

Please sign in to comment.