Example #1
0
    def test_concat_commands(self):
        expected_result = '1|test|100|235|http://tolary.cz|http://tolary.cz|111111111111111111111111'
        result = utils.Concat(secret=SECRET).command(utils.Concat.PAYMENT, PAYMENT_COMMAND)
        self.assertEqual(expected_result, result)

        #try another way to call Concat
        result = utils.Concat(secret=SECRET)(utils.Concat.PAYMENT, PAYMENT_COMMAND)
        self.assertEqual(expected_result, result)

        expected_result = '8363419680|test|100|235|CALL_COMPLETED|WAITING|111111111111111111111111'
        result = utils.Concat(secret=SECRET).command(utils.Concat.PAYMENT_RESULT,
            utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE))
        self.assertEqual(expected_result, result)
Example #2
0
    def create_payment(self, productName, variableSymbol, totalPriceInCents, paymentChannels=const.PAYMENT_METHODS):
        cmd = self._create_payment_cmd(productName, variableSymbol, totalPriceInCents, paymentChannels)
        payment_string = self.concat(utils.Concat.PAYMENT, cmd)
        cmd['encryptedSignature'] = self.crypt.encrypt(payment_string)
        cmd = utils.prefix_command_keys(cmd, const.PREFIX_CMD_PAYMENT)
        r = requests.post(const.GOPAY_NEW_PAYMENT_URL, data=cmd, verify=VERIFY_SSL)

        if r.status_code != 200:
            raise utils.ValidationException(WRONG_STATUS_MSG % r.status_code)
        utils.CommandsValidator(r.content).payment()

        response = utils.parse_xml_to_dict(r.content)
        #        print response
        return response['paymentSessionId']
Example #3
0
    def verify_payment_status(self, paymentSessionId):
        """tells if the payment was successful or not, returns tuple (success, whole response)"""

        cmd = dict(eshopGoId=settings.GOPAY_ESHOP_GOID, paymentSessionId=paymentSessionId)
        concat_cmd = self.concat(utils.Concat.PAYMENT_STATUS, cmd)
        cmd['encryptedSignature'] = self.crypt.encrypt(concat_cmd)
        cmd = utils.prefix_command_keys(cmd, prefix=const.PREFIX_CMD_PAYMENT_RESULT)
        r = requests.post(const.GOPAY_PAYMENT_STATUS_URL, data=cmd, verify=VERIFY_SSL)
        #        print r.content
        if r.status_code != 200:
            raise utils.ValidationException(WRONG_STATUS_MSG % r.status_code)
        utils.CommandsValidator(r.content).payment_status()
        response = utils.parse_xml_to_dict(r.content)
        #        print response
        return response['sessionState'] == const.PAYMENT_DONE, response
Example #4
0
    def test_concat_commands(self):
        expected_result = '1|test|100|235|http://tolary.cz|http://tolary.cz|111111111111111111111111'
        result = utils.Concat(secret=SECRET).command(utils.Concat.PAYMENT,
                                                     PAYMENT_COMMAND)
        self.assertEqual(expected_result, result)

        #try another way to call Concat
        result = utils.Concat(secret=SECRET)(utils.Concat.PAYMENT,
                                             PAYMENT_COMMAND)
        self.assertEqual(expected_result, result)

        expected_result = '8363419680|test|100|235|CALL_COMPLETED|WAITING|111111111111111111111111'
        result = utils.Concat(secret=SECRET).command(
            utils.Concat.PAYMENT_RESULT,
            utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE))
        self.assertEqual(expected_result, result)
Example #5
0
    def verify_payment_status(self, paymentSessionId):
        """tells if the payment was successful or not, returns tuple (success, whole response)"""

        cmd = dict(eshopGoId=settings.GOPAY_ESHOP_GOID,
                   paymentSessionId=paymentSessionId)
        concat_cmd = self.concat(utils.Concat.PAYMENT_STATUS, cmd)
        cmd['encryptedSignature'] = self.crypt.encrypt(concat_cmd)
        cmd = utils.prefix_command_keys(cmd,
                                        prefix=const.PREFIX_CMD_PAYMENT_RESULT)
        r = requests.post(const.GOPAY_PAYMENT_STATUS_URL,
                          data=cmd,
                          verify=VERIFY_SSL)
        #        print r.content
        if r.status_code != 200:
            raise utils.ValidationException(WRONG_STATUS_MSG % r.status_code)
        utils.CommandsValidator(r.content).payment_status()
        response = utils.parse_xml_to_dict(r.content)
        #        print response
        return response['sessionState'] == const.PAYMENT_DONE, response
Example #6
0
    def create_payment(self,
                       productName,
                       variableSymbol,
                       totalPriceInCents,
                       paymentChannels=const.PAYMENT_METHODS):
        cmd = self._create_payment_cmd(productName, variableSymbol,
                                       totalPriceInCents, paymentChannels)
        payment_string = self.concat(utils.Concat.PAYMENT, cmd)
        cmd['encryptedSignature'] = self.crypt.encrypt(payment_string)
        cmd = utils.prefix_command_keys(cmd, const.PREFIX_CMD_PAYMENT)
        r = requests.post(const.GOPAY_NEW_PAYMENT_URL,
                          data=cmd,
                          verify=VERIFY_SSL)

        if r.status_code != 200:
            raise utils.ValidationException(WRONG_STATUS_MSG % r.status_code)
        utils.CommandsValidator(r.content).payment()

        response = utils.parse_xml_to_dict(r.content)
        #        print response
        return response['paymentSessionId']
Example #7
0
 def test_parse_response_xml(self):
     response_dict = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     self.assertEqual(response_dict['productName'],
                      PAYMENT_COMMAND['productName'])
Example #8
0
 def test_decrypt(self):
     response = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     response_cmd = self.concat(utils.Concat.PAYMENT_RESULT, response)
     hashed_cmd = self.crypt.hash(response_cmd)
     decrypted = self.crypt.decrypt(response['encryptedSignature'])
     self.assertEqual(hashed_cmd, decrypted)
Example #9
0
 def test_decryption_methods_equal(self):
     response = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     pycrypt = self.crypt.decrypt(response['encryptedSignature'])
     pydes = self.crypt.decrypt_pydes(response['encryptedSignature'])
     self.assertEqual(pycrypt, pydes)
Example #10
0
 def test_parse_response_xml(self):
     response_dict = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     self.assertEqual(response_dict['productName'], PAYMENT_COMMAND['productName'])
Example #11
0
 def test_decrypt(self):
     response = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     response_cmd = self.concat(utils.Concat.PAYMENT_RESULT, response)
     hashed_cmd = self.crypt.hash(response_cmd)
     decrypted = self.crypt.decrypt(response['encryptedSignature'])
     self.assertEqual(hashed_cmd, decrypted)
Example #12
0
 def test_decryption_methods_equal(self):
     response = utils.parse_xml_to_dict(PAYMENT_RESULT_RESPONSE)
     pycrypt = self.crypt.decrypt(response['encryptedSignature'])
     pydes = self.crypt.decrypt_pydes(response['encryptedSignature'])
     self.assertEqual(pycrypt, pydes)