Sha256: 841a5545656bfe603bde64e3c36d8d7fd04ae244c6fa4854ce6069486efbfe5a

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module ChargeBee
  class Result

    def initialize(response)
      @response = response
    end
    
    def subscription() 
        get(:subscription, Subscription, 
        {:addons => Subscription::Addon, :coupons => Subscription::Coupon, :shipping_address => Subscription::ShippingAddress});
    end

    def customer() 
        get(:customer, Customer, 
        {:billing_address => Customer::BillingAddress});
    end

    def card() 
        get(:card, Card);
    end

    def invoice() 
        get(:invoice, Invoice, 
        {:line_items => Invoice::LineItem, :discounts => Invoice::Discount, :taxes => Invoice::Tax, :invoice_transactions => Invoice::LinkedTransaction});
    end

    def transaction() 
        get(:transaction, Transaction, 
        {:invoice_transactions => Transaction::LinkedInvoice});
    end

    def hosted_page() 
        get(:hosted_page, HostedPage);
    end

    def estimate() 
        get(:estimate, Estimate, 
        {:line_items => Estimate::LineItem, :discounts => Estimate::Discount, :taxes => Estimate::Tax});
    end

    def plan() 
        get(:plan, Plan);
    end

    def addon() 
        get(:addon, Addon);
    end

    def coupon() 
        get(:coupon, Coupon);
    end

    def coupon_code() 
        get(:coupon_code, CouponCode);
    end

    def address() 
        get(:address, Address);
    end

    def event() 
        get(:event, Event);
    end

    def comment() 
        get(:comment, Comment);
    end

    def download() 
        get(:download, Download);
    end


    def to_s(*args) 
      JSON.pretty_generate(@response) 
    end

    private
    def get(type, klass, sub_types = {})
      klass.construct(@response[type], sub_types)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chargebee-1.4.0 lib/chargebee/result.rb
chargebee-1.3.9 lib/chargebee/result.rb