# frozen_string_literal: true require 'peddler/client' module MWS module OffAmazonPayments # The Off-Amazon Payments API helps you to process payments for purchases # made by buyers on your website using the Login and Pay with Amazon # service. This API enables you to programmatically retrieve shipping and # payment information provided by the buyer from their Amazon account. It # allows you to authorize, capture, and refund payments, enabling a variety # of payments scenarios. # # @note The Off-Amazon Payments API section is only applicable to payments # made through the Login and Pay with Amazon service offered by Amazon # Payments. You cannot use this API section to process payments for Amazon # Marketplace, Amazon Webstore, or Checkout by Amazon. class Client < ::Peddler::Client self.version = '2013-01-01' self.path = "/OffAmazonPayments/#{version}/" # Switches the client to the sandbox environment # # @see https://payments.amazon.com/help/Checkout-by-Amazon/Using-the-Checkout-by-Amazon-Sandbox/Overview-of-the-Sandbox # @return [self] def sandbox self.path = "/OffAmazonPayments_Sandbox/#{version}/" self end # Reserves a specified amount against the payment method(s) stored in the # order reference # # @see https://payments.amazon.com/documentation/apireference/201752010 # @param [String] amazon_order_reference_id # @param [String] authorization_reference_id # @param [Struct, Hash] authorization_amount # @param [Hash] opts # @option opts [String] :seller_authorization_note # @option opts [Integer] :transaction_timeout # @option opts [Boolean] :capture_now # @option opts [String] :soft_descriptor # @return [Peddler::XMLParser] def authorize(amazon_order_reference_id, authorization_reference_id, authorization_amount, opts = {}) operation('Authorize') .add(opts) .add('AmazonOrderReferenceId' => amazon_order_reference_id, 'AuthorizationReferenceId' => authorization_reference_id, 'AuthorizationAmount' => authorization_amount) run end # Cancels a previously confirmed order reference # # @see https://payments.amazon.com/documentation/apireference/201751990 # @param [String] amazon_order_reference_id # @param [Hash] opts # @option opts [String] cancelation_reason # @return [Peddler::XMLParser] def cancel_order_reference(amazon_order_reference_id, opts = {}) operation('CancelOrderReference') .add(opts) .add('AmazonOrderReferenceId' => amazon_order_reference_id) run end # Captures funds from an authorized payment instrument # # @see https://payments.amazon.com/documentation/apireference/201752040 # @param [String] amazon_authorization_id # @param [String] capture_reference_id # @param [Struct, Hash] capture_amount # @param [Hash] opts # @option opts [String] :seller_capture_note # @option opts [String] :soft_descriptor # @return [Peddler::XMLParser] def capture(amazon_authorization_id, capture_reference_id, capture_amount, opts = {}) operation('Capture') .add(opts) .add('AmazonAuthorizationId' => amazon_authorization_id, 'CaptureReferenceId' => capture_reference_id, 'CaptureAmount' => capture_amount) run end # Closes an authorization # # @see https://payments.amazon.com/documentation/apireference/201752070 # @param [String] amazon_authorization_id # @param [Hash] opts # @option opts [String] closure_reason # @return [Peddler::XMLParser] def close_authorization(amazon_authorization_id, opts = {}) operation('CloseAuthorization') .add(opts) .add('AmazonAuthorizationId' => amazon_authorization_id) run end # 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 https://payments.amazon.com/documentation/apireference/201752000 # @param [String] amazon_order_reference_id # @param [Hash] opts # @option opts [String] closure_reason # @return [Peddler::XMLParser] def close_order_reference(amazon_order_reference_id, opts = {}) operation('CloseOrderReference') .add(opts) .add('AmazonOrderReferenceId' => amazon_order_reference_id) run end # Confirms that the order reference is free of constraints and all # required information has been set on the order reference # # @see https://payments.amazon.com/documentation/apireference/201751980 # @param [String] amazon_order_reference_id # @return [Peddler::XMLParser] def confirm_order_reference(amazon_order_reference_id) operation('ConfirmOrderReference') .add('AmazonOrderReferenceId' => amazon_order_reference_id) run end # Creates an order reference for the given object # # @see https://payments.amazon.com/documentation/apireference/201751670 # @param [String] id # @param [String] id_type # @param [Hash] opts # @option opts [Boolean] :inherit_shipping_address # @option opts [Boolean] :confirm_now # @option opts [Struct, Hash] :order_reference_attributes # @return [Peddler::XMLParser] def create_order_reference_for_id(id, id_type, opts = {}) operation('CreateOrderReferenceForId') .add(opts) .add('Id' => id, 'IdType' => id_type) run end # Returns the status of a particular authorization and the total amount # captured on the authorization # # @see https://payments.amazon.com/documentation/apireference/201752030 # @param [String] amazon_authorization_id # @return [Peddler::XMLParser] def get_authorization_details(amazon_authorization_id) operation('GetAuthorizationDetails') .add('AmazonAuthorizationId' => amazon_authorization_id) run end # Returns the status of a particular capture and the total amount refunded # on the capture # # @see https://payments.amazon.com/documentation/apireference/201752060 # @param [String] amazon_capture_id # @return [Peddler::XMLParser] def get_capture_details(amazon_capture_id) operation('GetCaptureDetails') .add('AmazonCaptureId' => amazon_capture_id) run end # Returns details about the Order Reference object and its current state # # @see https://payments.amazon.com/documentation/apireference/201751970 # @param [String] amazon_order_reference_id # @param [Hash] opts # @option opts [String] address_consent_token # @return [Peddler::XMLParser] def get_order_reference_details(amazon_order_reference_id, opts = {}) operation('GetOrderReferenceDetails') .add(opts) .add('AmazonOrderReferenceId' => amazon_order_reference_id) run end # Returns the status of a particular refund # # @see https://payments.amazon.com/documentation/apireference/201752100 # @param [String] amazon_refund_id # @return [Peddler::XMLParser] def get_refund_details(amazon_refund_id) operation('GetRefundDetails') .add('AmazonRefundId' => amazon_refund_id) run end # Gets the operational status of the API # # @see https://payments.amazon.com/documentation/apireference/201752110 # @return [Peddler::XMLParser] def get_service_status operation('GetServiceStatus') run end # Refunds a previously captured amount # # @see https://payments.amazon.com/documentation/apireference/201752080 # @param [String] amazon_capture_id # @param [String] refund_reference_id # @param [Struct, Hash] refund_amount # @param [Hash] opts # @option opts [String] :seller_refund_note # @option opts [String] :soft_descriptor # @return [Peddler::XMLParser] def refund(amazon_capture_id, refund_reference_id, refund_amount, opts = {}) operation('Refund') .add(opts) .add('AmazonCaptureId' => amazon_capture_id, 'RefundReferenceId' => refund_reference_id, 'RefundAmount' => refund_amount) run end # Sets order reference details such as the order total and a description # for the order # # @see https://payments.amazon.com/documentation/apireference/201751960 # @param [String] amazon_order_reference_id # @param [Struct, Hash] order_total # @param [Hash] opts # @option opts [String] :platform_id # @option opts [String] :seller_note # @option opts [Struct, Hash] :seller_order_attributes # @return [Peddler::XMLParser] def set_order_reference_details(amazon_order_reference_id, order_total, opts = {}) order_reference_attributes = opts.update('OrderTotal' => order_total) operation('SetOrderReferenceDetails') .add('AmazonOrderReferenceId' => amazon_order_reference_id, 'OrderReferenceAttributes' => order_reference_attributes) run end # Reserves a specified amount against the payment method(s) stored in the # billing agreement # # @see https://payments.amazon.com/documentation/apireference/201751940 # @param [String] amazon_billing_agreement_id # @param [String] authorization_reference_id # @param [Hash, Struct] authorization_amount # @param [Hash] opts # @option opts [String] :seller_authorization_note # @option opts [Integer] :transaction_timeout # @option opts [Boolean] :capture_now # @option opts [String] :soft_descriptor # @option opts [String] :seller_note # @option opts [String] :platform_id # @option opts [Hash, Struct] :seller_order_attributes # @option opts [Boolean] :inherit_shipping_address # @return [Peddler::XMLParser] def authorize_on_billing_agreement(amazon_billing_agreement_id, authorization_reference_id, authorization_amount, opts = {}) operation('AuthorizeOnBillingAgreement') .add(opts) .add('AmazonBillingAgreementId' => amazon_billing_agreement_id, 'AuthorizationReferenceId' => authorization_reference_id, 'AuthorizationAmount' => authorization_amount) run end # 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 https://payments.amazon.com/documentation/apireference/201751950 # @param [String] amazon_billing_agreement_id # @param [Hash] opts # @option opts [String] :closure_reason # @return [Peddler::XMLParser] def close_billing_agreement(amazon_billing_agreement_id, opts = {}) operation('CloseBillingAgreement') .add(opts) .add('AmazonBillingAgreementId' => amazon_billing_agreement_id) run end # Confirms that the billing agreement is free of constraints and all # required information has been set on the billing agreement # # @see https://payments.amazon.com/documentation/apireference/201751710 # @param [String] amazon_billing_agreement_id # @return [Peddler::XMLParser] def confirm_billing_agreement(amazon_billing_agreement_id) operation('ConfirmBillingAgreement') .add('AmazonBillingAgreementId' => amazon_billing_agreement_id) run end # Returns details about the Billing Agreement object and its current state # # @see https://payments.amazon.com/documentation/apireference/201751690 # @param [String] amazon_billing_agreement_id # @param [Hash] opts # @option opts [String] :address_consent_token # @return [Peddler::XMLParser] def get_billing_agreement_details(amazon_billing_agreement_id, opts = {}) operation('GetBillingAgreementDetails') .add(opts) .add('AmazonBillingAgreementId' => amazon_billing_agreement_id) run end # Sets billing agreement details such as a description of the agreement # and other information about the seller # # @see https://payments.amazon.com/documentation/apireference/201751700 # @param [String] amazon_billing_agreement_id # @param [Struct, Hash] billing_agreement_attributes # @return [Peddler::XMLParser] def set_billing_agreement_details(amazon_billing_agreement_id, billing_agreement_attributes) operation('SetBillingAgreementDetails') .add('AmazonBillingAgreementId' => amazon_billing_agreement_id, 'BillingAgreementAttributes' => billing_agreement_attributes) run end # Validates the status of the BillingAgreement object and the payment # method associated with it # # @see https://payments.amazon.com/documentation/apireference/201751720 # @param [String] amazon_billing_agreement_id # @return [Peddler::XMLParser] def validate_billing_agreement(amazon_billing_agreement_id) operation('ValidateBillingAgreement') .add('AmazonBillingAgreementId' => amazon_billing_agreement_id) run end end end end