-
Notifications
You must be signed in to change notification settings - Fork 129
Description
Describe the bug
Recurly::Purchase.preview! fails with "The provided XML was invalid. 1:0: ERROR: Element 'currency': This element is not expected. (Recurly::API::BadRequest)" when I believe that I am passing in valid XML. It appears that Recurly::Purchase.preview! modifies the passed-in Recurly Subscription.
To Reproduce
Obtain a Recurly Account and a Recurly Subscription, use those objects to initialize a Recurly Purchase
irb(main):001:0> company = Company.find(16149);rec_acc = RecurlyAccessor.find_account(company.id);rec_sub = RecurlyAccessor.find_subscription(company.id)
=> #<Recurly::Subscription ...
irb(main):002:0> rec_pur = Recurly::Purchase.new({ account: rec_acc, subscriptions: [rec_sub] })
=> #<Recurly::Purchase collection_method: nil, coupon_codes: nil, currency: nil, customer_notes: nil, net_terms: nil, po_number: nil, shipping_address_id: nil, terms_and_conditions: nil, vat_reverse_charge_notes: nil>
Confirm that the Recurly Subscription does not indicate currency has changed (USD is my default currency)
irb(main):003:0> rec_sub.to_xml
=> "<subscription><plan_code>basic_monthly</plan_code></subscription>"
irb(main):004:0> rec_sub
=> #<Recurly::Subscription ..., currency: "USD", ...>
Attempt to preview the purchase and receive the error
irb(main):005:0> rec_pre = Recurly::Purchase.preview!(rec_pur)
Traceback (most recent call last):
/app/vendor/bundle/ruby/2.6.0/gems/recurly-2.15.4/lib/recurly/api/net_http_adapter.rb:101:in `request': The provided XML was invalid. 1:0: ERROR: Element 'currency': This element is not expected. (Recurly::API::BadRequest)
The Recurly Subscription now indicates currency has been changed
irb(main):006:0> rec_sub.to_xml
=> "<subscription><currency></currency><plan_code>basic_monthly</plan_code></subscription>"
irb(main):007:0> rec_sub
=> #<Recurly::Subscription ..., currency: nil, ...>
Expected behavior
I expected that the Recurly Subscription would be used as-is when converted to XML and passed into the Recurly API.
Extra notes
I believe the issue could be related to Recurly Purchase's overridden .to_xml which does seem to modify Subscription currency. Looks like this code was introduced with #339
Is there a higher version of the gem that addresses this issue for me?
Your Environment
- Which version of this library are you using? 2.15.4
- Which version of ruby are you using? 2.6.9