Skip to content

Instantly share code, notes, and snippets.

@jkthorne
Created February 21, 2021 18:15
Show Gist options
  • Save jkthorne/f7efd84b0cbd4eb1d2f1f32bfe249e2a to your computer and use it in GitHub Desktop.
Save jkthorne/f7efd84b0cbd4eb1d2f1f32bfe249e2a to your computer and use it in GitHub Desktop.
xmll bug
require "xml"
xml = XML.parse <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<transaction>
<id>fj6df5n1</id>
<status>submitted_for_settlement</status>
<type>sale</type>
<currency-iso-code>USD</currency-iso-code>
<amount>9363.36</amount>
<merchant-account-id>kilmercorp</merchant-account-id>
<sub-merchant-account-id nil="true"/>
<master-merchant-account-id nil="true"/>
<order-id nil="true"/>
<created-at type="datetime">2021-02-05T04:40:15Z</created-at>
<updated-at type="datetime">2021-02-05T04:40:16Z</updated-at>
<customer>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<email nil="true"/>
<website nil="true"/>
<phone nil="true"/>
<fax nil="true"/>
</customer>
<billing>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<street-address nil="true"/>
<extended-address nil="true"/>
<locality nil="true"/>
<region nil="true"/>
<postal-code nil="true"/>
<country-name nil="true"/>
<country-code-alpha2 nil="true"/>
<country-code-alpha3 nil="true"/>
<country-code-numeric nil="true"/>
</billing>
<refund-id nil="true"/>
<refund-ids type="array"/>
<refunded-transaction-id nil="true"/>
<partial-settlement-transaction-ids type="array"/>
<authorized-transaction-id nil="true"/>
<settlement-batch-id nil="true"/>
<shipping>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<street-address nil="true"/>
<extended-address nil="true"/>
<locality nil="true"/>
<region nil="true"/>
<postal-code nil="true"/>
<country-name nil="true"/>
<country-code-alpha2 nil="true"/>
<country-code-alpha3 nil="true"/>
<country-code-numeric nil="true"/>
</shipping>
<custom-fields/>
<avs-error-response-code nil="true"/>
<avs-postal-code-response-code>I</avs-postal-code-response-code>
<avs-street-address-response-code>I</avs-street-address-response-code>
<cvv-response-code>I</cvv-response-code>
<gateway-rejection-reason nil="true"/>
<processor-authorization-code>TVQFHG</processor-authorization-code>
<processor-response-code>1000</processor-response-code>
<processor-response-text>Approved</processor-response-text>
<additional-processor-response nil="true"/>
<voice-referral-number nil="true"/>
<purchase-order-number nil="true"/>
<tax-amount nil="true"/>
<tax-exempt type="boolean">false</tax-exempt>
<sca-exemption-requested nil="true"/>
<processed-with-network-token type="boolean">false</processed-with-network-token>
<credit-card>
<token nil="true"/>
<bin>402389</bin>
<last-4>8028</last-4>
<card-type>Visa</card-type>
<expiration-month>03</expiration-month>
<expiration-year>2022</expiration-year>
<customer-location>US</customer-location>
<cardholder-name nil="true"/>
<image-url>https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox</image-url>
<prepaid>Unknown</prepaid>
<healthcare>Unknown</healthcare>
<debit>Unknown</debit>
<durbin-regulated>Unknown</durbin-regulated>
<commercial>Unknown</commercial>
<payroll>Unknown</payroll>
<issuing-bank>Unknown</issuing-bank>
<country-of-issuance>Unknown</country-of-issuance>
<product-id>Unknown</product-id>
<global-id nil="true"/>
<account-type nil="true"/>
<unique-number-identifier nil="true"/>
<venmo-sdk type="boolean">false</venmo-sdk>
</credit-card>
<status-history type="array">
<status-event>
<timestamp type="datetime">2021-02-05T04:40:15Z</timestamp>
<status>authorized</status>
<amount>9363.36</amount>
<user>jkthorne</user>
<transaction-source>api</transaction-source>
</status-event>
<status-event>
<timestamp type="datetime">2021-02-05T04:40:15Z</timestamp>
<status>submitted_for_settlement</status>
<amount>9363.36</amount>
<user>jkthorne</user>
<transaction-source>api</transaction-source>
</status-event>
</status-history>
<plan-id nil="true"/>
<subscription-id nil="true"/>
<subscription>
<billing-period-end-date nil="true"/>
<billing-period-start-date nil="true"/>
</subscription>
<add-ons type="array"/>
<discounts type="array"/>
<descriptor>
<name nil="true"/>
<phone nil="true"/>
<url nil="true"/>
</descriptor>
<recurring type="boolean">false</recurring>
<channel nil="true"/>
<service-fee-amount nil="true"/>
<escrow-status nil="true"/>
<disbursement-details>
<disbursement-date nil="true"/>
<settlement-amount nil="true"/>
<settlement-currency-iso-code nil="true"/>
<settlement-currency-exchange-rate nil="true"/>
<funds-held nil="true"/>
<success nil="true"/>
</disbursement-details>
<disputes type="array">
<dispute>
<id>dpp74szzb5srtw4d</id>
<global-id>ZGlzcHV0ZV9kcHA3NHN6emI1c3J0dzRk</global-id>
<amount>9363.36</amount>
<amount-disputed>9363.36</amount-disputed>
<amount-won>0.00</amount-won>
<case-number>CB328430743124</case-number>
<created-at type="datetime">2021-02-05T04:40:16Z</created-at>
<currency-iso-code>USD</currency-iso-code>
<date-opened type="date">2021-02-05</date-opened>
<date-won nil="true"/>
<processor-comments nil="true"/>
<kind>chargeback</kind>
<merchant-account-id>kilmercorp</merchant-account-id>
<reason>fraud</reason>
<reason-code>62</reason-code>
<reason-description nil="true"/>
<received-date type="date">2021-02-05</received-date>
<reference-number nil="true"/>
<reply-by-date type="date">2021-02-10</reply-by-date>
<processor-reply-by-date type="date">2021-02-14</processor-reply-by-date>
<response-deadline type="datetime">2021-02-09T05:59:59Z</response-deadline>
<status>open</status>
<updated-at type="datetime">2021-02-05T04:40:16Z</updated-at>
<original-dispute-id nil="true"/>
<evidence type="array"/>
<status-history type="array">
<status-history>
<disbursement-date type="date">2021-02-05</disbursement-date>
<effective-date type="date">2021-02-05</effective-date>
<status>open</status>
<timestamp type="datetime">2021-02-05T04:40:16Z</timestamp>
</status-history>
</status-history>
<transaction>
<id>fj6df5n1</id>
<global-id>dHJhbnNhY3Rpb25fZmo2ZGY1bjE</global-id>
<amount>9363.36</amount>
<created-at>2021-02-05T04:40:15Z</created-at>
<installment-count nil="true"/>
<order-id nil="true"/>
<purchase-order-number nil="true"/>
<payment-instrument-subtype>Visa</payment-instrument-subtype>
</transaction>
</dispute>
</disputes>
<authorization-adjustments type="array"/>
<payment-instrument-type>credit_card</payment-instrument-type>
<processor-settlement-response-code></processor-settlement-response-code>
<processor-settlement-response-text></processor-settlement-response-text>
<network-response-code>XX</network-response-code>
<network-response-text>sample network response text</network-response-text>
<three-d-secure-info nil="true"/>
<ships-from-postal-code nil="true"/>
<shipping-amount nil="true"/>
<discount-amount nil="true"/>
<network-transaction-id>020210205044015</network-transaction-id>
<processor-response-type>approved</processor-response-type>
<authorization-expires-at type="datetime">2021-02-12T04:40:15Z</authorization-expires-at>
<retry-ids type="array"/>
<retried-transaction-id nil="true"/>
<refund-global-ids type="array"/>
<partial-settlement-transaction-global-ids type="array"/>
<refunded-transaction-global-id nil="true"/>
<authorized-transaction-global-id nil="true"/>
<global-id>dHJhbnNhY3Rpb25fZmo2ZGY1bjE</global-id>
<retry-global-ids type="array"/>
<retried-transaction-global-id nil="true"/>
<retrieval-reference-number>1234567</retrieval-reference-number>
<installment-count nil="true"/>
<installments type="array"/>
<refunded-installments type="array"/>
<response-emv-data nil="true"/>
<acquirer-reference-number nil="true"/>
<merchant-identification-number>123456789012</merchant-identification-number>
<terminal-identification-number>00000001</terminal-identification-number>
<merchant-name>DESCRIPTORNAME</merchant-name>
<merchant-address>
<street-address></street-address>
<locality>Braintree</locality>
<region>MA</region>
<postal-code>02184</postal-code>
<phone>5555555555</phone>
</merchant-address>
<pin-verified type="boolean">false</pin-verified>
</transaction>
XML
xml = xml.xpath_node("transaction").not_nil!
x = xml.xpath_string("string(id[text()])")
x = xml.xpath_string("string(status[text()])")
x = xml.xpath_string("string(type[text()])")
x = xml.xpath_string("string(currency-iso-code[text()])")
x = xml.xpath_string("string(amount[text()])")
x = xml.xpath_string("string(merchant-account-id[text()])")
x = xml.xpath_string("string(sub_merchant-account-id[text()])")
x = xml.xpath_string("string(master_merchant-account-id[text()])")
x = xml.xpath_string("string(order-id[text()])")
x= Time.parse_iso8601 xml.xpath_string("string(created-at[text()])")
x= Time.parse_iso8601 xml.xpath_string("string(updated-at[text()])")
x = xml.xpath_string("string(refund-id[text()])")
x = xml.xpath_string("string(refund-ids[text()])")
x = xml.xpath_string("string(refund-transaction-id[text()])")
x = xml.xpath_string("string(authorized-transaction-id[text()])")
x = xml.xpath_string("string(settlement-batch-id[text()])")
x = xml.xpath_string("string(avs-error-response-code[text()])")
x = xml.xpath_string("string(avs-postal-code-response-code[text()])")
x = xml.xpath_string("string(avs-street-address-response-code[text()])")
x = xml.xpath_string("string(cvv-response-code[text()])")
x = xml.xpath_string("string(gateway-rejection-reason[text()])")
x = xml.xpath_string("string(processor-authorization-code[text()])")
x = xml.xpath_string("string(processor-response-code[text()])").to_i
x = xml.xpath_string("string(processor-response-text[text()])")
x = xml.xpath_string("string(additional-processor-response[text()])")
x = xml.xpath_string("string(voice-referral-number[text()])")
x = xml.xpath_string("string(purchase_order-number[text()])")
x = xml.xpath_string("string(tax-amount[text()])")
x = xml.xpath_bool("boolean(tax-exempt[text()])")
x = xml.xpath_string("string(sca-exemption-requested[text()])")
x = xml.xpath_bool("boolean(processed-with-network-token[text()])")
x = xml.xpath_string("string(plan-id[text()])")
x = xml.xpath_string("string(subscription-id[text()])")
x = xml.xpath_bool("boolean(recurring[text()])")
x = xml.xpath_string("string(channel[text()])")
x = xml.xpath_string("string(service-fee-amount[text()])")
x = xml.xpath_string("string(escrow_status[text()])")
x = xml.xpath_string("string(payment-instrument-type[text()])")
x = xml.xpath_string("string(processor-settlement-response-code[text()])")
x = xml.xpath_string("string(processor-settlement-response-text[text()])")
x = xml.xpath_string("string(network-response-code[text()])")
x = xml.xpath_string("string(network-response-text[text()])")
x = xml.xpath_string("string(three-d-secure-info[text()])")
x = xml.xpath_string("string(ships-from-postal-code[text()])")
x = xml.xpath_string("string(shipping-amount[text()])")
x = xml.xpath_string("string(discount-amount[text()])")
x = xml.xpath_string("string(network-transaction-id[text()])")
x = xml.xpath_string("string(processor-response-type[text()])")
x= Time.parse_iso8601 xml.xpath_string("string(authorization-expires-at[text()])")
x = xml.xpath_string("string(retried-transaction-id[text()])")
x = xml.xpath_string("string(refunded-transaction-global-id[text()])")
x = xml.xpath_string("string(authorized-transaction-global-id[text()])")
x = xml.xpath_string("string(global-id[text()])")
x = xml.xpath_string("string(retried-transaction-global-id[text()])")
x = xml.xpath_string("string(retrieval-reference-number[text()])")
x = xml.xpath_string("string(installment-count[text()])")
x = xml.xpath_string("string(response-emv-data[text()])")
x = xml.xpath_string("string(acquirer-reference-number[text()])")
x = xml.xpath_string("string(merchant-identification-number[text()])")
x = xml.xpath_string("string(terminal-identification-number[text()])")
x = xml.xpath_string("string(merchant-name[text()])")
xml.xpath_nodes("disputes//dispute").try &.each do |child|
puts child
end
puts xml
require "xml"
xml = XML.parse <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<transaction>
<id>fj6df5n1</id>
<status>submitted_for_settlement</status>
<type>sale</type>
<currency-iso-code>USD</currency-iso-code>
<amount>9363.36</amount>
<merchant-account-id>kilmercorp</merchant-account-id>
<sub-merchant-account-id nil="true"/>
<master-merchant-account-id nil="true"/>
<order-id nil="true"/>
<created-at type="datetime">2021-02-05T04:40:15Z</created-at>
<updated-at type="datetime">2021-02-05T04:40:16Z</updated-at>
<customer>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<email nil="true"/>
<website nil="true"/>
<phone nil="true"/>
<fax nil="true"/>
</customer>
<billing>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<street-address nil="true"/>
<extended-address nil="true"/>
<locality nil="true"/>
<region nil="true"/>
<postal-code nil="true"/>
<country-name nil="true"/>
<country-code-alpha2 nil="true"/>
<country-code-alpha3 nil="true"/>
<country-code-numeric nil="true"/>
</billing>
<refund-id nil="true"/>
<refund-ids type="array"/>
<refunded-transaction-id nil="true"/>
<partial-settlement-transaction-ids type="array"/>
<authorized-transaction-id nil="true"/>
<settlement-batch-id nil="true"/>
<shipping>
<id nil="true"/>
<first-name nil="true"/>
<last-name nil="true"/>
<company nil="true"/>
<street-address nil="true"/>
<extended-address nil="true"/>
<locality nil="true"/>
<region nil="true"/>
<postal-code nil="true"/>
<country-name nil="true"/>
<country-code-alpha2 nil="true"/>
<country-code-alpha3 nil="true"/>
<country-code-numeric nil="true"/>
</shipping>
<custom-fields/>
<avs-error-response-code nil="true"/>
<avs-postal-code-response-code>I</avs-postal-code-response-code>
<avs-street-address-response-code>I</avs-street-address-response-code>
<cvv-response-code>I</cvv-response-code>
<gateway-rejection-reason nil="true"/>
<processor-authorization-code>TVQFHG</processor-authorization-code>
<processor-response-code>1000</processor-response-code>
<processor-response-text>Approved</processor-response-text>
<additional-processor-response nil="true"/>
<voice-referral-number nil="true"/>
<purchase-order-number nil="true"/>
<tax-amount nil="true"/>
<tax-exempt type="boolean">false</tax-exempt>
<sca-exemption-requested nil="true"/>
<processed-with-network-token type="boolean">false</processed-with-network-token>
<credit-card>
<token nil="true"/>
<bin>402389</bin>
<last-4>8028</last-4>
<card-type>Visa</card-type>
<expiration-month>03</expiration-month>
<expiration-year>2022</expiration-year>
<customer-location>US</customer-location>
<cardholder-name nil="true"/>
<image-url>https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox</image-url>
<prepaid>Unknown</prepaid>
<healthcare>Unknown</healthcare>
<debit>Unknown</debit>
<durbin-regulated>Unknown</durbin-regulated>
<commercial>Unknown</commercial>
<payroll>Unknown</payroll>
<issuing-bank>Unknown</issuing-bank>
<country-of-issuance>Unknown</country-of-issuance>
<product-id>Unknown</product-id>
<global-id nil="true"/>
<account-type nil="true"/>
<unique-number-identifier nil="true"/>
<venmo-sdk type="boolean">false</venmo-sdk>
</credit-card>
<status-history type="array">
<status-event>
<timestamp type="datetime">2021-02-05T04:40:15Z</timestamp>
<status>authorized</status>
<amount>9363.36</amount>
<user>jkthorne</user>
<transaction-source>api</transaction-source>
</status-event>
<status-event>
<timestamp type="datetime">2021-02-05T04:40:15Z</timestamp>
<status>submitted_for_settlement</status>
<amount>9363.36</amount>
<user>jkthorne</user>
<transaction-source>api</transaction-source>
</status-event>
</status-history>
<plan-id nil="true"/>
<subscription-id nil="true"/>
<subscription>
<billing-period-end-date nil="true"/>
<billing-period-start-date nil="true"/>
</subscription>
<add-ons type="array"/>
<discounts type="array"/>
<descriptor>
<name nil="true"/>
<phone nil="true"/>
<url nil="true"/>
</descriptor>
<recurring type="boolean">false</recurring>
<channel nil="true"/>
<service-fee-amount nil="true"/>
<escrow-status nil="true"/>
<disbursement-details>
<disbursement-date nil="true"/>
<settlement-amount nil="true"/>
<settlement-currency-iso-code nil="true"/>
<settlement-currency-exchange-rate nil="true"/>
<funds-held nil="true"/>
<success nil="true"/>
</disbursement-details>
<disputes type="array">
<dispute>
<id>dpp74szzb5srtw4d</id>
<global-id>ZGlzcHV0ZV9kcHA3NHN6emI1c3J0dzRk</global-id>
<amount>9363.36</amount>
<amount-disputed>9363.36</amount-disputed>
<amount-won>0.00</amount-won>
<case-number>CB328430743124</case-number>
<created-at type="datetime">2021-02-05T04:40:16Z</created-at>
<currency-iso-code>USD</currency-iso-code>
<date-opened type="date">2021-02-05</date-opened>
<date-won nil="true"/>
<processor-comments nil="true"/>
<kind>chargeback</kind>
<merchant-account-id>kilmercorp</merchant-account-id>
<reason>fraud</reason>
<reason-code>62</reason-code>
<reason-description nil="true"/>
<received-date type="date">2021-02-05</received-date>
<reference-number nil="true"/>
<reply-by-date type="date">2021-02-10</reply-by-date>
<processor-reply-by-date type="date">2021-02-14</processor-reply-by-date>
<response-deadline type="datetime">2021-02-09T05:59:59Z</response-deadline>
<status>open</status>
<updated-at type="datetime">2021-02-05T04:40:16Z</updated-at>
<original-dispute-id nil="true"/>
<evidence type="array"/>
<status-history type="array">
<status-history>
<disbursement-date type="date">2021-02-05</disbursement-date>
<effective-date type="date">2021-02-05</effective-date>
<status>open</status>
<timestamp type="datetime">2021-02-05T04:40:16Z</timestamp>
</status-history>
</status-history>
<transaction>
<id>fj6df5n1</id>
<global-id>dHJhbnNhY3Rpb25fZmo2ZGY1bjE</global-id>
<amount>9363.36</amount>
<created-at>2021-02-05T04:40:15Z</created-at>
<installment-count nil="true"/>
<order-id nil="true"/>
<purchase-order-number nil="true"/>
<payment-instrument-subtype>Visa</payment-instrument-subtype>
</transaction>
</dispute>
</disputes>
<authorization-adjustments type="array"/>
<payment-instrument-type>credit_card</payment-instrument-type>
<processor-settlement-response-code></processor-settlement-response-code>
<processor-settlement-response-text></processor-settlement-response-text>
<network-response-code>XX</network-response-code>
<network-response-text>sample network response text</network-response-text>
<three-d-secure-info nil="true"/>
<ships-from-postal-code nil="true"/>
<shipping-amount nil="true"/>
<discount-amount nil="true"/>
<network-transaction-id>020210205044015</network-transaction-id>
<processor-response-type>approved</processor-response-type>
<authorization-expires-at type="datetime">2021-02-12T04:40:15Z</authorization-expires-at>
<retry-ids type="array"/>
<retried-transaction-id nil="true"/>
<refund-global-ids type="array"/>
<partial-settlement-transaction-global-ids type="array"/>
<refunded-transaction-global-id nil="true"/>
<authorized-transaction-global-id nil="true"/>
<global-id>dHJhbnNhY3Rpb25fZmo2ZGY1bjE</global-id>
<retry-global-ids type="array"/>
<retried-transaction-global-id nil="true"/>
<retrieval-reference-number>1234567</retrieval-reference-number>
<installment-count nil="true"/>
<installments type="array"/>
<refunded-installments type="array"/>
<response-emv-data nil="true"/>
<acquirer-reference-number nil="true"/>
<merchant-identification-number>123456789012</merchant-identification-number>
<terminal-identification-number>00000001</terminal-identification-number>
<merchant-name>DESCRIPTORNAME</merchant-name>
<merchant-address>
<street-address></street-address>
<locality>Braintree</locality>
<region>MA</region>
<postal-code>02184</postal-code>
<phone>5555555555</phone>
</merchant-address>
<pin-verified type="boolean">false</pin-verified>
</transaction>
XML
xml = xml.xpath_node("transaction").not_nil!
x = xml.xpath_string("string(id[text()])")
xml.xpath_nodes("disputes//dispute").try &.each do |child|
puts child
end
puts xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment