Ejemplo n.º 1
0
    def test_excludes_SHASIGN_key(self):
        data = {"key_1": "val_1", "key_2": "val_2"}
        without_shasign = shasign(data)

        # Add the shasign to the data and generate again
        data["SHASIGN"] = without_shasign
        with_shasign = shasign(data)
        self.assertEqual(with_shasign, without_shasign)
Ejemplo n.º 2
0
    def test_different_secrets_produce_different_keys(self):
        data = {"key_1": "val_1", "key_2": "val_2"}
        default_key = shasign(data)

        # Set a new secret key
        Setting.objects.create(
            key="SECRET", group="PAYMENT_INGENICO", value="My New Key"
        )

        new_key = shasign(data)
        self.assertNotEqual(default_key, new_key)
Ejemplo n.º 3
0
    def test_no_status(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": order.total,
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": order.id,
            "PAYID": "ingenico-1",
            "PM": "CC",
            # No Status - "STATUS": "9",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        response = process(request)
        self.assertEqual(response.status_code, 200)

        order = Order.objects.get(id=order.id)
        self.assertIn("Status: Unknown", order.notes)
Ejemplo n.º 4
0
    def test_no_status(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": order.total,
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": order.id,
            "PAYID": "ingenico-1",
            "PM": "CC",
            # No Status - "STATUS": "9",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        response = process(request)
        self.assertEqual(response.status_code, 200)

        order = Order.objects.get(id=order.id)
        self.assertIn("Status: Unknown", order.notes)
Ejemplo n.º 5
0
    def test_upper_and_lower_case_keys(self):
        data = {"key_2": "val_2", "KEY_1": "val_1"}

        self.assertEqual(
            shasign(data),
            "a03bed660c957ee6fcf9039476e76cfde54f1fcc7f8c5897d34f70fc06029f8fa6585f6020f5fc4ef90f473756b4d43b04328ed1f3cbc0b221756ddff89de2f3",
        )
Ejemplo n.º 6
0
    def test_excludes_empty_values(self):
        data = {"key_1": "val_1", "key_2": "val_2", "key_3": ""}

        self.assertEqual(
            shasign(data),
            "a03bed660c957ee6fcf9039476e76cfde54f1fcc7f8c5897d34f70fc06029f8fa6585f6020f5fc4ef90f473756b4d43b04328ed1f3cbc0b221756ddff89de2f3",
        )
Ejemplo n.º 7
0
    def test_handles_unicode(self):
        data = {"key_1": "⊙﹏⊙", "key_2": "(◕‿◕)"}

        self.assertEqual(
            shasign(data),
            "2c371045435356083beb5801d4d9c27031066b568fa9253eab5153138e4853f34483e05242055161f1bddec5ab8f43697ca449ef83128e200b56bef9cd8c032d",
        )
Ejemplo n.º 8
0
    def test_status__refund__payment_deleted(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": str(order.total),
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": str(order.id),
            "PAYID": "ingenico-1",
            "PM": "CC",
            "STATUS": "7",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        response = process(request)
        self.assertEqual(response.status_code, 200)

        order = Order.objects.get(id=order.id)
        self.assertTrue(order.frozen)
        self.assertEqual(order.refund, order.total)
        self.assertEqual(order.status.status.status, "Refunded")
        self.assertFalse(
            order.payments.filter(
                amount=order.total,
                payment="INGENICO",
                transaction_id=data["ACCEPTANCE"],
            ).exists()
        )
        for item in order.orderitem_set.all():
            self.assertEqual(item.product.items_in_stock, item.quantity)
            self.assertEqual(item.product.total_sold, 0)
        self.assertIn("Status: Payment deleted", order.notes)
        self.assertTrue(
            OrderRefund.objects.filter(
                order=order, amount=order.refund, transaction_id="trans-1"
            ).exists()
        )
Ejemplo n.º 9
0
    def test_status__refund__payment_deleted(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": str(order.total),
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": str(order.id),
            "PAYID": "ingenico-1",
            "PM": "CC",
            "STATUS": "7",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        response = process(request)
        self.assertEqual(response.status_code, 200)

        order = Order.objects.get(id=order.id)
        self.assertTrue(order.frozen)
        self.assertEqual(order.refund, order.total)
        self.assertEqual(order.status.status.status, "Refunded")
        self.assertFalse(
            order.payments.filter(
                amount=order.total,
                payment="INGENICO",
                transaction_id=data["ACCEPTANCE"],
            ).exists())
        for item in order.orderitem_set.all():
            self.assertEqual(item.product.items_in_stock, item.quantity)
            self.assertEqual(item.product.total_sold, 0)
        self.assertIn("Status: Payment deleted", order.notes)
        self.assertTrue(
            OrderRefund.objects.filter(order=order,
                                       amount=order.refund,
                                       transaction_id="trans-1").exists())
Ejemplo n.º 10
0
    def test_shasign(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "AMOUNT": str(order.total),
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": None,
            "ORDERID": str(order.id),
            "PAYID": "ingenico-1",
            "PM": "CC",
            "STATUS": "1",
            "TRXDATE": date.today().isoformat(),
        }
        form = IngenicoForm(data)

        self.assertIn("SHASIGN", form.fields)
        self.assertEqual(form.data["SHASIGN"], shasign(data))
Ejemplo n.º 11
0
    def test_order_unavailable(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": str(order.total),
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": "1234567890",  # Made up order number
            "PAYID": "ingenico-1",
            "PM": "CC",
            "STATUS": "9",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        with self.assertRaises(Http404):
            process(request)
Ejemplo n.º 12
0
    def test_order_unavailable(self):
        order = TestOrderFactory()

        data = {
            "ACCEPTANCE": "trans-1",
            "amount": str(order.total),
            "BRAND": "Visa",
            "CARDNO": "xxxx xxxx xxxx 4679",
            "CN": order.bill_addressee,
            "CURRENCY": order.currency.iso_4217_code,
            "ED": "02/2019",
            "NCERROR": "",
            "orderID": "1234567890",  # Made up order number
            "PAYID": "ingenico-1",
            "PM": "CC",
            "STATUS": "9",
            "TRXDATE": date.today().isoformat(),
        }
        data["SHASIGN"] = shasign(data)

        request = self.factory.post("/shop/checkout/ingenico/success/", data)

        with self.assertRaises(Http404):
            process(request)