spreedly / spreedly-gem

A convenient Ruby wrapper for the Spreedly API.
MIT License
108 stars 86 forks source link

Don't parse nil payment method attributes as empty strings #93

Open jsanguinetticds opened 5 years ago

jsanguinetticds commented 5 years ago

This gem is parsing nil attributes as empty strings and this caused unexpected errors in our application. I'm worried the same might happen to yours. Either way, this can probably be fixed.

Responses from GET core.spreedly.com/v1/payment_methods/YBEtVpJvKWed2bkitmP0MFS7OOc.{format} using JSON and XML apis. Then using gem.

Notice how gem response is the only one not having nil values.

XML:

<payment_method>
  <token>YBEtVpJvKWed2bkitmP0MFS7OOc</token>
  <created_at type="dateTime">2019-08-06T17:41:41Z</created_at>
  <updated_at type="dateTime">2019-08-06T17:42:38Z</updated_at>
  <email nil="true"/>
  <data nil="true"/>
  <storage_state>retained</storage_state>
  <test type="boolean">true</test>
  <metadata nil="true"/>
  <callback_url nil="true"/>
  <last_four_digits>0005</last_four_digits>
  <first_six_digits>378282</first_six_digits>
  <card_type>american_express</card_type>
  <first_name>LUIS</first_name>
  <last_name>SUAREZ</last_name>
  <month type="integer">8</month>
  <year type="integer">2024</year>
  <address1 nil="true"/>
  <address2 nil="true"/>
  <city nil="true"/>
  <state nil="true"/>
  <zip>12345</zip>
  <country nil="true"/>
  <phone_number nil="true"/>
  <company nil="true"/>
  <full_name>LUIS SUAREZ</full_name>
  <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
  <shipping_address1 nil="true"/>
  <shipping_address2 nil="true"/>
  <shipping_city nil="true"/>
  <shipping_state nil="true"/>
  <shipping_zip nil="true"/>
  <shipping_country nil="true"/>
  <shipping_phone_number nil="true"/>
  <payment_method_type>credit_card</payment_method_type>
  <errors>
  </errors>
  <verification_value></verification_value>
  <number>XXXX-XXXX-XXXX-0005</number>
  <fingerprint>5430cba1b3ca00de0e5297e3291686d259f6</fingerprint>
</payment_method>

JSON

{
    "payment_method": {
        "token": "YBEtVpJvKWed2bkitmP0MFS7OOc",
        "created_at": "2019-08-06T17:41:41Z",
        "updated_at": "2019-08-06T17:42:38Z",
        "email": null,
        "data": null,
        "storage_state": "retained",
        "test": true,
        "metadata": null,
        "callback_url": null,
        "last_four_digits": "0005",
        "first_six_digits": "378282",
        "card_type": "american_express",
        "first_name": "LUIS",
        "last_name": "SUAREZ",
        "month": 8,
        "year": 2024,
        "address1": null,
        "address2": null,
        "city": null,
        "state": null,
        "zip": "12345",
        "country": null,
        "phone_number": null,
        "company": null,
        "full_name": "LUIS SUAREZ",
        "eligible_for_card_updater": true,
        "shipping_address1": null,
        "shipping_address2": null,
        "shipping_city": null,
        "shipping_state": null,
        "shipping_zip": null,
        "shipping_country": null,
        "shipping_phone_number": null,
        "payment_method_type": "credit_card",
        "errors": [],
        "fingerprint": "5430cba1b3ca00de0e5297e3291686d259f6",
        "verification_value": "",
        "number": "XXXX-XXXX-XXXX-0005"
    }
}

and gem:

[14] pry(main)> SPREEDLY.find_payment_method('YBEtVpJvKWed2bkitmP0MFS7OOc')
#<Spreedly::CreditCard:0x007f9655ddd158
 @address1="",
 @address2="",
 @card_type="american_express",
 @city="",
 @company="",
 @country="",
 @created_at="2019-08-06T17:41:41Z",
 @data="",
 @eligible_for_card_updater="true",
 @email="",
 @errors=[],
 @fingerprint="5430cba1b3ca00de0e5297e3291686d259f6",
 @first_name="LUIS",
 @first_six_digits="378282",
 @full_name="LUIS SUAREZ",
 @last_four_digits="0005",
 @last_name="SUAREZ",
 @month="8",
 @number="XXXX-XXXX-XXXX-0005",
 @phone_number="",
 @state="",
 @storage_state="retained",
 @token="YBEtVpJvKWed2bkitmP0MFS7OOc",
 @updated_at="2019-08-06T17:42:38Z",
 @verification_value="",
 @year="2024",