class AuthorizeTransactionTestCase(TestCase):

    def setUp(self):
        self.id = "BB55ED929FF749E6BE5A835E4C811B77"
        self.client = TransactionClient(api_store="teststore",
                                        api_key="testkey",
                                        api_token="testtoken")
        self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                   "transactions/{}/authorization-request".format(self.id)
        self.data = {
            "transactionId": self.id,
            "softDescriptor": "sandboxintegracao",
            "prepareForRecurrency": False,
            "split": []
        }

    @responses.activate
    def test_ok(self):
        response_body, response_data = mockup.get_authorize_success()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=200,
                      content_type='text/json')

        result = self.client.authorize(self.id, self.data)
        self.assertEqual(result, response_data)

    @responses.activate
    def test_authorization_error(self):
        response_body = mockup.get_authorization_error()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=401,
                      content_type='text/json')

        with self.assertRaises(faults.AuthorizationError) as context:
            self.client.authorize(self.id, self.data)

        self.assertEqual(context.exception.message, "Acesso não autorizado")
        self.assertEqual(context.exception.code, "1")

    @responses.activate
    def test_without_payment(self):
        response_body = mockup.get_without_payment_error()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=400,
                      content_type='text/json')

        with self.assertRaises(faults.InvalidDataError) as context:
            self.client.authorize(self.id, self.data)

        self.assertEqual("The transaction does not have any payments.",
                         context.exception.message)
        self.assertEqual(context.exception.code, "1419")
class SendTransactionPaymentTestCase(TestCase):

    def setUp(self):
        self.id = "BB55ED929FF749E6BE5A835E4C811B77"
        self.client = TransactionClient(api_store="teststore",
                                        api_key="testkey",
                                        api_token="testtoken")
        self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                   "transactions/{}/payments".format(self.id)
        self.data = [
            {
                "paymentSystem": 2,
                "paymentSystemName": "Visa",
                "groupName": "creditCard",
                "currencyCode": "BRL",
                "installments": 1,
                "value": 100,
                "installmentsInterestRate": 0,
                "installmentsValue": 100,
                "referenceValue": 100,
                "fields": {
                    "accountId": "AJA4CF6058ED44BD9A3637F43C0BAA5Y",
                    "validationCode": "123"
                },
                "transaction": {
                    "id": self.id,
                    "merchantName": "test"
                }
            }
        ]

    @responses.activate
    def test_ok(self):
        responses.add(responses.POST,
                      self.url,
                      body="",
                      status=200,
                      content_type='text/json')

        result = self.client.send_payment(self.id, self.data)
        self.assertEqual(result, {})

    @responses.activate
    def test_invalid_data(self):
        body, response_data = mockup.send_payment_invalid_data_error(
            self.id)
        responses.add(responses.POST,
                      self.url,
                      body=body,
                      status=400,
                      content_type='text/json')

        with self.assertRaises(faults.InvalidDataError) as context:
            self.client.send_payment(self.id, self.data)

        self.assertIn("Error when receiving payments for transaction",
                      context.exception.message)
        self.assertEqual(context.exception.code, "1414")
 def setUp(self):
     self.id = "BB55ED929FF749E6BE5A835E4C811B77"
     self.client = TransactionClient(api_store="teststore",
                                     api_key="testkey",
                                     api_token="testtoken")
     self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                "transactions/{}/payments".format(self.id)
     self.data = [
         {
             "paymentSystem": 2,
             "paymentSystemName": "Visa",
             "groupName": "creditCard",
             "currencyCode": "BRL",
             "installments": 1,
             "value": 100,
             "installmentsInterestRate": 0,
             "installmentsValue": 100,
             "referenceValue": 100,
             "fields": {
                 "accountId": "AJA4CF6058ED44BD9A3637F43C0BAA5Y",
                 "validationCode": "123"
             },
             "transaction": {
                 "id": self.id,
                 "merchantName": "test"
             }
         }
     ]
Exemplo n.º 4
0
 def setUp(self):
     self.id = "BB55ED929FF749E6BE5A835E4C811B77"
     self.client = TransactionClient(api_store="teststore",
                                     api_key="testkey",
                                     api_token="testtoken")
     self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                "transactions/{}/cancellation-request".format(self.id)
