Example #1
0
 def test_parse_xml(self):
     gateway = GlobalIrisGateway(config={'TEST': dict(SHARED_SECRET="mysecret",
                                                      MERCHANT_ID="thestore",
                                                      ACCOUNT="theaccount")
                                         },
                                 test_mode=True)
     fail_resp = Dummy200Response('<?xml version="1.0" ?>\r\n<response timestamp="20140212143606">\r\n<result>504</result>\r\n<message>There is no such merchant id.</message>\r\n<orderid>1</orderid>\r\n</response>\r\n')
     retval = gateway.handle_response(fail_resp, "purchase")
     self.assertEqual(retval['status'], 'FAILURE')
     self.assertEqual(retval['message'], 'There is no such merchant id.')
     self.assertEqual(retval['response_code'], "504")
     self.assertEqual(retval['response'], fail_resp)
Example #2
0
 def mk_gateway(self):
     return GlobalIrisGateway(
         config={'TEST': dict(SHARED_SECRET="mysecret",
                              MERCHANT_ID="thestore",
                              ACCOUNT="theaccount")
                 },
         test_mode=True)
Example #3
0
    def test_purchase_with_test_cards(self):
        # This test requires valid test numbers
        gateway = GlobalIrisGateway()
        if not gateway.test_mode:
            self.fail("MERCHANT_TEST_MODE must be true for running tests")

        for card in self._get_test_cards():
            received_signals = []

            def success(sender, **kwargs):
                received_signals.append(kwargs.get("signal"))

            transaction_was_successful.connect(success)

            def fail(sender, **kwargs):
                received_signals.append(kwargs.get("signal"))

            transaction_was_unsuccessful.connect(fail)

            # Cards with invalid numbers will get caught by billing code, not by
            # the gateway itself.
            try:
                gateway.validate_card(card)
            except CardNotSupported:
                self.assertNotEqual(card.expected_response_code, "00")
                continue  # skip the rest

            response = gateway.purchase(Decimal("45.00"),
                                        card,
                                        options={
                                            'order_id': self.get_order_id(),
                                        })

            actual_rc = response['response_code']
            expected_rc = card.expected_response_code

            self.assertEqual(
                actual_rc, expected_rc, "%s != %s - card %s, message: %s" %
                (actual_rc, expected_rc, card.number, response['message']))
            if card.expected_response_code == "00":
                self.assertEqual(response['status'], 'SUCCESS')
                self.assertEqual(received_signals,
                                 [transaction_was_successful])
            else:
                self.assertEqual(response['status'], 'FAILURE')
                self.assertEqual(received_signals,
                                 [transaction_was_unsuccessful])
Example #4
0
    def test_config_for_card_type(self):
        """
        Test that the GateWay object can pick the correct config depending on the card type.
        """
        gateway = GlobalIrisGateway(config={
                'LIVE': dict(SHARED_SECRET="mysecret",
                             MERCHANT_ID="thestore",
                             ACCOUNT="theaccount"),
                'LIVE_AMEX': dict(SHARED_SECRET="mysecret2",
                                  MERCHANT_ID="thestore",
                                  ACCOUNT="theaccountamex"),
                }, test_mode=False)

        vc = self.get_visa_card()
        self.assertTrue(gateway.validate_card(vc)) # needed for side effects

        ac = self.get_amex_card()
        self.assertTrue(gateway.validate_card(ac))

        self.assertEqual("theaccount", gateway.get_config(vc).account)
        self.assertEqual("theaccountamex", gateway.get_config(ac).account)
Example #5
0
    def test_purchase_with_test_cards(self):
        # This test requires valid test numbers
        gateway = GlobalIrisGateway()
        if not gateway.test_mode:
            self.fail("MERCHANT_TEST_MODE must be true for running tests")

        for card in self._get_test_cards():
            received_signals = []
            def success(sender, **kwargs):
                received_signals.append(kwargs.get("signal"))
            transaction_was_successful.connect(success)

            def fail(sender, **kwargs):
                received_signals.append(kwargs.get("signal"))
            transaction_was_unsuccessful.connect(fail)

            # Cards with invalid numbers will get caught by billing code, not by
            # the gateway itself.
            try:
                gateway.validate_card(card)
            except CardNotSupported:
                self.assertNotEqual(card.expected_response_code, "00")
                continue # skip the rest


            response = gateway.purchase(Decimal("45.00"), card,
                                        options={'order_id': self.get_order_id(),
                                                 })

            actual_rc = response['response_code']
            expected_rc = card.expected_response_code

            self.assertEqual(actual_rc, expected_rc,
                             "%s != %s - card %s, message: %s" % (actual_rc, expected_rc, card.number, response['message']))
            if card.expected_response_code == "00":
                self.assertEqual(response['status'], 'SUCCESS')
                self.assertEqual(received_signals, [transaction_was_successful])
            else:
                self.assertEqual(response['status'], 'FAILURE')
                self.assertEqual(received_signals, [transaction_was_unsuccessful])
Example #6
0
    def test_config_for_card_type(self):
        """
        Test that the GateWay object can pick the correct config depending on the card type.
        """
        gateway = GlobalIrisGateway(config={
                'LIVE': dict(SHARED_SECRET="mysecret",
                             MERCHANT_ID="thestore",
                             ACCOUNT="theaccount"),
                'LIVE_AMEX': dict(SHARED_SECRET="mysecret2",
                                  MERCHANT_ID="thestore",
                                  ACCOUNT="theaccountamex"),
                }, test_mode=False)

        vc = self.get_visa_card()
        self.assertTrue(gateway.validate_card(vc)) # needed for side effects

        ac = self.get_amex_card()
        self.assertTrue(gateway.validate_card(ac))

        self.assertEqual("theaccount", gateway.get_config(vc).account)
        self.assertEqual("theaccountamex", gateway.get_config(ac).account)
Example #7
0
 def test_address_to_code(self):
     gateway = GlobalIrisGateway()
     self.assertEqual(gateway.address_to_code("382, The Road", "WB1 A42"),
                      "142|382")
Example #8
0
 def test_address_to_code(self):
     gateway = GlobalIrisGateway()
     self.assertEqual(gateway.address_to_code("382, The Road", "WB1 A42"),
                      "142|382")