Beispiel #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)
Beispiel #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']
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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']
Beispiel #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'])
Beispiel #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)
Beispiel #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)
Beispiel #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'])
Beispiel #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)
Beispiel #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)