Exemplo n.º 5
0
 def setUp(self):
     self.client = TransactionClient(api_store="teststore",
                                     api_key="testkey",
                                     api_token="testtoken")
     self.url = "https://teststore.vtexpayments.com.br/api/pvt/transactions"
     self.data = {"value": 100,
                  "referenceId": "REF001",
                  "channel": "mychannel",
                  "urn": ""}
 def setUp(self):
     self.id = "BB55ED929FF749E6BE5A835E4C811B77"
     self.client = TransactionClient(api_store="teststore",
                                     api_key="testkey",
                                     api_token="testtoken")
     self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                "transactions/{}/authorization-request".format(self.id)
     self.data = {
         "transactionId": self.id,
         "softDescriptor": "sandboxintegracao",
         "prepareForRecurrency": False,
         "split": []
     }
Exemplo n.º 7
0
class CancelTransactionTestCase(TestCase):

    def setUp(self):
        self.id = "BB55ED929FF749E6BE5A835E4C811B77"
        self.client = TransactionClient(api_store="teststore",
                                        api_key="testkey",
                                        api_token="testtoken")
        self.url = "https://teststore.vtexpayments.com.br/api/pvt/"\
                   "transactions/{}/cancellation-request".format(self.id)

    @responses.activate
    def test_ok(self):
        body, response_data = mockup.cancel_transaction_success()
        responses.add(responses.POST,
                      self.url,
                      body=body,
                      status=200,
                      content_type='text/json')

        result = self.client.cancel(self.id, 100)
        self.assertEqual(result, response_data)

    @responses.activate
    def test_invalid_data(self):
        body = mockup.cancel_transaction_invalid_data_error()
        responses.add(responses.POST,
                      self.url,
                      body=body,
                      status=400,
                      content_type='text/json')

        with self.assertRaises(faults.InvalidDataError) as context:
            self.client.cancel(self.id, 0)

        self.assertIn("The transaction value passed (0) is different",
                      context.exception.message)
        self.assertEqual(context.exception.code, "1402")
Exemplo n.º 8
0
class CreateTransactionTestCase(TestCase):

    def setUp(self):
        self.client = TransactionClient(api_store="teststore",
                                        api_key="testkey",
                                        api_token="testtoken")
        self.url = "https://teststore.vtexpayments.com.br/api/pvt/transactions"
        self.data = {"value": 100,
                     "referenceId": "REF001",
                     "channel": "mychannel",
                     "urn": ""}

    @responses.activate
    def test_ok(self):
        response_body, response_data = mockup.create_transaction_success()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=200,
                      content_type='text/json')

        result = self.client.create(self.data)
        self.assertEqual(result, response_data)

    @responses.activate
    def test_authorization_error(self):
        response_body = mockup.get_authorization_error()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=401,
                      content_type='text/json')

        with self.assertRaises(faults.AuthorizationError) as context:
            self.client.create(self.data)

        self.assertEqual(context.exception.message, "Acesso não autorizado")
        self.assertEqual(context.exception.code, "1")

    @responses.activate
    def test_invalid_data_without_value(self):
        response_body = mockup.create_transaction_invalid_data_error()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=400,
                      content_type='text/json')

        del self.data['value']

        with self.assertRaises(faults.InvalidDataError) as context:
            self.client.create(self.data)

        self.assertIn("make sure the transaction value is greater than zero",
                      context.exception.message)
        self.assertEqual(context.exception.code, "1402")

    @responses.activate
    def test_invalid_data_without_reference_id(self):
        response_body = mockup.create_transaction_invalid_data_error()
        responses.add(responses.POST,
                      self.url,
                      body=response_body,
                      status=400,
                      content_type='text/json')

        del self.data['referenceId']

        with self.assertRaises(faults.InvalidDataError) as context:
            self.client.create(self.data)

        self.assertIn("paramaters must be different from null or whitespace",
                      context.exception.message)
        self.assertEqual(context.exception.code, "1402")