Skip to content

ARBTransactionList doesn't need to inherit from Array #182

Open
@garciadanny

Description

@garciadanny

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions