class AmazonPay::Client

AmazonPay API

This client allows you to make all the necessary API calls to integrate with AmazonPay. This client only uses the standard Ruby library and is not dependant on Rails.

This will extend the client class to add additional helper methods that combine core API calls.

Attributes

access_key[R]
application_name[R]
application_version[R]
currency_code[R]
log_enabled[R]
log_file_name[R]
log_level[R]
merchant_id[R]
platform_id[R]
proxy_addr[RW]
proxy_pass[RW]
proxy_port[RW]
proxy_user[RW]
region[R]
sandbox[R]
secret_key[R]
throttle[R]

Public Class Methods

new( merchant_id, access_key, secret_key, sandbox: false, currency_code: :usd, region: :na, platform_id: nil, throttle: true, application_name: nil, application_version: nil, proxy_addr: :ENV, proxy_port: nil, proxy_user: nil, proxy_pass: nil, log_enabled: false, log_file_name: nil, log_level: :DEBUG ) click to toggle source

API keys are located at: @see sellercentral.amazon.com @param merchant_id [String] @param access_key [String] @param secret_key [String] @optional sandbox [Boolean] Default: false @optional currency_code [Symbol] Default: :usd @optional region [Symbol] Default: :na @optional platform_id [String] Default: nil @optional throttle [Boolean] Default: true @optional application_name [String] @optional application_version [String] @optional log_enabled [Boolean] Default: false @optional log_file_name [String] @optional log_level [Symbol] Default: DEBUG @optional proxy_addr [String] @optional proxy_port [String] @optional proxy_user [String] @optional proxy_pass [String]

# File lib/amazon_pay/client.rb, line 56
def initialize(
  merchant_id,
  access_key,
  secret_key,
  sandbox: false,
  currency_code: :usd,
  region: :na,
  platform_id: nil,
  throttle: true,
  application_name: nil,
  application_version: nil,
  proxy_addr: :ENV,
  proxy_port: nil,
  proxy_user: nil,
  proxy_pass: nil,
  log_enabled: false,
  log_file_name: nil,
  log_level: :DEBUG
)
  @merchant_id = merchant_id
  @access_key = access_key
  @secret_key = secret_key
  @currency_code = currency_code.to_s.upcase
  @sandbox = sandbox
  @sandbox_str = @sandbox ? 'OffAmazonPayments_Sandbox' : 'OffAmazonPayments'
  @region = region
  @mws_endpoint = region_hash[@region] ? region_hash[@region] : raise("Invalid Region Code. (#{@region})")
  @platform_id = platform_id
  @throttle = throttle
  @application_name = application_name
  @application_version = application_version
  @proxy_addr = proxy_addr
  @proxy_port = proxy_port
  @proxy_user = proxy_user
  @proxy_pass = proxy_pass

  @default_hash = {
    'AWSAccessKeyId' => @access_key,
    'SignatureMethod' => 'HmacSHA256',
    'SignatureVersion' => '2',
    'Version' => AmazonPay::API_VERSION
  }

  @log_enabled = log_enabled
  @log_level = log_level
  @log_file_name = log_file_name

  @default_hash['PlatformId'] = @platform_id if @platform_id
end

Public Instance Methods

