Exemplo n.º 1
0
 def create_receipt_by_term_type(self, product, order_item, term_type):
     today = timezone.now()
     receipt = Receipt()
     receipt.profile = self.invoice.profile
     receipt.order_item = order_item
     receipt.transaction = self.payment.transaction
     receipt.status = PurchaseStatus.COMPLETE
     receipt.start_date = today
     if term_type == TermType.PERPETUAL or term_type == TermType.ONE_TIME_USE:
         receipt.auto_renew = False
     elif term_type == TermType.SUBSCRIPTION:
         total_months = int(
             order_item.offer.term_details['period_length']) * int(
                 order_item.offer.term_details['payment_occurrences'])
     else:
         total_months = term_type - 100
         # Get if it is monthy, bi-monthly, quartarly of annually
     if term_type < TermType.PERPETUAL:
         trial_offset = self.get_payment_schedule_start_date(
             order_item
         )  # If there are any trial days or months you need to offset it on the end date.
         receipt.end_date = self.get_future_date_months(
             trial_offset, total_months)
         receipt.auto_renew = True
     return receipt
Exemplo n.º 2
0
    def test_subscription_update_payment(self):
        self.form_data['credit_card_form']['card_number'] = choice(self.VALID_CARD_NUMBERS)
        subscription_list = self.processor.get_list_of_subscriptions()
        active_subscriptions = [ s for s in subscription_list if s['status'] == 'active' ]
        dummy_receipt = Receipt(order_item=OrderItem.objects.get(pk=2))
        dummy_receipt.transaction = active_subscriptions[-1].id.pyval
        dummy_payment = Payment.objects.create(invoice=self.existing_invoice, 
                                                transaction=dummy_receipt.transaction,
                                                profile=dummy_receipt.profile,
                                                success=True,
                                                amount=dummy_receipt.order_item.invoice.total)
        dummy_payment.result['account_number'] = ""
        dummy_payment.result['account_type'] = ""
        dummy_payment.save()

        if active_subscriptions:
            self.processor.get_payment_info_form_data(self.form_data['credit_card_form'], CreditCardForm)
            self.processor.subscription_update_payment(dummy_receipt)
            dummy_payment.refresh_from_db()
            print(f'Message: {self.processor.transaction_message}\nResponse: {self.processor.transaction_response}\nSubscription ID: {dummy_receipt.transaction}')
            print(f"Update Card number: {self.form_data['credit_card_form']['card_number'][-4:]}")
            self.assertTrue(self.processor.transaction_submitted)
            self.assertEquals(dummy_payment.result['account_number'][-4:], self.form_data['credit_card_form']['card_number'][-4:])
        else:
            print("No active Subscriptions, Skipping Test")
Exemplo n.º 3
0
    def test_cancel_subscription_success(self):
        subscription_list = self.processor.get_list_of_subscriptions()
        active_subscriptions = [ s for s in subscription_list if s['status'] == 'active' ]
        dummy_receipt = Receipt(order_item=OrderItem.objects.get(pk=2))
        dummy_receipt.transaction = active_subscriptions[0].id.pyval

        if active_subscriptions:
            self.processor.subscription_cancel(dummy_receipt)
            self.assertTrue(self.processor.transaction_submitted)
            self.assertTrue(dummy_receipt.status, PurchaseStatus.CANCELED)
        else:
            print("No active Subscriptions, Skipping Test")
Exemplo n.º 4
0
    def test_get_active_offer_receipts_success(self):
        cart = self.customer_profile.get_cart_or_checkout_cart()
        offer = Offer.objects.get(pk=3)
        cart.add_offer(offer)

        receipt = Receipt(profile=self.customer_profile,
                          order_item=cart.order_items.first(),
                          start_date=timezone.now(),
                          transaction="123",
                          status=PurchaseStatus.COMPLETE)
        receipt.save()
        self.assertTrue(
            len(self.customer_profile.get_active_offer_receipts(offer)) > 0)
Exemplo n.º 5
0
    def test_has_previously_owned_products_true(self):
        cart = self.customer_profile.get_cart_or_checkout_cart()
        offer = Offer.objects.get(pk=3)
        cart.add_offer(offer)

        receipt = Receipt(profile=self.customer_profile,
                          order_item=cart.order_items.first(),
                          start_date=timezone.now(),
                          transaction="123",
                          status=PurchaseStatus.COMPLETE)
        receipt.save()
        receipt.products.add(offer.products.first())
        self.assertTrue(
            self.customer_profile.has_previously_owned_products(
                Product.objects.filter(pk=3)))
Exemplo n.º 6
0
    def test_get_one_time_transaction_receipts(self):
        cart = self.customer_profile.get_cart_or_checkout_cart()
        offer = Offer.objects.get(pk=3)
        cart.add_offer(offer)

        receipt = Receipt(profile=self.customer_profile,
                          order_item=cart.order_items.first(),
                          start_date=timezone.now(),
                          transaction="123",
                          status=PurchaseStatus.COMPLETE)
        receipt.save()
        self.assertEqual(0,
                         len(self.customer_profile.get_recurring_receipts()))
        self.assertEqual(
            1, len(self.customer_profile.get_one_time_transaction_receipts()))
Exemplo n.º 7
0
 def create_receipt_by_term_type(self, product, order_item, term_type):
     receipt = Receipt()
     receipt.profile = self.invoice.profile
     receipt.order_item = order_item
     receipt.transaction = self.payment.transaction
     receipt.status = PurchaseStatus.COMPLETE
     receipt.start_date = timezone.now()
     if term_type == TermType.SUBSCRIPTION:
         total_months = int(
             order_item.offer.term_details['period_length']) * int(
                 order_item.offer.term_details['payment_occurrences'])
         receipt.end_date = timezone.now() + timedelta(days=(total_months *
                                                             31))
         receipt.auto_renew = True
     elif term_type == TermType.MONTHLY_SUBSCRIPTION:
         total_months = 1
         receipt.end_date = timezone.now() + timedelta(days=(total_months *
                                                             31))
         receipt.auto_renew = True
     elif term_type == TermType.QUARTERLY_SUBSCRIPTION:
         total_months = 3
         receipt.end_date = timezone.now() + timedelta(days=(total_months *
                                                             31))
         receipt.auto_renew = True
     elif term_type == TermType.SEMIANNUAL_SUBSCRIPTION:
         total_months = 6
         receipt.end_date = timezone.now() + timedelta(days=(total_months *
                                                             31))
         receipt.auto_renew = True
     elif term_type == TermType.ANNUAL_SUBSCRIPTION:
         total_months = 12
         receipt.end_date = timezone.now() + timedelta(days=(total_months *
                                                             31))
         receipt.auto_renew = True
     elif term_type == TermType.PERPETUAL:
         receipt.auto_renew = False
     elif term_type == TermType.ONE_TIME_USE:
         receipt.auto_renew = False
     return receipt
Exemplo n.º 8
0
    def create_receipt_by_term_type(self, product, order_item, term_type):
        today = timezone.now()
        receipt = Receipt()
        receipt.profile = self.invoice.profile
        receipt.order_item = order_item
        receipt.transaction = self.payment.transaction
        receipt.status = PurchaseStatus.COMPLETE
        receipt.start_date = today
        if term_type == TermType.PERPETUAL or term_type == TermType.ONE_TIME_USE:
            receipt.auto_renew = False
        elif term_type == TermType.SUBSCRIPTION:
            total_months = int(order_item.offer.term_details['period_length']) * int(order_item.offer.term_details['payment_occurrences'])
            receipt.end_date = self.get_future_date_months(today, total_months)
            receipt.auto_renew = True
        else:
            total_months = term_type - 100
            receipt.end_date = self.get_future_date_months(today, total_months)
            receipt.auto_renew = True

        return receipt