<s> import stripe <EOL> from zebra . conf import options <EOL> def _get_attr_value ( instance , attr , default = None ) : <EOL> """<STR_LIT>""" <EOL> value = default <EOL> if hasattr ( instance , attr ) : <EOL> value = getattr ( instance , attr ) <EOL> if callable ( value ) : <EOL> value = value ( ) <EOL> return value <EOL> class StripeMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> stripe . api_key = _get_attr_value ( self , '<STR_LIT>' ) <EOL> elif hasattr ( options , '<STR_LIT>' ) : <EOL> stripe . api_key = _get_attr_value ( options , '<STR_LIT>' ) <EOL> return stripe <EOL> stripe = property ( _get_stripe ) <EOL> class StripeCustomerMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_customer ( self ) : <EOL> c = None <EOL> if _get_attr_value ( self , '<STR_LIT>' ) : <EOL> c = self . stripe . Customer . retrieve ( _get_attr_value ( self , <EOL> '<STR_LIT>' ) ) <EOL> if not c and options . ZEBRA_AUTO_CREATE_STRIPE_CUSTOMERS : <EOL> c = self . stripe . Customer . create ( ) <EOL> self . stripe_customer_id = c . id <EOL> self . save ( ) <EOL> return c <EOL> stripe_customer = property ( _get_stripe_customer ) <EOL> class StripeSubscriptionMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_subscription ( self ) : <EOL> subscription = None <EOL> customer = _get_attr_value ( self , '<STR_LIT>' ) <EOL> if hasattr ( customer , '<STR_LIT>' ) : <EOL> subscription = customer . subscription <EOL> return subscription <EOL> stripe_subscription = property ( _get_stripe_subscription ) <EOL> class StripePlanMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_plan ( self ) : <EOL> return stripe . Plan . retrieve ( _get_attr_value ( self , '<STR_LIT>' ) ) <EOL> stripe_plan = property ( _get_stripe_plan ) <EOL> class StripeInvoiceMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_invoice ( self ) : <EOL> return stripe . Invoice . retrieve ( _get_attr_value ( self , <EOL> '<STR_LIT>' ) ) <EOL> stripe_invoice = property ( _get_stripe_invoice ) <EOL> class StripeInvoiceItemMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_invoice_item ( self ) : <EOL> return stripe . InvoiceItem . retrieve ( _get_attr_value ( self , <EOL> '<STR_LIT>' ) ) <EOL> stripe_invoice_item = property ( _get_stripe_invoice_item ) <EOL> class StripeChargeMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def _get_stripe_charge ( self ) : <EOL> return stripe . Charge . retrieve ( _get_attr_value ( self , '<STR_LIT>' ) ) <EOL> stripe_charge = property ( _get_stripe_charge ) <EOL> class ZebraMixin ( StripeMixin , StripeCustomerMixin , StripeSubscriptionMixin , <EOL> StripePlanMixin , StripeInvoiceMixin , StripeInvoiceItemMixin , <EOL> StripeChargeMixin ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
