Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AmazonPay::Response#get_element error #11

Open
rikaimind-BuiMinhThu opened this issue Jul 13, 2017 · 0 comments
Open

AmazonPay::Response#get_element error #11

rikaimind-BuiMinhThu opened this issue Jul 13, 2017 · 0 comments

Comments

@rikaimind-BuiMinhThu
Copy link

rikaimind-BuiMinhThu commented Jul 13, 2017

Problem

Source code of method AmazonPay::Response#get_element is:

def get_element(xpath, xml_element)
  xml = self.to_xml
  xml.elements.each(xpath) do |element|
    @value = element.elements[xml_element].text
  end
  return @value
end

Above source code will run wrong in below case:

GetOrderReferenceDetails response:

<GetOrderReferenceDetailsResponse xmlns="http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01">
  <GetOrderReferenceDetailsResult>
    <OrderReferenceDetails>
      <OrderReferenceStatus>
        <LastUpdateTimestamp>2017-07-13T04:56:08.046Z</LastUpdateTimestamp>
        <State>Open</State>
      </OrderReferenceStatus>
      <Destination>
        <DestinationType>Physical</DestinationType>
        <PhysicalDestination>
          <StateOrRegion>Tokyo</StateOrRegion>
          <City>Ota-ku</City>
          <Phone>09056412829</Phone>
          <CountryCode>JP</CountryCode>
          <PostalCode>0600001</PostalCode>
          <Name>JP APA test test1</Name>
          <AddressLine1>1-17-25 Shinkamata</AddressLine1>
        </PhysicalDestination>
      </Destination>
      <ExpirationTimestamp>2018-01-09T04:55:21.829Z</ExpirationTimestamp>
      <PlatformId>A3QCQLYZKBHFRS</PlatformId>
      <IdList>
        <member>S03-4685906-3575244-A052252</member>
      </IdList>
      <SellerOrderAttributes>
        <StoreName>default name</StoreName>
        <SellerOrderId>ON-170713015605-000-000006</SellerOrderId>
      </SellerOrderAttributes>
      <OrderTotal>
        <CurrencyCode>JPY</CurrencyCode>
        <Amount>1939.00</Amount>
      </OrderTotal>
      <Buyer>
        <Name>TEST NAME</Name>
        <Email>[email protected]</Email>
      </Buyer>
      <ReleaseEnvironment>Sandbox</ReleaseEnvironment>
      <AmazonOrderReferenceId>S03-4685906-3575244</AmazonOrderReferenceId>
      <CreationTimestamp>2017-07-13T04:55:21.829Z</CreationTimestamp>
      <RequestPaymentAuthorization>false</RequestPaymentAuthorization>
    </OrderReferenceDetails>
  </GetOrderReferenceDetailsResult>
  <ResponseMetadata>
    <RequestId>6a46dc4d-8892-495f-80d1-bfe7ae1b95ba</RequestId>
  </ResponseMetadata>
</GetOrderReferenceDetailsResponse>

Above response does not contain constrains element.
But when call:

GET_ORDER_REFERENCE_STATUS_XPATH = "GetOrderReferenceDetailsResponse/GetOrderReferenceDetailsResult/OrderReferenceDetails/OrderReferenceStatus"
GET_ORDER_REFERENCE_CONSTRAINTS_XPATH = "GetOrderReferenceDetailsResponse/GetOrderReferenceDetailsResult/OrderReferenceDetails/Constraints/Constraint"

CONSTRAINT_ID_ELEMENT = "ConstraintID"
STATE_ELEMENT = "State"


status = response.get_element(GET_ORDER_REFERENCE_STATUS_XPATH, STATE_ELEMENT)

→ "Open"

constraint_id = response.get_element(GET_ORDER_REFERENCE_CONSTRAINTS_XPATH, CONSTRAINT_ID_ELEMENT)
→ "Open"

In above case, we expect constraint_id is nil, but its value still is Open.

Fixed

I was fixed it and sent pull request.

#12

Please check it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant