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

ARBTransactionList doesn't need to inherit from Array #182

Open
garciadanny opened this issue Dec 10, 2019 · 3 comments
Open

ARBTransactionList doesn't need to inherit from Array #182

garciadanny opened this issue Dec 10, 2019 · 3 comments

Comments

@garciadanny
Copy link

garciadanny commented Dec 10, 2019

Problem

When making an ARBGetSubscriptionRequest using the ruby client, an empty array [] is getting returned for a user's arbTransactions. Submitting this same exact request using CURL, however, we were able to confirm that there were in fact arbTransactions present in the response.

After further investigation, we learned that the ruby client wasn't returning an array literal but an ARBTransactionList instead that appeared to be an array literal [] because it inherits from Array. This caused a lot of confusion.

transactions = response.subscription.arbTransactions
=> []

transactions.arbTransaction

=> [#<AuthorizeNet::API::ArbTransaction:0x00007fc8984c00c8
    @attemptNum="1",
    @payNum="1",
.
.
.
]

It turns out this is because the auto-generated ARBTransactionList class in authorize_net/api/schema.rb unnecessarily inherits from Array.

  class ARBTransactionList < ::Array
    include ROXML
    xml_accessor :arbTransaction, as: [ArbTransaction]

    def initialize(arbTransaction = [])
      @arbTransaction = arbTransaction
    end
 end

A solution

Because this class essentially just defines getter and setter methods to ultimately retrieve a list of ArbTransaction objects, there doesn't seem to be any functionality from Array that ARBTransactionList needs. We've verified that this works without the inheritance. One possible solution we've identified is to simply remove the Array inheritance.

  class ARBTransactionList
    include ROXML
    xml_accessor :arbTransaction, as: [ArbTransaction]

    def initialize(arbTransaction = [])
      @arbTransaction = arbTransaction
    end
 end

We were going to submit a PR, but according to the Contributing docs, it seems that PRs can't be merged for response classes since they're auto-generated.

Is it possible to have this auto-generated code not inherit from Array or is there another more feasible solution you propose?

Thanks!

@lenny
Copy link

lenny commented Jan 13, 2020

I was also confused by this. I assumed that includeTransactions was not working as documented after seeing this:

irb(main):395:0* response.subscription.arbTransactions                                        
=> []

Easy to see how it could be confusing. Glad I stumbled on this and that it is workable if you know the secret.

@jberhang
Copy link

+1 for confusion factor. Please either fix the API to be more intuitive like above or update the documentation to be clear on its intended usage.

@nickgrahamfox
Copy link

+1 for confusion factor as well. I cannot get the transactions from the returned subscription object even though they are present in the response. Has anyone found a workaround for this that does not involve me editing the gem? Any alternative solutions? Thanks!

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

No branches or pull requests

4 participants