def test_credit_card_reader_payment(self):
        # Payment creation
        cmd = pagseguro_facade.procces_external_payment_cmd(
            create_credit_card_xml())
        cmd()
        payment = PagSegPayment.query().get()
        self.assertEqual('6F09ACBC-BEC1-463F-9174-5E0CF5BE33F1', payment.code)
        self.assertEqual(Decimal('1.00'), payment.total)
        self.assertEqual(Decimal('0.98'), payment.net_amount)
        self.assertEqual(STATUS_AVAILABLE, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_AVAILABLE, logs[0].status)
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(1, len(items))
        item = items[0]
        self.assertEqual(Decimal('1.00'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Venda pelo celular com leitor de chip e senha',
                         item.description)

        # Payment update
        cmd = pagseguro_facade.procces_external_payment_cmd(
            create_credit_card_xml(7))
        cmd()
        payments = PagSegPayment.query().fetch()
        self.assertEqual(1, len(payments))
        payment = payments[0]

        self.assertEqual('6F09ACBC-BEC1-463F-9174-5E0CF5BE33F1', payment.code)
        self.assertEqual(Decimal('1.00'), payment.total)
        self.assertEqual(Decimal('0.98'), payment.net_amount)
        self.assertEqual(STATUS_CANCELLED, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertListEqual([STATUS_AVAILABLE, STATUS_CANCELLED],
                             [log.status for log in logs])
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(1, len(items))
        item = items[0]
        self.assertEqual(Decimal('1.00'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Venda pelo celular com leitor de chip e senha',
                         item.description)
    def test_integration_button_payment(self):
        # Payment creation
        cmd = pagseguro_facade.procces_external_payment_cmd(
            generate_xml('non particular id', '1', '18.99'))
        cmd()
        payment = PagSegPayment.query().get()
        self.assertEqual(CODE, payment.code)
        self.assertEqual(Decimal('49900'), payment.total)
        self.assertEqual(Decimal('18.99'), payment.net_amount)
        self.assertEqual(STATUS_SENT_TO_PAGSEGURO, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_SENT_TO_PAGSEGURO, logs[0].status)
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(2, len(items))
        item = items[0]
        self.assertEqual(Decimal('24300'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Notebook Prata', item.description)

        # Payment update
        cmd = pagseguro_facade.procces_external_payment_cmd(
            generate_xml('non particular id', '7', '18.99'))
        cmd()
        payments = PagSegPayment.query().fetch()
        self.assertEqual(1, len(payments))
        payment = payments[0]

        self.assertEqual(CODE, payment.code)
        self.assertEqual(Decimal('49900'), payment.total)
        self.assertEqual(Decimal('18.99'), payment.net_amount)
        self.assertEqual(STATUS_CANCELLED, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertListEqual([STATUS_SENT_TO_PAGSEGURO, STATUS_CANCELLED],
                             [log.status for log in logs])
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(2, len(items))
        item = items[0]
        self.assertEqual(Decimal('24300'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Notebook Prata', item.description)
    def test_integration_button_payment(self):
        # Payment creation
        cmd = pagseguro_facade.procces_external_payment_cmd(generate_xml('non particular id', '1', '18.99'))
        cmd()
        payment = PagSegPayment.query().get()
        self.assertEqual(CODE, payment.code)
        self.assertEqual(Decimal('49900'), payment.total)
        self.assertEqual(Decimal('18.99'), payment.net_amount)
        self.assertEqual(STATUS_SENT_TO_PAGSEGURO, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_SENT_TO_PAGSEGURO, logs[0].status)
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(2, len(items))
        item = items[0]
        self.assertEqual(Decimal('24300'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Notebook Prata', item.description)

        # Payment update
        cmd = pagseguro_facade.procces_external_payment_cmd(generate_xml('non particular id', '7', '18.99'))
        cmd()
        payments = PagSegPayment.query().fetch()
        self.assertEqual(1, len(payments))
        payment = payments[0]

        self.assertEqual(CODE, payment.code)
        self.assertEqual(Decimal('49900'), payment.total)
        self.assertEqual(Decimal('18.99'), payment.net_amount)
        self.assertEqual(STATUS_CANCELLED, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertListEqual([STATUS_SENT_TO_PAGSEGURO, STATUS_CANCELLED], [log.status for log in logs])
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(2, len(items))
        item = items[0]
        self.assertEqual(Decimal('24300'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Notebook Prata', item.description)
    def test_credit_card_reader_payment(self):
        # Payment creation
        cmd = pagseguro_facade.procces_external_payment_cmd(create_credit_card_xml())
        cmd()
        payment = PagSegPayment.query().get()
        self.assertEqual('6F09ACBC-BEC1-463F-9174-5E0CF5BE33F1', payment.code)
        self.assertEqual(Decimal('1.00'), payment.total)
        self.assertEqual(Decimal('0.98'), payment.net_amount)
        self.assertEqual(STATUS_AVAILABLE, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertEqual(1, len(logs))
        self.assertEqual(STATUS_AVAILABLE, logs[0].status)
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(1, len(items))
        item = items[0]
        self.assertEqual(Decimal('1.00'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Venda pelo celular com leitor de chip e senha', item.description)

        # Payment update
        cmd = pagseguro_facade.procces_external_payment_cmd(create_credit_card_xml(7))
        cmd()
        payments = PagSegPayment.query().fetch()
        self.assertEqual(1, len(payments))
        payment = payments[0]

        self.assertEqual('6F09ACBC-BEC1-463F-9174-5E0CF5BE33F1', payment.code)
        self.assertEqual(Decimal('1.00'), payment.total)
        self.assertEqual(Decimal('0.98'), payment.net_amount)
        self.assertEqual(STATUS_CANCELLED, payment.status)
        logs = pagseguro_facade.search_logs(payment)()
        self.assertListEqual([STATUS_AVAILABLE, STATUS_CANCELLED], [log.status for log in logs])
        items = pagseguro_facade.search_items(payment)()
        self.assertEqual(1, len(items))
        item = items[0]
        self.assertEqual(Decimal('1.00'), item.price)
        self.assertEqual(1, item.quantity)
        self.assertEqual('Venda pelo celular com leitor de chip e senha', item.description)