Class: AdvancedBilling::BaseModel

Inherits:
CoreLibrary::BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/base_model.rb

Overview

Base model.

Direct Known Subclasses

ACHAgreement, AccountBalance, AccountBalances, ActivateEventBasedComponent, ActivateSubscriptionRequest, AddCouponsRequest, AddSubscriptionToAGroup, AddressChange, AgreementAcceptance, AllocateComponents, Allocation, AllocationExpirationDate, AllocationPreview, AllocationPreviewItem, AllocationPreviewLineItem, AllocationPreviewResponse, AllocationResponse, AllocationSettings, ApplePayPaymentProfile, AppliedCreditNoteData, ApplyCreditNoteEvent, ApplyCreditNoteEventData, ApplyDebitNoteEvent, ApplyDebitNoteEventData, ApplyPaymentEvent, ApplyPaymentEventData, AttributeError, AutoResume, BackportInvoiceEvent, BankAccountAttributes, BankAccountPaymentProfile, BankAccountResponse, BankAccountVerification, BankAccountVerificationRequest, BaseRefundError, BaseStringError, BatchJob, BatchJobResponse, BillingManifest, BillingManifestItem, BillingSchedule, Breakouts, BulkComponentsPricePointAssignment, BulkCreateProductPricePointsRequest, BulkCreateProductPricePointsResponse, BulkCreateSegments, BulkUpdateSegments, BulkUpdateSegmentsItem, CalendarBilling, CancelGroupedSubscriptionsRequest, CancellationOptions, CancellationRequest, ChangeChargebackStatusEvent, ChangeChargebackStatusEventData, ChangeInvoiceCollectionMethodEvent, ChangeInvoiceCollectionMethodEventData, ChangeInvoiceStatusEvent, ChangeInvoiceStatusEventData, ChargifyEBB, Component, ComponentAllocationChange, ComponentAllocationErrorItem, ComponentCostData, ComponentCostDataRateTier, ComponentCurrencyPrice, ComponentCurrencyPricesResponse, ComponentCustomPrice, ComponentPrice, ComponentPricePoint, ComponentPricePointAssignment, ComponentPricePointErrorItem, ComponentPricePointItem, ComponentPricePointResponse, ComponentPricePointsResponse, ComponentResponse, ConsolidatedInvoice, CountResponse, Coupon, CouponCurrency, CouponCurrencyRequest, CouponCurrencyResponse, CouponResponse, CouponRestriction, CouponSubcodes, CouponSubcodesResponse, CouponUsage, CreateAllocation, CreateAllocationRequest, CreateComponentPricePoint, CreateComponentPricePointRequest, CreateComponentPricePointsRequest, CreateCreditNoteEvent, CreateCurrencyPrice, CreateCurrencyPricesRequest, CreateCustomer, CreateCustomerRequest, CreateDebitNoteEvent, CreateEBBComponent, CreateInvoice, CreateInvoiceAddress, CreateInvoiceCoupon, CreateInvoiceItem, CreateInvoicePayment, CreateInvoicePaymentApplication, CreateInvoicePaymentRequest, CreateInvoiceRequest, CreateMetadata, CreateMetadataRequest, CreateMetafield, CreateMetafieldsRequest, CreateMeteredComponent, CreateMultiInvoicePayment, CreateMultiInvoicePaymentRequest, CreateOffer, CreateOfferComponent, CreateOfferRequest, CreateOnOffComponent, CreateOrUpdateCoupon, CreateOrUpdateEndpoint, CreateOrUpdateEndpointRequest, CreateOrUpdateFlatAmountCoupon, CreateOrUpdatePercentageCoupon, CreateOrUpdateProduct, CreateOrUpdateProductRequest, CreateOrUpdateSegmentPrice, CreatePayment, CreatePaymentProfile, CreatePaymentProfileRequest, CreatePrepaidComponent, CreatePrepaidUsageComponentPricePoint, CreatePrepayment, CreatePrepaymentRequest, CreatePrepaymentResponse, CreateProductCurrencyPrice, CreateProductCurrencyPricesRequest, CreateProductFamily, CreateProductFamilyRequest, CreateProductPricePoint, CreateProductPricePointRequest, CreateQuantityBasedComponent, CreateReasonCode, CreateReasonCodeRequest, CreateSegment, CreateSegmentRequest, CreateSubscription, CreateSubscriptionComponent, CreateSubscriptionGroup, CreateSubscriptionGroupRequest, CreateSubscriptionRequest, CreateUsage, CreateUsageRequest, CreatedPrepayment, CreditAccountBalanceChanged, CreditCardAttributes, CreditCardPaymentProfile, CreditNote, CreditNoteApplication, CreditNoteLineItem, CreditSchemeRequest, CurrencyPrice, CurrencyPricesResponse, CustomFieldValueChange, Customer, CustomerAttributes, CustomerChange, CustomerChangesPreviewResponse, CustomerCustomFieldsChange, CustomerError, CustomerPayerChange, CustomerResponse, DebitNote, DeductServiceCredit, DeductServiceCreditRequest, DelayedCancellationResponse, DeleteSubscriptionGroupResponse, DunnerData, DunningStepData, DunningStepReached, EBBComponent, EBBEvent, EnableWebhooksRequest, EnableWebhooksResponse, Endpoint, EndpointResponse, Errors, Event, EventBasedBillingSegmentError, EventResponse, FailedPaymentEvent, FailedPaymentEventData, FullSubscriptionGroupResponse, GetOneTimeTokenPaymentProfile, GetOneTimeTokenRequest, GroupBilling, GroupSettings, GroupTarget, HistoricUsage, Invoice, InvoiceAddress, InvoiceBalanceItem, InvoiceCredit, InvoiceCustomField, InvoiceCustomer, InvoiceDiscount, InvoiceDiscountBreakout, InvoiceDisplaySettings, InvoiceIssued, InvoiceLineItem, InvoiceLineItemComponentCostData, InvoiceLineItemEventData, InvoiceLineItemPricingDetail, InvoicePayer, InvoicePayerChange, InvoicePayment, InvoicePaymentApplication, InvoicePaymentMethod, InvoicePrePayment, InvoicePreviousBalance, InvoiceRefund, InvoiceResponse, InvoiceSeller, InvoiceTax, InvoiceTaxBreakout, InvoiceTaxComponentBreakout, IssueAdvanceInvoiceRequest, IssueInvoiceEvent, IssueInvoiceEventData, IssueInvoiceRequest, IssueServiceCredit, IssueServiceCreditRequest, ItemPricePointChanged, ItemPricePointData, ListComponentsFilter, ListComponentsPricePointsResponse, ListCouponsFilter, ListCreditNotesResponse, ListInvoiceEventsResponse, ListInvoicesResponse, ListMRRResponse, ListMRRResponseResult, ListMetafieldsResponse, ListMrrFilter, ListOffersResponse, ListPrepaymentsFilter, ListPricePointsFilter, ListProductPricePointsResponse, ListProductsFilter, ListProformaInvoicesMeta, ListProformaInvoicesResponse, ListPublicKeysMeta, ListPublicKeysResponse, ListSaleRepItem, ListSegmentsFilter, ListSegmentsResponse, ListSubcriptionGroupPrepaymentItem, ListSubscriptionComponentsFilter, ListSubscriptionComponentsForSiteFilter, ListSubscriptionComponentsResponse, ListSubscriptionGroupPrepayment, ListSubscriptionGroupPrepaymentResponse, ListSubscriptionGroupsItem, ListSubscriptionGroupsMeta, ListSubscriptionGroupsResponse, MRR, MRRMovement, MRRResponse, Metadata, Metafield, MetafieldScope, MeteredComponent, MeteredUsage, Movement, MovementLineItem, MultiInvoicePayment, MultiInvoicePaymentResponse, NestedSubscriptionGroup, NetTerms, Offer, OfferDiscount, OfferItem, OfferResponse, OfferSignupPage, OnOffComponent, OrganizationAddress, OriginInvoice, OveragePricing, OverrideSubscription, OverrideSubscriptionRequest, PaginatedMetadata, PaidInvoice, PauseRequest, PayerAttributes, PayerError, PaymentCollectionMethodChanged, PaymentForAllocation, PaymentMethodApplePay, PaymentMethodBankAccount, PaymentMethodCreditCard, PaymentMethodExternal, PaymentMethodPaypal, PaymentProfileAttributes, PaymentProfileResponse, PaymentRelatedEvents, PaypalPaymentProfile, PendingCancellationChange, PortalManagementLink, PrepaidComponentPricePoint, PrepaidConfiguration, PrepaidConfigurationResponse, PrepaidProductPricePointFilter, PrepaidSubscriptionBalanceChanged, PrepaidUsage, PrepaidUsageAllocationDetail, PrepaidUsageComponent, Prepayment, PrepaymentAccountBalanceChanged, PrepaymentResponse, PrepaymentsResponse, PreviewAllocationsRequest, Price, Product, ProductFamily, ProductFamilyResponse, ProductPricePoint, ProductPricePointErrors, ProductPricePointResponse, ProductResponse, ProformaError, ProformaInvoice, ProformaInvoiceCredit, ProformaInvoiceDiscount, ProformaInvoiceIssued, ProformaInvoicePayment, ProformaInvoiceTax, Proration, PublicKey, PublicSignupPage, QuantityBasedComponent, ReactivateSubscriptionGroupRequest, ReactivateSubscriptionGroupResponse, ReactivateSubscriptionRequest, ReactivationBilling, ReasonCode, ReasonCodeResponse, ReasonCodesJsonResponse, RecordPaymentRequest, RecordPaymentResponse, ReferralCode, ReferralValidationResponse, RefundConsolidatedInvoice, RefundInvoice, RefundInvoiceEvent, RefundInvoiceEventData, RefundInvoiceRequest, RefundPrepayment, RefundPrepaymentBaseRefundError, RefundPrepaymentRequest, RefundSuccess, RemovePaymentEvent, RemovePaymentEventData, RenewalPreview, RenewalPreviewComponent, RenewalPreviewLineItem, RenewalPreviewRequest, RenewalPreviewResponse, ReplayWebhooksRequest, ReplayWebhooksResponse, ResentInvitation, ResumeOptions, RevokedInvitation, SaleRep, SaleRepItemMrr, SaleRepSettings, SaleRepSubscription, Segment, SegmentPrice, SegmentResponse, SendInvoiceRequest, ServiceCredit, ServiceCreditResponse, SignupProformaPreview, SignupProformaPreviewResponse, Site, SiteResponse, SiteStatistics, SiteSummary, Subscription, SubscriptionComponent, SubscriptionComponentAllocationErrorItem, SubscriptionComponentResponse, SubscriptionComponentSubscription, SubscriptionCustomPrice, SubscriptionFilter, SubscriptionGroup, SubscriptionGroupBalances, SubscriptionGroupBankAccount, SubscriptionGroupComponentCustomPrice, SubscriptionGroupCreditCard, SubscriptionGroupCustomer, SubscriptionGroupItem, SubscriptionGroupMemberError, SubscriptionGroupMembersArrayError, SubscriptionGroupPaymentProfile, SubscriptionGroupPrepayment, SubscriptionGroupPrepaymentRequest, SubscriptionGroupPrepaymentResponse, SubscriptionGroupResponse, SubscriptionGroupSignup, SubscriptionGroupSignupComponent, SubscriptionGroupSignupError, SubscriptionGroupSignupFailure, SubscriptionGroupSignupFailureData, SubscriptionGroupSignupItem, SubscriptionGroupSignupRequest, SubscriptionGroupSignupResponse, SubscriptionGroupSignupSuccess, SubscriptionGroupSignupSuccessData, SubscriptionGroupSingleError, SubscriptionGroupSubscriptionError, SubscriptionGroupUpdateError, SubscriptionIncludedCoupon, SubscriptionMRR, SubscriptionMRRBreakout, SubscriptionMRRResponse, SubscriptionMigrationPreview, SubscriptionMigrationPreviewOptions, SubscriptionMigrationPreviewRequest, SubscriptionMigrationPreviewResponse, SubscriptionNote, SubscriptionNoteResponse, SubscriptionPreview, SubscriptionPreviewResponse, SubscriptionProductChange, SubscriptionProductMigration, SubscriptionProductMigrationRequest, SubscriptionResponse, SubscriptionStateChange, TaxConfiguration, TooManyManagementLinkRequests, UpdateAllocationExpirationDate, UpdateComponent, UpdateComponentPricePoint, UpdateComponentPricePointRequest, UpdateComponentRequest, UpdateCouponCurrency, UpdateCurrencyPrice, UpdateCurrencyPricesRequest, UpdateCustomer, UpdateCustomerRequest, UpdateMetadata, UpdateMetadataRequest, UpdateMetafield, UpdateMetafieldsRequest, UpdatePaymentProfile, UpdatePaymentProfileRequest, UpdatePrice, UpdateProductPricePoint, UpdateProductPricePointRequest, UpdateReasonCode, UpdateReasonCodeRequest, UpdateSegment, UpdateSegmentRequest, UpdateSubscription, UpdateSubscriptionComponent, UpdateSubscriptionGroup, UpdateSubscriptionGroupRequest, UpdateSubscriptionNote, UpdateSubscriptionNoteRequest, UpdateSubscriptionRequest, UpsertPrepaidConfiguration, UpsertPrepaidConfigurationRequest, Usage, UsageResponse, VoidInvoice, VoidInvoiceEvent, VoidInvoiceEventData, VoidInvoiceRequest, VoidRemainderEvent, VoidRemainderEventData, Webhook, WebhookResponse

