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, ActivateSubscriptionRequest, AddCouponsRequest, AddSubscriptionToAGroup, AgreementAcceptance, AllocateComponents, Allocation, AllocationExpirationDate, AllocationPayment, AllocationPreview, AllocationPreviewItem, AllocationPreviewLineItem, AllocationPreviewResponse, AllocationResponse, AllocationSettings, AppliedCreditNote, ApplyCreditNoteEventData, ApplyDebitNoteEventData, ApplyPaymentEventData, AttributeError, AutoResume, BankAccount, BankAccountAttributes, BankAccountPaymentProfile, BankAccountResponse, BankAccountVerification, BankAccountVerificationRequest, BaseRefundError, BaseStringError, BatchJob, BatchJobResponse, BillingAddress, BillingManifest, BillingManifestItem, Breakouts, BulkComponentSPricePointAssignment, BulkCreateProductPricePointsRequest, BulkCreateProductPricePointsResponse, BulkCreateSegments, BulkUpdateSegments, BulkUpdateSegmentsItem, CalendarBilling, CancelGroupedSubscriptionsRequest, CancellationOptions, CancellationRequest, ChangeInvoiceCollectionMethodEventData, ChargifyEBB, Component, ComponentAllocationChange, ComponentAllocationErrorItem, ComponentCostData, ComponentCostDataRateTier, ComponentCustomPrice, ComponentPrice, ComponentPricePoint, ComponentPricePointErrorItem, ComponentPricePointItem, ComponentPricePointPrice, ComponentPricePointResponse, ComponentPricePointsResponse, ComponentResponse, ComponentSPricePointAssignment, ConsolidatedInvoice, CountResponse, Coupon, CouponCurrency, CouponCurrencyRequest, CouponResponse, CouponRestriction, CouponSubcodes, CouponSubcodesResponse, CouponUsage, CreateAllocation, CreateAllocationRequest, CreateComponentPricePoint, CreateComponentPricePointRequest, CreateComponentPricePointsRequest, CreateCurrencyPrice, CreateCurrencyPricesRequest, CreateCustomer, CreateCustomerRequest, CreateEBBComponent, CreateInvoice, CreateInvoiceAddress, CreateInvoiceCoupon, CreateInvoiceItem, CreateInvoicePayment, CreateInvoicePaymentApplication, CreateInvoicePaymentRequest, CreateInvoiceRequest, CreateMetadata, CreateMetadataRequest, CreateMetafield, CreateMetafieldsRequest, CreateMeteredComponent, CreateMultiInvoicePayment, CreateMultiInvoicePaymentRequest, CreateOffer, CreateOfferComponent, CreateOfferRequest, CreateOnOffComponent, CreateOrUpdateCoupon, CreateOrUpdateFlatAmountCoupon, CreateOrUpdatePercentageCoupon, CreateOrUpdateProduct, CreateOrUpdateProductRequest, CreateOrUpdateSegmentPrice, CreatePayment, CreatePaymentProfile, CreatePaymentProfileRequest, CreatePaymentProfileResponse, CreatePrepaidComponent, CreatePrepaidUsageComponentPricePoint, CreatePrepayment, CreatePrepaymentRequest, CreatePrepaymentResponse, CreateProductCurrencyPrice, CreateProductCurrencyPricesRequest, CreateProductFamily, CreateProductFamilyRequest, CreateProductPricePoint, CreateProductPricePointRequest, CreateQuantityBasedComponent, CreateReasonCode, CreateReasonCodeRequest, CreateSegment, CreateSegmentRequest, CreateSubscription, CreateSubscriptionComponent, CreateSubscriptionGroup, CreateSubscriptionGroupRequest, CreateSubscriptionRequest, CreateUsage, CreateUsageRequest, CreatedPaymentProfile, CreatedPrepayment, CreditAccountBalanceChanged, CreditCardAttributes, CreditCardPaymentProfile, CreditNote, CreditNote1, CreditNoteApplication, CreditNoteLineItem, CreditSchemeRequest, CurrencyPrice, CustomFieldValueChange, CustomPriceUsedForSubscriptionCreateUpdate, Customer, Customer1, CustomerAttributes, CustomerBillingAddressChange, CustomerChange, CustomerChangesPreviewResponse, CustomerCustomFieldsChange, CustomerError, CustomerPayerChange, CustomerResponse, CustomerShippingAddressChange, DeductServiceCredit, DeductServiceCreditRequest, DelayedCancellationResponse, DeleteSubscriptionGroupResponse, DunnerData, DunningStepData, DunningStepReached, EBBComponent, EBBEvent, EnableWebhooksRequest, EnableWebhooksResponse, Endpoint, EndpointResponse, Errors, Event, EventBasedBillingSegmentError, EventResponse, FullSubscriptionGroupResponse, GetOneTimeTokenPaymentProfile, GetOneTimeTokenRequest, GroupBilling, GroupSettings, GroupTarget, Invoice, InvoiceAddress, InvoiceBalanceItem, InvoiceCredit, InvoiceCustomField, InvoiceCustomer, InvoiceDiscount, InvoiceDiscountBreakout, InvoiceDisplaySettings, InvoiceEvent, InvoiceEvent1, InvoiceIssued, InvoiceLineItem, InvoiceLineItemComponentCostData, InvoiceLineItemEventData, InvoiceLineItemPricingDetail, InvoicePayer, InvoicePayment, InvoicePaymentApplication, InvoicePaymentMethod, InvoicePreviousBalance, InvoiceRefund, InvoiceResponse, InvoiceSeller, InvoiceTax, InvoiceTaxBreakout, InvoiceTaxComponentBreakout, IssueAdvanceInvoiceRequest, IssueInvoiceEventData, IssueInvoiceRequest, IssueServiceCredit, IssueServiceCreditRequest, ItemPricePointChanged, ItemPricePointData, ListComponentsPricePointsResponse, ListCreditNotesResponse, ListInvoiceEventsResponse, ListInvoicesResponse, ListMRRResponse, ListMRRResponseResult, ListMetafieldsResponse, ListOffersResponse, ListPaymentProfileItem, ListPaymentProfilesResponse, ListProductPricePointsResponse, ListPublicKeysMeta, ListPublicKeysResponse, ListSaleRepItem, ListSegmentsResponse, ListSubcriptionGroupPrepaymentItem, ListSubscriptionComponentsResponse, ListSubscriptionGroupPrepayment, ListSubscriptionGroupPrepaymentResponse, ListSubscriptionGroupsItem, ListSubscriptionGroupsMeta, ListSubscriptionGroupsResponse, MRR, MRRMovement, MRRResponse, Metadata, Metafield, MetafieldScope, Metafields, Metafields1, MeteredComponent, MeteredUsage, Movement, MovementLineItem, MultiInvoicePayment, MultiInvoicePaymentResponse, NetTerms, Offer, OfferDiscount, OfferItem, OfferResponse, OfferSignupPage, OnOffComponent, OrganizationAddress, OriginInvoice, OveragePricing, OverrideSubscription, OverrideSubscriptionRequest, PaginatedMetadata, PauseRequest, PayerAttributes, PayerError, Payment, PaymentCollectionMethodChanged, PaymentMethodApplePayType, PaymentMethodBankAccountType, PaymentMethodCreditCardType, PaymentMethodExternalType, PaymentMethodNestedData, PaymentMethodPaypalType, PaymentProfile, PaymentProfileAttributes, PaymentProfileResponse, PaymentRelatedEvents, PaymentResponse, PendingCancellationChange, PortalManagementLink, PrePayment, PrepaidComponentPricePoint, PrepaidConfiguration, PrepaidConfigurationResponse, PrepaidSubscriptionBalanceChanged, PrepaidUsage, PrepaidUsageAllocationDetail, PrepaidUsageComponent, Prepayment1, PrepaymentAccountBalanceChanged, PrepaymentAggregatedError, PrepaymentResponse, PrepaymentsResponse, PreviewAllocationsRequest, Price, PricePoint, Product, ProductFamily, ProductFamilyResponse, ProductPricePoint, ProductPricePointCurrencyPrice, ProductPricePointResponse, ProductResponse, ProformaCustomField, ProformaError, ProformaInvoice, ProformaInvoiceCredit, ProformaInvoiceDiscount, ProformaInvoiceDiscountBreakout, ProformaInvoiceIssued, ProformaInvoicePayment, ProformaInvoicePreview, ProformaInvoiceTax, ProformaInvoiceTaxBreakout, Proration, PublicKey, PublicSignupPage, QuantityBasedComponent, ReactivateSubscriptionGroupRequest, ReactivateSubscriptionGroupResponse, ReactivateSubscriptionRequest, ReactivationBilling, ReadPaymentProfileResponse, ReasonCode, ReasonCodeResponse, ReasonCodesJsonResponse, RecordPaymentRequest, ReferralCode, ReferralValidationResponse, Refund, RefundConsolidatedInvoice, RefundInvoice, RefundInvoiceEventData, RefundInvoiceRequest, RefundPrepayment, RefundPrepaymentAggregatedError, RefundPrepaymentBaseRefundError, RefundPrepaymentRequest, RefundSuccess, RemovePaymentEventData, RenewalPreview, RenewalPreviewComponent, RenewalPreviewLineItem, RenewalPreviewRequest, RenewalPreviewResponse, ReplayWebhooksRequest, ReplayWebhooksResponse, ResentInvitation, ResumeOptions, RevokedInvitation, SaleRep, SaleRepItemMrr, SaleRepSettings, SaleRepSubscription, Segment, SegmentPrice, SegmentResponse, Seller, SendInvoiceRequest, ServiceCredit, ServiceCreditResponse, ShippingAddress, SignupProformaPreview, SignupProformaPreviewResponse, Site, SiteResponse, SiteStatistics, SiteSummary, Subscription, SubscriptionBankAccount, SubscriptionComponent, SubscriptionComponentAllocationErrorItem, SubscriptionComponentResponse, SubscriptionComponentSubscription, SubscriptionGroup, SubscriptionGroupBalances, SubscriptionGroupBankAccount, SubscriptionGroupComponentCustomPrice, SubscriptionGroupCreditCard, SubscriptionGroupCustomer, SubscriptionGroupInlined, SubscriptionGroupItem, SubscriptionGroupMemberError, SubscriptionGroupPaymentProfile, SubscriptionGroupPrepayment, SubscriptionGroupPrepaymentRequest, SubscriptionGroupPrepaymentResponse, SubscriptionGroupResponse, SubscriptionGroupSignup, SubscriptionGroupSignupComponent, SubscriptionGroupSignupError, SubscriptionGroupSignupFailure, SubscriptionGroupSignupFailureData, SubscriptionGroupSignupItem, SubscriptionGroupSignupRequest, SubscriptionGroupSignupResponse, SubscriptionGroupSignupSuccess, SubscriptionGroupSignupSuccessData, 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, UpdateEndpoint, UpdateEndpointRequest, UpdateMetadata, UpdateMetadataRequest, UpdateMetafield, UpdateMetafieldsRequest, UpdatePaymentProfile, UpdatePaymentProfileRequest, UpdatePaymentProfileResponse, UpdatePrice, UpdateProductPricePoint, UpdateProductPricePointRequest, UpdateReasonCode, UpdateReasonCodeRequest, UpdateSegment, UpdateSegmentRequest, UpdateSubscription, UpdateSubscriptionComponent, UpdateSubscriptionGroup, UpdateSubscriptionGroupRequest, UpdateSubscriptionNote, UpdateSubscriptionNoteRequest, UpdateSubscriptionRequest, UpdatedPaymentProfile, UpsertPrepaidConfiguration, UpsertPrepaidConfigurationRequest, Usage, UsageResponse, VoidInvoice, VoidInvoiceEventData, VoidInvoiceEventData1, VoidInvoiceRequest, 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