class PayWithAmazon::Client
Pay with Amazon API
This client allows you to make all the necessary API calls to integrate with Login
and Pay with Amazon. 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
Public Class Methods
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 proxy_addr
[String] @optional proxy_port
[String] @optional proxy_user
[String] @optional proxy_pass
[String]
# File lib/pay_with_amazon/client.rb, line 47 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) @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', 'Timestamp' => Time.now.utc.iso8601, 'Version' => PayWithAmazon::API_VERSION } @default_hash['PlatformId'] = @platform_id if @platform_id end
Public Instance Methods
Cancels a previously confirmed order reference @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_CancelOrderReference.html @param amazon_order_reference_id [String] @optional cancelation_reason [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 460 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
Captures funds from an authorized payment instrument. @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_Capture.html @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/pay_with_amazon/client.rb, line 564 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
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/pay_with_amazon/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 is_order_reference?(amazon_reference_id) response = 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) return response end if is_billing_agreement?(amazon_reference_id) response = 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) return response end 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 docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_CloseBillingAgreement.html @param amazon_billing_agreement_id [String] @optional closure_reason [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 339 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
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 docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_CloseOrderReference.html @param amazon_order_reference_id [String] @optional closure_reason [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 718 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
Confirms that the billing agreement is free of constraints and all required information has been set on the billing agreement @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_ConfirmBillingAgreement.html @param amazon_billing_agreement_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 226 def confirm_billing_agreement( amazon_billing_agreement_id, merchant_id: @merchant_id, mws_auth_token: nil) parameters = { 'Action' => 'ConfirmBillingAgreement', 'SellerId' => merchant_id, 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optional = { 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Confirms that the order reference is free of constraints and all required information has been set on the order reference @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_ConfirmOrderReference.html @param amazon_order_reference_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 436 def confirm_order_reference( amazon_order_reference_id, merchant_id: @merchant_id, mws_auth_token: nil) parameters = { 'Action' => 'ConfirmOrderReference', 'SellerId' => merchant_id, 'AmazonOrderReferenceId' => amazon_order_reference_id } optional = { 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Creates an order reference for the given object @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_CreateOrderReferenceForId.html @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 merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 117 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, 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, 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Returns details about the Billing Agreement object and its current state @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetBillingAgreementDetails.html @param amazon_billing_agreement_id [String] @optional address_consent_token [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 161 def get_billing_agreement_details( amazon_billing_agreement_id, address_consent_token: nil, merchant_id: @merchant_id, mws_auth_token: nil) parameters = { 'Action' => 'GetBillingAgreementDetails', 'SellerId' => merchant_id, 'AmazonBillingAgreementId' => amazon_billing_agreement_id } optional = { 'AddressConsentToken' => address_consent_token, 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Returns the status of a particular capture and the total amount refunded on the capture @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetCaptureDetails.html @param amazon_capture_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 601 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
Returns details about the Order Reference object and its current state @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetOrderReferenceDetails.html @param amazon_order_reference_id [String] @optional address_consent_token [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 365 def get_order_reference_details( amazon_order_reference_id, address_consent_token: nil, merchant_id: @merchant_id, mws_auth_token: nil) parameters = { 'Action' => 'GetOrderReferenceDetails', 'SellerId' => merchant_id, 'AmazonOrderReferenceId' => amazon_order_reference_id } optional = { 'AddressConsentToken' => address_consent_token, 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
@param amazon_provider_credit_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 741 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
@param amazon_provider_credit_reversal_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 762 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
Returns the status of a particular refund @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetRefundDetails.html @param amazon_refund_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 666 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
The GetServiceStatus operation returns the operational status of the Amazon Payments API section of Amazon Marketplace Web Service (Amazon MWS). Status values are GREEN, GREEN_I, YELLOW, and RED. @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetServiceStatus.html
# File lib/pay_with_amazon/client.rb, line 94 def get_service_status parameters = { 'Action' => 'GetServiceStatus' } operation(parameters, {}) end
Refunds a previously captured amount @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_Refund.html @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/pay_with_amazon/client.rb, line 630 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
@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/pay_with_amazon/client.rb, line 787 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
Sets billing agreement details such as a description of the agreement and other information about the seller. @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_SetBillingAgreementDetails.html @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]
# File lib/pay_with_amazon/client.rb, line 192 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, 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, 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Sets order reference details such as the order total and a description for the order @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_SetOrderReferenceDetails.html @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 store_name [String] @optional custom_information [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 398 def set_order_reference_details( amazon_order_reference_id, amount, currency_code: @currency_code, platform_id: nil, seller_note: nil, seller_order_id: nil, store_name: nil, custom_information: 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.SellerNote' => seller_note, 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id, 'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name, 'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information, 'MWSAuthToken' => mws_auth_token } operation(parameters, optional) end
Validates the status of the BillingAgreement object and the payment method associated with it @see docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_ValidateBillingAgreement.html @param amazon_billing_agreement_id [String] @optional merchant_id
[String] @optional mws_auth_token [String]
# File lib/pay_with_amazon/client.rb, line 250 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
# File lib/pay_with_amazon/client_helper.rb, line 123 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) if response.success.eql?(false) return response end 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) return response end
# File lib/pay_with_amazon/client_helper.rb, line 72 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) return response else return response end else return response end end
# File lib/pay_with_amazon/client_helper.rb, line 187 def is_billing_agreement?(amazon_reference_id) amazon_reference_id.start_with?('C','B') end
# File lib/pay_with_amazon/client_helper.rb, line 183 def is_order_reference?(amazon_reference_id) amazon_reference_id.start_with?('S','P') end
# File lib/pay_with_amazon/client.rb, line 856 def operation(parameters, optional) PayWithAmazon::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).send_post end
# File lib/pay_with_amazon/client.rb, line 815 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
This method builds the provider credit details hash that will be combined with either the authorize or capture API call.
# File lib/pay_with_amazon/client.rb, line 829 def set_provider_credit_details(provider_credit_details) member_details = {} provider_credit_details.each_with_index { |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] } return member_details end
This method builds the provider credit reversal details hash that will be combined with the refund API call.
# File lib/pay_with_amazon/client.rb, line 844 def set_provider_credit_reversal_details(provider_credit_reversal_details) member_details = {} provider_credit_reversal_details.each_with_index { |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] } return member_details end