Instance Method Summary collapse

Instance Method Details

#to_hashObject

Returns a Hash representation of the current object.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/advanced_billing/models/base_model.rb', line 10

def to_hash
  # validating the model being serialized
  self.class.validate(self) if self.class.respond_to?(:validate)

  hash = {}
  instance_variables.each do |name|
    value = instance_variable_get(name)
    name = name[1..]
    key = self.class.names.key?(name) ? self.class.names[name] : name
    optional_fields = self.class.optionals
    nullable_fields = self.class.nullables
    if value.nil?
      next unless nullable_fields.include?(name)

      if !optional_fields.include?(name) && !nullable_fields.include?(name)
        raise ArgumentError,
              "`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
      end
    end

    hash[key] = nil
    unless value.nil?
      if respond_to?("to_custom_#{name}")
        if (value.instance_of? Array) || (value.instance_of? Hash)
          params = [hash, key]
          hash[key] = send("to_custom_#{name}", *params)
        else
          hash[key] = send("to_custom_#{name}")
        end
      elsif respond_to?("to_union_type_#{name}")
        hash[key] = send("to_union_type_#{name}")
      elsif value.instance_of? Array
        hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
      elsif value.instance_of? Hash
        hash[key] = {}
        value.each do |k, v|
          hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
        end
      else
        hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
      end
    end
  end
  hash
end

#to_json(options = {}) ⇒ Object

Returns a JSON representation of the curent object.



57
58
59
60
# File 'lib/advanced_billing/models/base_model.rb', line 57

def to_json(options = {})
  hash = to_hash
  hash.to_json(options)
end