예제 #1
0
 def setUp(self):
     self.config = Config()
     self.payment = Payment(self.config)
예제 #2
0
class PaymentTests(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.payment = Payment(self.config)

    def fill_payment(self):
        self.payment.setValue(123)
        self.payment.setReturnUrl('http://test.te')
        self.payment.setCustomerEmail('*****@*****.**')
        self.payment.setDescription('Order 123 payment')
        self.payment.setMethodId(1)
        self.payment.setMerchantData('Order 123')

    def test_data(self):
        self.fill_payment()

        self.assertEqual(self.payment.getValue(), 123)
        self.assertEqual(self.payment.getReturnUrl(), 'http://test.te')
        self.assertEqual(self.payment.getCustomerEmail(), '*****@*****.**')
        self.assertEqual(self.payment.getDescription(), 'Order 123 payment')
        self.assertEqual(self.payment.getMethodId(), 1)
        self.assertEqual(self.payment.getMerchantData(), 'Order 123')

    def test_wrong_data(self):
        self.assertRaises(ValueError, lambda: self.payment.setValue('-120'))

    def test_params(self):
        self.fill_payment()

        self.assertDictEqual(
            dict(self.payment._getParams()), {
                'value': 123.,
                'accountId': 1,
                'merchantId': 1,
                'returnUrl': 'http://test.te',
                'customerEmail': '*****@*****.**',
                'description': 'Order 123 payment',
                'methodId': 1,
                'merchantData': 'Order 123',
            })

        self.payment.setCurrency('USD')
        self.assertEqual(self.payment.getCurrency(), 'USD')

        self.payment.setCustomerData('test')
        self.assertEqual(self.payment.getCustomerData(), 'test')

        self.payment.setDeposit(321)
        self.assertEqual(self.payment.getDeposit(), 321)

        self.payment.setIsRecurring(True)
        self.assertEqual(self.payment.getIsRecurring(), True)

    def test_url(self):
        self.fill_payment()
        self.assertEqual(
            self.payment.getCreateUrl(),
            'https://www.thepay.cz/demo-gate/?merchantId=1&accountId=1&value=123.0&description=Order+123+payment&merchantData=Order+123&customerEmail=test%40test.te&returnUrl=http%3A%2F%2Ftest.te&methodId=1&signature=7450a2ca57f4a380ed7c4e71d6e0e6bf'
        )
예제 #3
0
파일: tests.py 프로젝트: cuchac/thepay
class PaymentTests(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.payment = Payment(self.config)

    def fill_payment(self):
        self.payment.setValue(123)
        self.payment.setReturnUrl('http://test.te')
        self.payment.setCustomerEmail('*****@*****.**')
        self.payment.setDescription('Order 123 payment')
        self.payment.setMethodId(1)
        self.payment.setMerchantData('Order 123')

    def test_data(self):
        self.fill_payment()

        self.assertEqual(self.payment.getValue(), 123)
        self.assertEqual(self.payment.getReturnUrl(), 'http://test.te')
        self.assertEqual(self.payment.getCustomerEmail(), '*****@*****.**')
        self.assertEqual(self.payment.getDescription(), 'Order 123 payment')
        self.assertEqual(self.payment.getMethodId(), 1)
        self.assertEqual(self.payment.getMerchantData(), 'Order 123')

    def test_wrong_data(self):
        self.assertRaises(ValueError, lambda: self.payment.setValue('-120'))

    def test_params(self):
        self.fill_payment()

        self.assertDictEqual(dict(self.payment.getParams()),
                             {
                                 'value': 123.,
                                 'accountId': 1,
                                 'merchantId': 1,
                                 'returnUrl': 'http://test.te',
                                 'customerEmail': '*****@*****.**',
                                 'description': 'Order 123 payment',
                                 'methodId': 1,
                                 'merchantData': 'Order 123',
                             })

        self.payment.setCurrency('USD')
        self.assertEqual(self.payment.getCurrency(), 'USD')

        self.payment.setCustomerData('test')
        self.assertEqual(self.payment.getCustomerData(), 'test')

        self.payment.setDeposit(321)
        self.assertEqual(self.payment.getDeposit(), 321)

        self.payment.setIsRecurring(True)
        self.assertEqual(self.payment.getIsRecurring(), True)

    def test_url(self):
        self.fill_payment()
        self.assertEqual(self.payment.getCreateUrl(),
                         'https://www.thepay.cz/demo-gate/?merchantId=1&accountId=1&value=123.0&description=Order+123+payment&merchantData=Order+123&customerEmail=test%40test.te&returnUrl=http%3A%2F%2Ftest.te&methodId=1&signature=7450a2ca57f4a380ed7c4e71d6e0e6bf')
예제 #4
0
파일: tests.py 프로젝트: cuchac/thepay
 def setUp(self):
     self.config = Config()
     self.payment = Payment(self.config)
예제 #5
0
    def test_cardCreateRecurrentPayment(self):
        payment_id = str(uuid.uuid4())
        # Create new recurring payment
        payment = Payment(self.config)
        payment.setValue(123)
        payment.setReturnUrl('http://test.te')
        payment.setCustomerEmail('*****@*****.**')
        payment.setDescription('Order 123 payment')
        payment.setMethodId(31)
        payment.setMerchantData(payment_id)
        payment.setIsRecurring(1)
        # Simulate user going through payment process
        response = requests.get(payment.getCreateUrl())
        payment_url = response.url[:-1] + "p"
        response = requests.get(payment_url)
        body = response.content.decode()
        assert "Číslo platby" in body
        for line in body.splitlines():
            if '<input type="hidden" name="id"' in line:
                payment_number = line.split('value="')[1].split('"')[0]
        # Confirm payment state
        response = requests.post("https://www.thepay.cz/demo-gate/return.php",
                                 data={
                                     "state": 2,
                                     "underpaid_value": 1,
                                     "id": payment_number
                                 },
                                 allow_redirects=False)

        # Create recurrent payment for previous one
        # This should work, but is failing for some reason
        with self.assertRaises(GateError):
            self.gateApi.cardCreateRecurrentPayment(payment_id,
                                                    str(uuid.uuid4()), 123)