`ARBTransactionList` doesn't need to inherit from Array
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!
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.
+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.
+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!