Esempio n. 1
0
 def approve_and_pay(self, stripe_token, amount, email, line_item_ids):
     """Approve `line_item_ids` and pay `amount` for them with a verified `stripe_token`
     """
     success = False
     amount = int(amount)
     description = '%s %s: %s' % (
         htk_setting('HTK_SITE_NAME'),
         self.get_type(),
         self.id,
     )
     from htk.lib.stripe_lib.utils import create_customer
     customer, stripe_customer = create_customer(
         stripe_token,
         email=email,
         description=description
     )
     line_items = self.resolve_line_item_ids(line_item_ids)
     metadata = {
         'quote' : self.id,
         'line_item_ids' : ','.join(line_item_ids),
         'line_items' : ','.join(['[%s] %s' % (line_item.id, line_item.name,) for line_item in line_items]),
     }
     success = customer.charge(amount=amount, metadata=metadata)
     if success:
         self.create_invoice_for_payment(customer, line_items)
     # TODO: send the customer an email receipt
     return success
Esempio n. 2
0
 def _create_customer_with_card(self):
     card_dict = self._get_card_dict()
     customer, stripe_customer = create_customer(
         card=card_dict, description='Test creating a customer with card')
     self.assertEqual(STRIPE_ID_PREFIX_CUSTOMER,
                      stripe_customer.id[:len(STRIPE_ID_PREFIX_CUSTOMER)])
     return customer
Esempio n. 3
0
 def approve_and_pay(self, stripe_token, amount, email, line_item_ids):
     """Approve `line_item_ids` and pay `amount` for them with a verified `stripe_token`
     """
     success = False
     amount = int(amount)
     description = '%s %s: %s' % (
         htk_setting('HTK_SITE_NAME'),
         self.get_type(),
         self.id,
     )
     # HTK Imports
     from htk.lib.stripe_lib.utils import create_customer
     customer, stripe_customer = create_customer(stripe_token,
                                                 email=email,
                                                 description=description)
     line_items = self.resolve_line_item_ids(line_item_ids)
     metadata = {
         'quote':
         self.id,
         'line_item_ids':
         ','.join(line_item_ids),
         'line_items':
         ','.join([
             '[%s] %s' % (
                 line_item.id,
                 line_item.name,
             ) for line_item in line_items
         ]),
     }
     success = customer.charge(amount=amount, metadata=metadata)
     if success:
         self.create_invoice_for_payment(customer, line_items)
     # TODO: send the customer an email receipt
     return success
Esempio n. 4
0
    def create_stripe_customer(self, card=None):
        """Creates a new StripeCustomer object for this User if one does not exist

        If `card` is passed in, will also create the card for the customer
        """
        if self.stripe_customer:
            pass
        else:
            from htk.lib.stripe_lib.utils import create_customer
            email = self.get_stripe_customer_email()
            description = self.get_stripe_customer_description()
            customer, stripe_customer = create_customer(card=card, email=email, description=description)
            self.stripe_customer = customer
            self.save()
        return self.stripe_customer
Esempio n. 5
0
    def create_stripe_customer(self, card=None):
        """Creates a new StripeCustomer object for this User if one does not exist

        If `card` is passed in, will also create the card for the customer
        """
        if self.stripe_customer:
            pass
        else:
            from htk.lib.stripe_lib.utils import create_customer
            email = self.get_stripe_customer_email()
            description = self.get_stripe_customer_description()
            customer, stripe_customer = create_customer(card=card, email=email, description=description)
            self.stripe_customer = customer
            self.save()
        return self.stripe_customer
Esempio n. 6
0
 def _create_customer_with_card(self):
     card_dict = self._get_card_dict()
     customer, stripe_customer = create_customer(card=card_dict, description='Test creating a customer with card')
     self.assertEqual(STRIPE_ID_PREFIX_CUSTOMER, stripe_customer.id[:len(STRIPE_ID_PREFIX_CUSTOMER)])
     return customer