authorize( amazon_order_reference_id, authorization_reference_id, amount, currency_code: @currency_code, seller_authorization_note: nil, transaction_timeout: nil, capture_now: nil, soft_descriptor: nil, provider_credit_details: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Reserves a specified amount against the payment method(s) stored in the order reference @see pay.amazon.com/documentation/apireference/201751630#201752010 @param amazon_order_reference_id [String] @param authorization_reference_id [String] @param amount [String] @optional currency_code [String] @optional seller_authorization_note [String] @optional transaction_timeout [Integer] @optional capture_now [Boolean] @optional soft_descriptor [String] @optional provider_credit_details [Array of Hash] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 745
def authorize(
  amazon_order_reference_id,
  authorization_reference_id,
  amount,
  currency_code: @currency_code,
  seller_authorization_note: nil,
  transaction_timeout: nil,
  capture_now: nil,
  soft_descriptor: nil,
  provider_credit_details: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'Authorize',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id,
    'AuthorizationReferenceId' => authorization_reference_id,
    'AuthorizationAmount.Amount' => amount,
    'AuthorizationAmount.CurrencyCode' => currency_code
  }

  optional = {
    'SellerAuthorizationNote' => seller_authorization_note,
    'TransactionTimeout' => transaction_timeout,
    'CaptureNow' => capture_now,
    'SoftDescriptor' => soft_descriptor,
    'MWSAuthToken' => mws_auth_token
  }

  optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details

  operation(parameters, optional)
end
authorize_on_billing_agreement( amazon_billing_agreement_id, authorization_reference_id, amount, currency_code: @currency_code, seller_authorization_note: nil, transaction_timeout: nil, capture_now: false, soft_descriptor: nil, seller_note: nil, platform_id: nil, custom_information: nil, seller_order_id: nil, store_name: nil, inherit_shipping_address: nil, supplementary_data: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Reserves a specified amount against the payment method(s) stored in the billing agreement @see pay.amazon.com/documentation/apireference/201751630#201751940 @param amazon_billing_agreement_id [String] @param authorization_reference_id [String] @param amount [String] @optional currency_code [String] @optional seller_authorization_note [String] @optional transaction_timeout [Integer] @optional capture_now [Boolean] @optional soft_descriptor [String] @optional seller_note [String] @optional platform_id [String] @optional custom_information [String] @optional seller_order_id [String] @optional store_name [String] @optional inherit_shipping_address [Boolean] @optional supplementary_data [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 337
def authorize_on_billing_agreement(
  amazon_billing_agreement_id,
  authorization_reference_id,
  amount,
  currency_code: @currency_code,
  seller_authorization_note: nil,
  transaction_timeout: nil,
  capture_now: false,
  soft_descriptor: nil,
  seller_note: nil,
  platform_id: nil,
  custom_information: nil,
  seller_order_id: nil,
  store_name: nil,
  inherit_shipping_address: nil,
  supplementary_data: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'AuthorizeOnBillingAgreement',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id,
    'AuthorizationReferenceId' => authorization_reference_id,
    'AuthorizationAmount.Amount' => amount,
    'AuthorizationAmount.CurrencyCode' => currency_code
  }

  optional = {
    'SellerAuthorizationNote' => seller_authorization_note,
    'TransactionTimeout' => transaction_timeout,
    'CaptureNow' => capture_now,
    'SoftDescriptor' => soft_descriptor,
    'SellerNote' => seller_note,
    'PlatformId' => platform_id,
    'SellerOrderAttributes.CustomInformation' => custom_information,
    'SellerOrderAttributes.SellerOrderId' => seller_order_id,
    'SellerOrderAttributes.StoreName' => store_name,
    'SellerOrderAttributes.SupplementaryData' => supplementary_data,
    'InheritShippingAddress' => inherit_shipping_address,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
cancel_order_reference( amazon_order_reference_id, cancelation_reason: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Cancels a previously confirmed order reference @see pay.amazon.com/documentation/apireference/201751630#201751990 @param amazon_order_reference_id [String] @optional cancelation_reason [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 710
def cancel_order_reference(
  amazon_order_reference_id,
  cancelation_reason: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'CancelOrderReference',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id
  }

  optional = {
    'CancelationReason' => cancelation_reason,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
capture( amazon_authorization_id, capture_reference_id, amount, currency_code: @currency_code, seller_capture_note: nil, soft_descriptor: nil, provider_credit_details: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Captures funds from an authorized payment instrument. @see pay.amazon.com/documentation/apireference/201751630#201752040 @param amazon_authorization_id [String] @param capture_reference_id [String] @param amount [String] @optional currency_code [String] @optional seller_capture_note [String] @optional soft_descriptor [String] @optional provider_credit_details [Array of Hash] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 817
def capture(
  amazon_authorization_id,
  capture_reference_id,
  amount,
  currency_code: @currency_code,
  seller_capture_note: nil,
  soft_descriptor: nil,
  provider_credit_details: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'Capture',
    'SellerId' => merchant_id,
    'AmazonAuthorizationId' => amazon_authorization_id,
    'CaptureReferenceId' => capture_reference_id,
    'CaptureAmount.Amount' => amount,
    'CaptureAmount.CurrencyCode' => currency_code
  }

  optional = {
    'SellerCaptureNote' => seller_capture_note,
    'SoftDescriptor' => soft_descriptor,
    'MWSAuthToken' => mws_auth_token
  }

  optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details

  operation(parameters, optional)
end
charge( amazon_reference_id, authorization_reference_id, charge_amount, charge_currency_code: @currency_code, charge_note: nil, charge_order_id: nil, store_name: nil, custom_information: nil, soft_descriptor: nil, platform_id: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

This method combines multiple API calls to perform a complete transaction with minimum requirements. @param amazon_reference_id [String] @param authorization_reference_id [String] @param charge_amount [String] @optional charge_currency_code [String] @optional charge_note [String] @optional charge_order [String] @optional store_name [String] @optional custom_information [String] @optional soft_descriptor [String] @optional platform_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client_helper.rb, line 21
def charge(
  amazon_reference_id,
  authorization_reference_id,
  charge_amount,
  charge_currency_code: @currency_code,
  charge_note: nil,
  charge_order_id: nil,
  store_name: nil,
  custom_information: nil,
  soft_descriptor: nil,
  platform_id: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  if order_reference?(amazon_reference_id)
    call_order_reference_api(
      amazon_reference_id,
      authorization_reference_id,
      charge_amount,
      charge_currency_code,
      charge_note,
      charge_order_id,
      store_name,
      custom_information,
      soft_descriptor,
      platform_id,
      merchant_id,
      mws_auth_token
    )
  elsif billing_agreement?(amazon_reference_id)
    call_billing_agreement_api(
      amazon_reference_id,
      authorization_reference_id,
      charge_amount,
      charge_currency_code,
      charge_note,
      charge_order_id,
      store_name,
      custom_information,
      soft_descriptor,
      platform_id,
      merchant_id,
      mws_auth_token
    )
  end
end
close_authorization( amazon_authorization_id, closure_reason: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Closes an authorization @see pay.amazon.com/documentation/apireference/201751630#201752070 @param amazon_authorization_id [String] @optional closure_reason [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 947
def close_authorization(
  amazon_authorization_id,
  closure_reason: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'CloseAuthorization',
    'SellerId' => merchant_id,
    'AmazonAuthorizationId' => amazon_authorization_id
  }

  optional = {
    'ClosureReason' => closure_reason,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
close_billing_agreement( amazon_billing_agreement_id, closure_reason: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Confirms that you want to terminate the billing agreement with the buyer and that you do not expect to create any new order references or authorizations on this billing agreement @see pay.amazon.com/documentation/apireference/201751630#201751950 @param amazon_billing_agreement_id [String] @optional closure_reason [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 392
def close_billing_agreement(
  amazon_billing_agreement_id,
  closure_reason: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'CloseBillingAgreement',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id
  }

  optional = {
    'ClosureReason' => closure_reason,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
close_order_reference( amazon_order_reference_id, closure_reason: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Confirms that an order reference has been fulfilled (fully or partially) and that you do not expect to create any new authorizations on this order reference @see pay.amazon.com/documentation/apireference/201751630#201752000 @param amazon_order_reference_id [String] @optional closure_reason [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 976
def close_order_reference(
  amazon_order_reference_id,
  closure_reason: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'CloseOrderReference',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id
  }

  optional = {
    'ClosureReason' => closure_reason,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
confirm_billing_agreement( amazon_billing_agreement_id, merchant_id: @merchant_id, success_url: nil, failure_url: nil, mws_auth_token: nil ) click to toggle source

Confirms that the billing agreement is free of constraints and all required information has been set on the billing agreement @see pay.amazon.com/documentation/apireference/201751630#201751710 @param amazon_billing_agreement_id [String] @optional merchant_id [String] @optional mws_auth_token [String] @optional success_url [String] @optional failure_url [String]

# File lib/amazon_pay/client.rb, line 269
def confirm_billing_agreement(
  amazon_billing_agreement_id,
  merchant_id: @merchant_id,
  success_url: nil,
  failure_url: nil,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'ConfirmBillingAgreement',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id
  }

  optional = {
    'SuccessUrl' => success_url,
    'FailureUrl' => failure_url,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
confirm_order_reference( amazon_order_reference_id, success_url: nil, failure_url: nil, authorization_amount: nil, currency_code: @currency_code, merchant_id: @merchant_id, mws_auth_token: nil, expect_immediate_authorization: nil ) click to toggle source

Confirms that the order reference is free of constraints and all required information has been set on the order reference @see pay.amazon.com/documentation/apireference/201751630#201751980 @param amazon_order_reference_id [String] @optional success_url [String] @optional failure_url [String] @optional authorization_amount [String] @optional currency_code [String] @optional merchant_id [String] @optional mws_auth_token [String] @optional expect_immediate_authorization [Boolean]

# File lib/amazon_pay/client.rb, line 673
def confirm_order_reference(
  amazon_order_reference_id,
  success_url: nil,
  failure_url: nil,
  authorization_amount: nil,
  currency_code: @currency_code,
  merchant_id: @merchant_id,
  mws_auth_token: nil,
  expect_immediate_authorization: nil
)

  parameters = {
    'Action' => 'ConfirmOrderReference',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id
  }

  optional = {
    'SuccessUrl' => success_url,
    'FailureUrl' => failure_url,
    'AuthorizationAmount.Amount' => authorization_amount,
    'AuthorizationAmount.CurrencyCode' => currency_code,
    'MWSAuthToken' => mws_auth_token,
    'ExpectImmediateAuthorization' => expect_immediate_authorization
  }

  optional['AuthorizationAmount.CurrencyCode'] = nil if authorization_amount.nil?

  operation(parameters, optional)
end
create_order_reference_for_id( id, id_type, inherit_shipping_address: nil, confirm_now: nil, amount: nil, currency_code: @currency_code, platform_id: nil, seller_note: nil, seller_order_id: nil, store_name: nil, custom_information: nil, supplementary_data: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Creates an order reference for the given object @see pay.amazon.com/documentation/apireference/201751630#201751670 @param id [String] @param id_type [String] @optional inherit_shipping_address [Boolean] @optional confirm_now [Boolean] @optional amount [String] (required when confirm_now is set to true) @optional currency_code [String] @optional platform_id [String] @optional seller_note [String] @optional seller_order_id [String] @optional store_name [String] @optional custom_information [String] @optional supplementary_data [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 133
def create_order_reference_for_id(
  id,
  id_type,
  inherit_shipping_address: nil,
  confirm_now: nil,
  amount: nil,
  currency_code: @currency_code,
  platform_id: nil,
  seller_note: nil,
  seller_order_id: nil,
  store_name: nil,
  custom_information: nil,
  supplementary_data: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'CreateOrderReferenceForId',
    'SellerId' => merchant_id,
    'Id' => id,
    'IdType' => id_type
  }

  optional = {
    'InheritShippingAddress' => inherit_shipping_address,
    'ConfirmNow' => confirm_now,
    'OrderReferenceAttributes.OrderTotal.Amount' => amount,
    'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code,
    'OrderReferenceAttributes.PlatformId' => platform_id,
    'OrderReferenceAttributes.SellerNote' => seller_note,
    'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
    'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
    'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
    'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_authorization_details( amazon_authorization_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns the status of a particular authorization and the total amount captured on the authorization @see pay.amazon.com/documentation/apireference/201751630#201752030 @param amazon_authorization_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 787
def get_authorization_details(
  amazon_authorization_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetAuthorizationDetails',
    'SellerId' => merchant_id,
    'AmazonAuthorizationId' => amazon_authorization_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_billing_agreement_details( amazon_billing_agreement_id, address_consent_token: nil, access_token: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns details about the Billing Agreement object and its current state @see pay.amazon.com/documentation/apireference/201751630#201751690 @param amazon_billing_agreement_id [String] @optional address_consent_token [String] @optional access_token [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 182
def get_billing_agreement_details(
  amazon_billing_agreement_id,
  address_consent_token: nil,
  access_token: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetBillingAgreementDetails',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id
  }

  optional = {
    # Preseving address_consent_token for backwards compatibility
    # AccessToken returns all data in AddressConsentToken plus new data
    # You cannot pass both address_consent_token and access_token in
    # the same call or you will encounter a 400/"AmbiguousToken" error
    'AccessToken' => access_token,
    'AddressConsentToken' => address_consent_token,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_capture_details( amazon_capture_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns the status of a particular capture and the total amount refunded on the capture @see pay.amazon.com/documentation/apireference/201751630#201752060 @param amazon_capture_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 855
def get_capture_details(
  amazon_capture_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetCaptureDetails',
    'SellerId' => merchant_id,
    'AmazonCaptureId' => amazon_capture_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_merchant_account_status( merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns status of the merchant @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 482
def get_merchant_account_status(
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetMerchantAccountStatus',
    'SellerId' => merchant_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_order_reference_details( amazon_order_reference_id, address_consent_token: nil, access_token: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns details about the Order Reference object and its current state @see pay.amazon.com/documentation/apireference/201751630#201751970 @param amazon_order_reference_id [String] @optional address_consent_token [String] @optional access_token [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 506
def get_order_reference_details(
  amazon_order_reference_id,
  address_consent_token: nil,
  access_token: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetOrderReferenceDetails',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id
  }

  optional = {
    # Preseving address_consent_token for backwards compatibility
    # AccessToken returns all data in AddressConsentToken plus new data
    'AccessToken' => access_token || address_consent_token,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_provider_credit_details( amazon_provider_credit_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

@param amazon_provider_credit_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 1000
def get_provider_credit_details(
  amazon_provider_credit_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetProviderCreditDetails',
    'SellerId' => merchant_id,
    'AmazonProviderCreditId' => amazon_provider_credit_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_provider_credit_reversal_details( amazon_provider_credit_reversal_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

@param amazon_provider_credit_reversal_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 1022
def get_provider_credit_reversal_details(
  amazon_provider_credit_reversal_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetProviderCreditReversalDetails',
    'SellerId' => merchant_id,
    'AmazonProviderCreditReversalId' => amazon_provider_credit_reversal_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_refund_details( amazon_refund_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Returns the status of a particular refund @see pay.amazon.com/documentation/apireference/201751630#201752100 @param amazon_refund_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 922
def get_refund_details(
  amazon_refund_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'GetRefundDetails',
    'SellerId' => merchant_id,
    'AmazonRefundId' => amazon_refund_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
get_service_status() click to toggle source

The GetServiceStatus operation returns the operational status of the AmazonPay API section of Amazon Marketplace Web Service (Amazon MWS). Status values are GREEN, GREEN_I, YELLOW, and RED. @see pay.amazon.com/documentation/apireference/201751630#201752110

# File lib/amazon_pay/client.rb, line 109
def get_service_status
  parameters = {
    'Action' => 'GetServiceStatus'
  }

  operation(parameters, {})
end
list_order_reference( query_id, query_id_type, created_time_range_start: nil, created_time_range_end: nil, sort_order: nil, page_size: nil, order_reference_status_list_filter: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Allows the search of any Amazon Pay order made using secondary seller order IDs generated manually, a solution provider, or a custom order fulfillment service. @param query_id [String] @param query_id_type [String] @optional created_time_range_start [String] @optional created_time_range_end [String] @optional sort_order [String] @optional page_size [Integer] @optional order_reference_status_list_filter Array @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 425
def list_order_reference(
  query_id,
  query_id_type,
  created_time_range_start: nil,
  created_time_range_end: nil,
  sort_order: nil,
  page_size: nil,
  order_reference_status_list_filter: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  payment_domain = payment_domain_hash[@region]

  parameters = {
    'Action' => 'ListOrderReference',
    'SellerId' => merchant_id,
    'QueryId' => query_id,
    'QueryIdType' => query_id_type
  }

  optional = {
    'CreatedTimeRange.StartTime' => created_time_range_start,
    'CreatedTimeRange.EndTime' => created_time_range_end,
    'SortOrder' => sort_order,
    'PageSize' => page_size,
    'PaymentDomain' => payment_domain,
    'MWSAuthToken' => mws_auth_token
  }

  if order_reference_status_list_filter
    order_reference_status_list_filter.each_with_index do |val, index|
      optional_key = "OrderReferenceStatusListFilter.OrderReferenceStatus.#{index + 1}"
      optional[optional_key] = val
    end
  end

  operation(parameters, optional)
end
list_order_reference_by_next_token(next_page_token) click to toggle source

When ListOrderReference returns multiple pages you can continue by using the NextPageToken returned by ListOrderReference @param next_page_token [String]

# File lib/amazon_pay/client.rb, line 469
def list_order_reference_by_next_token(next_page_token)
  parameters = {
    'Action' => 'ListOrderReferenceByNextToken',
    'SellerId' => @merchant_id,
    'NextPageToken' => next_page_token
  }

  operation(parameters, {})
end
modify_order_attributes( amazon_order_reference_id, seller_note: nil, seller_order_id: nil, payment_service_provider_id: nil, payment_service_provider_order_id: nil, request_payment_authorization: nil, store_name: nil, custom_information: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Modify order attributes such as CustomInformation for the order This is a convenience function for set_order_attributes to prevent accidentally passing extra variables that can't be modified ater Amazon Order Reference (ORO) is confirmed. @see pay.amazon.com/documentation/apireference/201751630#201751960 @param amazon_order_reference_id [String] @optional request_payment_authorization [Boolean] @optional seller_note [String] @optional seller_order_id [String] @optional store_name [String] @optional custom_information [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client_helper.rb, line 82
def modify_order_attributes(
  amazon_order_reference_id,
  seller_note: nil,
  seller_order_id: nil,
  payment_service_provider_id: nil,
  payment_service_provider_order_id: nil,
  request_payment_authorization: nil,
  store_name: nil,
  custom_information: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  set_order_attributes(
    # amount:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
    # currency_code:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
    # platform_id:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
    amazon_order_reference_id,
    seller_note: seller_note,
    seller_order_id: seller_order_id,
    payment_service_provider_id: payment_service_provider_id,
    payment_service_provider_order_id: payment_service_provider_order_id,
    request_payment_authorization: request_payment_authorization,
    store_name: store_name,
    # order_item_categories:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
    custom_information: custom_information,
    merchant_id: merchant_id,
    mws_auth_token: mws_auth_token
  )
end
refund( amazon_capture_id, refund_reference_id, amount, currency_code: @currency_code, seller_refund_note: nil, soft_descriptor: nil, provider_credit_reversal_details: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Refunds a previously captured amount @see pay.amazon.com/documentation/apireference/201751630#201752080 @param amazon_capture_id [String] @param refund_reference_id [String] @param amount [String] @optional currency_code [String] @optional seller_refund_note [String] @optional soft_descriptor [String] @optional provider_credit_reversal_details [Array of Hash] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 885
def refund(
  amazon_capture_id,
  refund_reference_id,
  amount,
  currency_code: @currency_code,
  seller_refund_note: nil,
  soft_descriptor: nil,
  provider_credit_reversal_details: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'Refund',
    'SellerId' => merchant_id,
    'AmazonCaptureId' => amazon_capture_id,
    'RefundReferenceId' => refund_reference_id,
    'RefundAmount.Amount' => amount,
    'RefundAmount.CurrencyCode' => currency_code
  }

  optional = {
    'SellerRefundNote' => seller_refund_note,
    'SoftDescriptor' => soft_descriptor,
    'MWSAuthToken' => mws_auth_token
  }

  optional.merge!(set_provider_credit_reversal_details(provider_credit_reversal_details)) if provider_credit_reversal_details

  operation(parameters, optional)
end
reverse_provider_credit( amazon_provider_credit_id, credit_reversal_reference_id, amount, currency_code: @currency_code, credit_reversal_note: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

@param amazon_provider_credit_id [String] @param credit_reversal_reference_id [String] @param amount [String] @optional currency_code [String] @optional credit_reversal_note [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 1048
def reverse_provider_credit(
  amazon_provider_credit_id,
  credit_reversal_reference_id,
  amount,
  currency_code: @currency_code,
  credit_reversal_note: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'ReverseProviderCredit',
    'SellerId' => merchant_id,
    'AmazonProviderCreditId' => amazon_provider_credit_id,
    'CreditReversalReferenceId' => credit_reversal_reference_id,
    'CreditReversalAmount.Amount' => amount,
    'CreditReversalAmount.CurrencyCode' => currency_code
  }

  optional = {
    'CreditReversalNote' => credit_reversal_note,
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end
set_billing_agreement_details( amazon_billing_agreement_id, platform_id: nil, seller_note: nil, seller_billing_agreement_id: nil, custom_information: nil, store_name: nil, merchant_id: @merchant_id, billing_agreement_type: nil, subscription_amount: nil, subscription_currency_code: @currency_code, mws_auth_token: nil ) click to toggle source

Sets billing agreement details such as a description of the agreement and other information about the seller. @see pay.amazon.com/documentation/apireference/201751630#201751700 @param amazon_billing_agreement_id [String] @optional platform_id [String] @optional seller_note [String] @optional seller_billing_agreement_id [String] @optional custom_information [String] @optional store_name [String] @optional merchant_id [String] @optional mws_auth_token [String] @optional billing_agreement_type [String] - one of CustomerInitiatedTransaction or MerchantInitiatedTransaction @optional subscription_amount [String] @optional subscription_currency_code [String]

# File lib/amazon_pay/client.rb, line 224
def set_billing_agreement_details(
  amazon_billing_agreement_id,
  platform_id: nil,
  seller_note: nil,
  seller_billing_agreement_id: nil,
  custom_information: nil,
  store_name: nil,
  merchant_id: @merchant_id,
  billing_agreement_type: nil,
  subscription_amount: nil,
  subscription_currency_code: @currency_code,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'SetBillingAgreementDetails',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id
  }

  optional = {
    'BillingAgreementAttributes.PlatformId' => platform_id,
    'BillingAgreementAttributes.SellerNote' => seller_note,
    'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
    'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
    'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
    'BillingAgreementAttributes.BillingAgreementType' => billing_agreement_type,
    'BillingAgreementAttributes.SubscriptionAmount.Amount' => subscription_amount,
    'BillingAgreementAttributes.SubscriptionAmount.CurrencyCode' => subscription_currency_code,
    'MWSAuthToken' => mws_auth_token
  }

  optional['BillingAgreementAttributes.SubscriptionAmount.CurrencyCode'] = nil if subscription_amount.nil?

  operation(parameters, optional)
end
set_order_attributes( amazon_order_reference_id, amount: nil, currency_code: @currency_code, platform_id: nil, seller_note: nil, seller_order_id: nil, payment_service_provider_id: nil, payment_service_provider_order_id: nil, request_payment_authorization: nil, store_name: nil, order_item_categories: nil, custom_information: nil, supplementary_data: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Sets order attributes such as the order total and a description for the order @see pay.amazon.com/documentation/apireference/201751630#201751960 @param amazon_order_reference_id [String] @optional amount [String] @optional currency_code [String] @optional platform_id [String] @optional seller_note [String] @optional seller_order_id [String] @optional request_payment_authorization [Boolean] @optional store_name [String] @optional order_item_categories Array @optional custom_information [String] @optional supplementary_data [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 609
def set_order_attributes(
  amazon_order_reference_id,
  amount: nil,
  currency_code: @currency_code,
  platform_id: nil,
  seller_note: nil,
  seller_order_id: nil,
  payment_service_provider_id: nil,
  payment_service_provider_order_id: nil,
  request_payment_authorization: nil,
  store_name: nil,
  order_item_categories: nil,
  custom_information: nil,
  supplementary_data: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'SetOrderAttributes',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id
  }

  optional = {
    'OrderAttributes.OrderTotal.Amount' => amount,
    'OrderAttributes.OrderTotal.CurrencyCode' => currency_code,
    'OrderAttributes.PlatformId' => platform_id,
    'OrderAttributes.SellerNote' => seller_note,
    'OrderAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
    'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId' => payment_service_provider_id,
    'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId' => payment_service_provider_order_id,
    'OrderAttributes.RequestPaymentAuthorization' => request_payment_authorization,
    'OrderAttributes.SellerOrderAttributes.StoreName' => store_name,
    'OrderAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
    'OrderAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
    'MWSAuthToken' => mws_auth_token
  }

  optional['OrderAttributes.OrderTotal.CurrencyCode'] = nil if amount.nil?

  if order_item_categories
    optional.merge!(
      get_categories_list(
        'OrderAttributes',
        order_item_categories
      )
    )
  end

  operation(parameters, optional)
end
set_order_reference_details( amazon_order_reference_id, amount, currency_code: @currency_code, platform_id: nil, seller_note: nil, seller_order_id: nil, request_payment_authorization: nil, store_name: nil, order_item_categories: nil, custom_information: nil, supplementary_data: nil, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Sets order reference details such as the order total and a description for the order @see pay.amazon.com/documentation/apireference/201751630#201751960 @param amazon_order_reference_id [String] @param amount [String] @optional currency_code [String] @optional platform_id [String] @optional seller_note [String] @optional seller_order_id [String] @optional request_payment_authorization [Boolean] @optional store_name [String] @optional order_item_categories Array @optional custom_information [String] @optional supplementary_data [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 546
def set_order_reference_details(
  amazon_order_reference_id,
  amount,
  currency_code: @currency_code,
  platform_id: nil,
  seller_note: nil,
  seller_order_id: nil,
  request_payment_authorization: nil,
  store_name: nil,
  order_item_categories: nil,
  custom_information: nil,
  supplementary_data: nil,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'SetOrderReferenceDetails',
    'SellerId' => merchant_id,
    'AmazonOrderReferenceId' => amazon_order_reference_id,
    'OrderReferenceAttributes.OrderTotal.Amount' => amount,
    'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code
  }

  optional = {
    'OrderReferenceAttributes.PlatformId' => platform_id,
    'OrderReferenceAttributes.RequestPaymentAuthorization' => request_payment_authorization,
    'OrderReferenceAttributes.SellerNote' => seller_note,
    'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
    'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
    'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
    'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
    'MWSAuthToken' => mws_auth_token
  }

  if order_item_categories
    optional.merge!(
      get_categories_list(
        'OrderReferenceAttributes',
        order_item_categories
      )
    )
  end

  operation(parameters, optional)
end
validate_billing_agreement( amazon_billing_agreement_id, merchant_id: @merchant_id, mws_auth_token: nil ) click to toggle source

Validates the status of the BillingAgreement object and the payment method associated with it @see pay.amazon.com/documentation/apireference/201751630#201751720 @param amazon_billing_agreement_id [String] @optional merchant_id [String] @optional mws_auth_token [String]

# File lib/amazon_pay/client.rb, line 298
def validate_billing_agreement(
  amazon_billing_agreement_id,
  merchant_id: @merchant_id,
  mws_auth_token: nil
)

  parameters = {
    'Action' => 'ValidateBillingAgreement',
    'SellerId' => merchant_id,
    'AmazonBillingAgreementId' => amazon_billing_agreement_id
  }

  optional = {
    'MWSAuthToken' => mws_auth_token
  }

  operation(parameters, optional)
end

Private Instance Methods

billing_agreement?(amazon_reference_id) click to toggle source
# File lib/amazon_pay/client_helper.rb, line 232
def billing_agreement?(amazon_reference_id)
  amazon_reference_id.start_with?('C', 'B')
end
call_billing_agreement_api( amazon_reference_id, authorization_reference_id, charge_amount, charge_currency_code, charge_note, charge_order_id, store_name, custom_information, soft_descriptor, platform_id, merchant_id, mws_auth_token ) click to toggle source
# File lib/amazon_pay/client_helper.rb, line 166
def call_billing_agreement_api(
      amazon_reference_id,
      authorization_reference_id,
      charge_amount,
      charge_currency_code,
      charge_note,
      charge_order_id,
      store_name,
      custom_information,
      soft_descriptor,
      platform_id,
      merchant_id,
      mws_auth_token
)

  response = get_billing_agreement_details(
    amazon_reference_id,
    merchant_id: merchant_id,
    mws_auth_token: mws_auth_token
  )
  if response.get_element('GetBillingAgreementDetailsResponse/GetBillingAgreementDetailsResult/BillingAgreementDetails/BillingAgreementStatus', 'State').eql?('Draft')
    response = set_billing_agreement_details(
      amazon_reference_id,
      platform_id: platform_id,
      seller_note: charge_note,
      seller_billing_agreement_id: charge_order_id,
      store_name: store_name,
      custom_information: custom_information,
      merchant_id: merchant_id,
      mws_auth_token: mws_auth_token
    )
    if response.success
      response = confirm_billing_agreement(
        amazon_reference_id,
        merchant_id: merchant_id,
        mws_auth_token: mws_auth_token
      )
      return response if response.success.eql?(false)
    end
  end

  response = authorize_on_billing_agreement(
    amazon_reference_id,
    authorization_reference_id,
    charge_amount,
    currency_code: charge_currency_code,
    seller_authorization_note: charge_note,
    transaction_timeout: 0,
    capture_now: true,
    soft_descriptor: soft_descriptor,
    seller_note: charge_note,
    platform_id: platform_id,
    seller_order_id: charge_order_id,
    store_name: store_name,
    custom_information: custom_information,
    inherit_shipping_address: true,
    merchant_id: merchant_id,
    mws_auth_token: mws_auth_token
  )
  response
end
call_order_reference_api( amazon_reference_id, authorization_reference_id, charge_amount, charge_currency_code, charge_note, charge_order_id, store_name, custom_information, soft_descriptor, platform_id, merchant_id, mws_auth_token ) click to toggle source
# File lib/amazon_pay/client_helper.rb, line 115
def call_order_reference_api(
  amazon_reference_id,
  authorization_reference_id,
  charge_amount,
  charge_currency_code,
  charge_note,
  charge_order_id,
  store_name,
  custom_information,
  soft_descriptor,
  platform_id,
  merchant_id,
  mws_auth_token
)

  response = set_order_reference_details(
    amazon_reference_id,
    charge_amount,
    currency_code: charge_currency_code,
    platform_id: platform_id,
    seller_note: charge_note,
    seller_order_id: charge_order_id,
    store_name: store_name,
    custom_information: custom_information,
    merchant_id: merchant_id,
    mws_auth_token: mws_auth_token
  )
  if response.success
    response = confirm_order_reference(
      amazon_reference_id,
      merchant_id: merchant_id,
      mws_auth_token: mws_auth_token
    )
    if response.success
      response = authorize(
        amazon_reference_id,
        authorization_reference_id,
        charge_amount,
        currency_code: charge_currency_code,
        seller_authorization_note: charge_note,
        transaction_timeout: 0,
        capture_now: true,
        soft_descriptor: soft_descriptor,
        merchant_id: merchant_id,
        mws_auth_token: mws_auth_token
      )
    end
  end
  response
end
get_categories_list(attribute_key, categories) click to toggle source
# File lib/amazon_pay/client.rb, line 1129
def get_categories_list(attribute_key, categories)
  list = {}

  categories.each_with_index do |val, index|
    list.merge!("#{attribute_key}.SellerOrderAttributes.OrderItemCategories.OrderItemCategory.#{index + 1}" => val)
  end

  list
end
operation(parameters, optional) click to toggle source
# File lib/amazon_pay/client.rb, line 1139
def operation(parameters, optional)
  AmazonPay::Request.new(
    parameters,
    optional,
    @default_hash,
    @mws_endpoint,
    @sandbox_str,
    @secret_key,
    @proxy_addr,
    @proxy_port,
    @proxy_user,
    @proxy_pass,
    @throttle,
    @application_name,
    @application_version,
    @log_enabled,
    @log_file_name,
    @log_level
  ).send_post
end
order_reference?(amazon_reference_id) click to toggle source
# File lib/amazon_pay/client_helper.rb, line 228
def order_reference?(amazon_reference_id)
  amazon_reference_id.start_with?('S', 'P')
end
payment_domain_hash() click to toggle source
# File lib/amazon_pay/client.rb, line 1088
def payment_domain_hash
  {
    jp: 'FE_JPY',
    uk: 'EU_GBP',
    de: 'EU_EUR',
    eu: 'EU_EUR',
    us: 'NA_USD',
    na: 'NA_USD'
  }
end
region_hash() click to toggle source
# File lib/amazon_pay/client.rb, line 1077
def region_hash
  {
    jp: 'mws.amazonservices.jp',
    uk: 'mws-eu.amazonservices.com',
    de: 'mws-eu.amazonservices.com',
    eu: 'mws-eu.amazonservices.com',
    us: 'mws.amazonservices.com',
    na: 'mws.amazonservices.com'
  }
end
set_provider_credit_details(provider_credit_details) click to toggle source

This method builds the provider credit details hash that will be combined with either the authorize or capture API call.

# File lib/amazon_pay/client.rb, line 1102
def set_provider_credit_details(provider_credit_details)
  member_details = {}
  provider_credit_details.each_with_index do |val, index|
    member = index + 1
    member_details["ProviderCreditList.member.#{member}.ProviderId"] = val[:provider_id]
    member_details["ProviderCreditList.member.#{member}.CreditAmount.Amount"] = val[:amount]
    member_details["ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode"] = val[:currency_code]
  end

  member_details
end
set_provider_credit_reversal_details(provider_credit_reversal_details) click to toggle source

This method builds the provider credit reversal details hash that will be combined with the refund API call.

# File lib/amazon_pay/client.rb, line 1117
def set_provider_credit_reversal_details(provider_credit_reversal_details)
  member_details = {}
  provider_credit_reversal_details.each_with_index do |val, index|
    member = index + 1
    member_details["ProviderCreditReversalList.member.#{member}.ProviderId"] = val[:provider_id]
    member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount"] = val[:amount]
    member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode"] = val[:currency_code]
  end

  member_details
end