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

Unexpected element 'currency' when previewing purchase #866

Open
mphilips-copper opened this issue Oct 5, 2023 · 0 comments
Open

Unexpected element 'currency' when previewing purchase #866

mphilips-copper opened this issue Oct 5, 2023 · 0 comments
Labels

Comments

@mphilips-copper
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant