def test_fetch_transaction_status_with_null_tx_id(self):

        customer = CustomerFactory.create()
        customer.meta = self.customer.meta

        entry = EntryFactory.create(unit_price=25.00)
        invoice = InvoiceFactory.create(
            series="pytest",
            customer=customer,
            invoice_entries=[entry],
            state='issued',
        )

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered', customer=customer)

        transaction = AuthorizeNetTransactionFactory.create(
            invoice=invoice,
            state=Transaction.States.Pending,
            data={
                'id': '1235',
                'status': None,
                'authorizenet_id': None,
            },
            payment_method=payment_method,
        )

        assert str(transaction.data.get('authorizenet_id')) == "None"

        payment_processor = get_instance(transaction.payment_processor)
        status = payment_processor.fetch_transaction_status(transaction)

        assert status == False
    def test_process_create_customer_profile(self):
        customer = CustomerFactory.create()
        customer.meta = self.customer.meta

        customer_data = CustomerData.objects.create(customer=customer,
                                                    data={
                                                        'id': '1235',
                                                    })

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered',
            customer=customer,
        )

        transaction = AuthorizeNetTransactionFactory.create(
            state=Transaction.States.Initial,
            data={
                'id': '1235',
            },
            payment_method=payment_method)

        payment_processor = get_instance(transaction.payment_processor)
        resp = payment_processor.create_customer_profile(customer)

        import os
        print(os.environ)
        assert resp == True
        tok = payment_processor.client_token(customer)

        customer_data = CustomerData.objects.get(customer=customer)

        assert tok == customer_data.get('payment_id')
    def test_process_transaction_from_customer_profile(self):
        # TODO:
        return

        customer = CustomerFactory.create()
        customer.meta = self.customer.meta

        customer_data = CustomerData.objects.create(customer=customer,
                                                    data={
                                                        'id': '1235',
                                                    })

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered',
            customer=customer,
        )

        transaction = AuthorizeNetTransactionFactory.create(
            state=Transaction.States.Initial,
            data={
                'id': '1235',
            },
            payment_method=payment_method)

        payment_processor = get_instance(transaction.payment_processor)
        resp = payment_processor.execute_transaction(transaction,
                                                     charge_profile=True)

        assert resp == True
        tok = payment_processor.client_token(customer)

        customer_data = CustomerData.objects.get(customer=customer)

        assert tok == customer_data.get('payment_id')
    def test_process_transaction_with_credit_card(self):

        customer      = CustomerFactory.create()
        customer.meta = self.customer.meta

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered',
            customer=customer
        )

        transaction = AuthorizeNetTransactionFactory.create(
            state=Transaction.States.Initial,
            data={
                'id': '1235',
                'status': None,
                'authorizenet_id': None,
            },
            payment_method=payment_method,
        )

        assert transaction.state == transaction.States.Initial

        payment_processor = get_instance(transaction.payment_processor)
        status = payment_processor.process_transaction(transaction)

        assert status == True
        assert transaction.state == transaction.States.Pending
    def test_refund_transaction(self):
        customer      = CustomerFactory.create()
        customer.meta = self.customer.meta

        entry   = EntryFactory.create()
        invoice = InvoiceFactory.create(
            series          = "pytest",
            customer        = customer,
            invoice_entries = [entry],
            state           = 'issued',
        )

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered',
            customer=customer
        )

        transaction = AuthorizeNetTransactionFactory.create(
            invoice=invoice,
            state=Transaction.States.Initial,
            data={
                'id': '1235',
                'status': None,
                'authorizenet_id': None,
            },
            payment_method=payment_method,
        )

        assert transaction.state == transaction.States.Initial

        payment_processor = get_instance(transaction.payment_processor)
        status = payment_processor.process_transaction(transaction)

        old_status = transaction.data.get('status')

        assert status == True
        assert transaction.state == transaction.States.Pending

        # assert transaction.data.get('status') != 0
        # 0 implies the API sandbox is in test mode
        assert transaction.data.get('authorizenet_id') != 0

        status = payment_processor.refund_transaction(transaction)

        # transaction.States.Settled
        assert status == True
        # 1 - success, even though it's void apparently 
        assert transaction.data.get('status') == 1
        assert transaction.data.get('authorizenet_id') != 0
        assert transaction.data.get('status') != 0
    def test_process_transaction_with_credit_card(self):

        customer = CustomerFactory.create()
        customer.meta = self.customer.meta

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered', customer=customer)

        entry = EntryFactory.create(unit_price=25.00)
        invoice = InvoiceFactory.create(
            series="pytest",
            customer=customer,
            invoice_entries=[entry],
            state='issued',
        )

        transaction = AuthorizeNetTransactionFactory.create(
            state=Transaction.States.Initial,
            data={
                'id': '1235',
                'status': None,
                'authorizenet_id': None,
            },
            payment_method=payment_method,
            amount=25.00,
            invoice=invoice)

        assert transaction.state == transaction.States.Initial

        payment_processor = get_instance(transaction.payment_processor)
        status = payment_processor.process_transaction(transaction)

        trx = Transaction.objects.all().first()

        assert Transaction.objects.all().count() > 0
        assert trx.data.get('status') != "Null response."

        assert status == True
        assert transaction.state in [
            transaction.States.Pending, transaction.States.Settled
        ]
    def test_process_transaction_with_credit_card_is_success(self):

        customer = CustomerFactory.create()
        customer.meta = self.customer.meta

        entry = EntryFactory.create(unit_price=25.00)
        invoice = InvoiceFactory.create(
            series="pytest",
            customer=customer,
            invoice_entries=[entry],
            state='issued',
        )

        payment_method = AuthorizeNetRecurringPaymentMethodFactory.create(
            payment_processor='AuthorizeNetTriggered', customer=customer)

        transaction = AuthorizeNetTransactionFactory.create(
            invoice=invoice,
            state=Transaction.States.Initial,
            data={
                'id': '1235',
                'status': None,
                'authorizenet_id': None,
            },
            payment_method=payment_method,
        )

        assert transaction.state == transaction.States.Initial

        payment_processor = get_instance(transaction.payment_processor)
        status = payment_processor.process_transaction(transaction)

        assert status == True
        assert transaction.state in [
            transaction.States.Pending, transaction.States.Settled
        ]

        assert transaction.data.get('status') != 0
        # 0 implies the API sandbox is in test mode
        assert transaction.data.get('authorizenet_id') != 0