示例#1
0
    def setUp(self):
        self.api = PayerPostAPI(
            agent_id="AGENT_ID",
            key_1="6866ef97a972ba3a2c6ff8bb2812981054770162",
            key_2="1388ac756f07b0dda2961436ba8596c7b7995e94",
        )

        self.api.set_processing_control(self.getProcessingControl())
        self.api.set_order(self.getOrder())
示例#2
0
    def test_config_errors(self):
        api = PayerPostAPI(agent_id=None, key_1=None, key_2=None)

        # Checksums (keys 1 & 2)
        self.assertRaises(PayerPostAPIError, api.get_checksum, "data")

        api.key_1 = "key1"
        self.assertRaises(PayerPostAPIError, api.get_checksum, "data")

        api.key_2 = "key2"

        raised = False
        try:
            api.get_checksum("data")
        except:
            raised = True

        try:
            api.get_post_data()
        except PayerPostAPIError as e:
            self.assertEqual(e.code, PayerPostAPIError.ERROR_MISSING_ORDER)

        api.set_order(self.getOrder())

        self.assertFalse(raised, 'Exception raised')
        self.assertIsNotNone(api.get_checksum("data"))

        # Order, Processing control, agent ID
        self.assertRaises(PayerPostAPIError, api.get_post_data)

        try:
            api.get_post_data()
        except PayerPostAPIError as e:
            self.assertEqual(
                e.code, PayerPostAPIError.ERROR_MISSING_PROCESSING_CONTROL)

            self.assertEqual(
                str(e),
                repr("Error %s: %s" %
                     (e.code, e.ERROR_MESSAGES.get(e.code, "Unknown Error"))))

        api.agent_id = "AGENT_ID"
        api.set_processing_control(self.getProcessingControl())

        raised = False
        try:
            api.get_post_data()
        except:
            raised = True
        self.assertFalse(raised, 'Exception raised')

        api.agent_id = None
        self.assertRaises(PayerPostAPIError, api._generate_xml)
示例#3
0
    def __init__(self, shop):
        self.shop = shop

        self.api = PayerPostAPI(
            agent_id=getattr(settings, 'SHOP_PAYER_BACKEND_AGENT_ID', ''),
            key_1=getattr(settings, 'SHOP_PAYER_BACKEND_ID1', ''),
            key_2=getattr(settings, 'SHOP_PAYER_BACKEND_ID2', ''),
            payment_methods=self.payment_methods,
            test_mode=getattr(settings, 'SHOP_PAYER_BACKEND_TEST_MODE', False),
            debug_mode=getattr(settings, 'SHOP_PAYER_BACKEND_DEBUG_MODE', DEBUG_MODE_SILENT),
            hide_details=getattr(settings, 'SHOP_PAYER_BACKEND_HIDE_DETAILS', False),
        )

        for ip in getattr(settings, 'SHOP_PAYER_BACKEND_IP_WHITELIST', []):
            self.api.add_whitelist_ip(ip)

        for ip in getattr(settings, 'SHOP_PAYER_BACKEND_IP_BLACKLIST', []):
            self.api.add_blacklist_ip(ip)