Example #1
0
    def testCreateAgreement3(self):
        # Needs credentials to test
        self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))

        service = Payex(merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False)

        # Create an agreement
        response = service.create_agreement(
            merchantRef="oneclick",
            description="One-click shopping",
            purchaseOperation="AUTHORIZATION",
            maxAmount="100000",
        )

        self.assertEquals(response["status"]["description"], "OK")
        self.assertEquals(response["status"]["errorCode"], "OK")
        self.assertTrue("agreementRef" in response)
        self.assertFalse("existingAgreementRef" in response)

        agreement_ref = response["agreementRef"]

        response = service.initialize(
            purchaseOperation="AUTHORIZATION",
            price="5000",
            currency="NOK",
            vat="2500",
            orderID="test2",
            productNumber="123",
            description=u"This is a test with øæå.",
            clientIPAddress="127.0.0.1",
            clientIdentifier="USERAGENT=test&username=testuser",
            additionalValues="PAYMENTMENU=TRUE",
            returnUrl="http://example.org/return",
            view="PX",
            agreementRef=agreement_ref,
            cancelUrl="http://example.org/cancel",
        )

        self.assertEquals(response["status"]["description"], "OK")
        self.assertEquals(response["status"]["errorCode"], "OK")
        self.assertTrue("redirectUrl" in response)
        self.assertTrue(response["orderRef"] in response["redirectUrl"])
Example #2
0
    def testPayment(self):
        """
        Test the initialize7 and complete method.
        """

        # Needs credentials to test
        self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY]))

        service = Payex(merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False)

        # Initialize a payment
        response = service.initialize(
            purchaseOperation="AUTHORIZATION",
            price="5000",
            currency="NOK",
            vat="2500",
            orderID="test1",
            productNumber="123",
            description=u"This is a test. åâaä",
            clientIPAddress="127.0.0.1",
            clientIdentifier="USERAGENT=test&username=testuser",
            additionalValues="PAYMENTMENU=TRUE",
            returnUrl="http://example.org/return",
            view="PX",
            cancelUrl="http://example.org/cancel",
        )

        # Check the response
        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response["status"]["description"], "OK")
        self.assertEquals(response["status"]["errorCode"], "OK")
        self.assertTrue("orderRef" in response)
        self.assertTrue(response["redirectUrl"].startswith("https://test-account.payex.com/MiscUI/PxMenu.aspx"))

        # Complete the order (even if it's not completed by user)
        response = service.complete(orderRef=response["orderRef"])

        self.assertEquals(type(response), XmlDictConfig)
        self.assertEquals(response["status"]["errorCode"], "Order_OrderProcessing")