Example #1
0
    def test_capture_request_setters(self):
        request = CapturePaymentRequest({
            'receipt': {'phone': '79990000000', 'email': 'test@email', 'tax_system_code': 1, 'items': [
                {
                    "description": "Product 1",
                    "quantity": 2.0,
                    "amount": {
                        "value": 250.0,
                        "currency": Currency.RUB
                    },
                    "vat_code": 2
                },
                {
                    "description": "Product 2",
                    "quantity": 1.0,
                    "amount": {
                        "value": 100.0,
                        "currency": Currency.RUB
                    },
                    "vat_code": 2
                }
            ]},
            'amount': {'value': 0.1, 'currency': Currency.RUB}
        })

        self.assertIsInstance(request.amount, Amount)
        self.assertIsInstance(request.receipt, Receipt)
        self.assertEqual(request.receipt.email, 'test@email')
        self.assertEqual(request.amount.currency, Currency.RUB)

        with self.assertRaises(TypeError):
            request.receipt = 'invalid receipt'

        with self.assertRaises(TypeError):
            request.amount = 'invalid amount'
Example #2
0
    def test_capture_request_cast(self):
        request = CapturePaymentRequest()
        request.receipt = Receipt({'phone': '79990000000', 'email': 'test@email', 'tax_system_code': 1, 'items': [
            {
                "description": "Product 1",
                "quantity": 2.0,
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            },
            {
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": 100.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            }
        ]})
        request.amount = Amount({'value': 0.1, 'currency': Currency.RUB})

        self.assertEqual(
            {
                'receipt': {'phone': '79990000000', 'email': 'test@email', 'tax_system_code': 1, 'items': [
                    {
                        "description": "Product 1",
                        "quantity": 2.0,
                        "amount": {
                            "value": 250.0,
                            "currency": Currency.RUB
                        },
                        "vat_code": 2
                    },
                    {
                        "description": "Product 2",
                        "quantity": 1.0,
                        "amount": {
                            "value": 100.0,
                            "currency": Currency.RUB
                        },
                        "vat_code": 2
                    }
                ]},
                'amount': {'value': 0.1, 'currency': Currency.RUB}
            }, dict(request)
        )
    def capture(cls, payment_id, client, params=None, idempotency_key=None):
        """
        Capture payment

        :param payment_id:
        :param params: data passed to capture payment
        :param idempotency_key:
        :return: PaymentResponse
        """
        instance = cls()
        if not isinstance(payment_id, str) or not payment_id:
            raise ValueError('Invalid payment_id value')

        path = instance.base_path + '/' + payment_id + '/capture'

        if not idempotency_key:
            idempotency_key = uuid.uuid4()

        headers = {'Idempotence-Key': str(idempotency_key)}

        if isinstance(params, dict):
            params_object = CapturePaymentRequest(params)
        elif isinstance(params, CapturePaymentRequest):
            params_object = params
        else:
            params_object = None

        response = client.request(HttpVerb.POST, path, None, headers,
                                  params_object)
        return PaymentResponse(response)
    def test_create_capture_with_object(self):
        payment_facade = Payment()
        with patch('yandex_checkout.client.ApiClient.request') as request_mock:
            request_mock.return_value = {
                'amount': {'currency': 'RUB', 'value': 1.0},
                'created_at': '2017-11-30T15:45:31.130Z',
                'id': '21b23b5b-000f-5061-a000-0674e49a8c10',
                'metadata': {'float_value': '123.32', 'key': 'data'},
                'paid': False,
                'payment_method': {'type': 'bank_card'},
                'recipient': {'account_id': '156833', 'gateway_id': '468284'},
                'status': 'waiting_for_capture'
            }

            payment = payment_facade.capture('21b23b5b-000f-5061-a000-0674e49a8c10', CapturePaymentRequest({
                "amount": {
                    "value": "1.00",
                    "currency": "RUB"
                },
                "receipt": {
                    "items": [
                        {
                            "description": "Item description",
                            "amount": {
                                "value": "1.00",
                                "currency": "RUB"
                            },
                            "quantity": 1,
                            "vat_code": 3
                        }
                    ],
                    "tax_system_id": 2,
                    "email": "test@test"
                },
                "payment_method_data": {
                    "type": "bank_card"
                },
                "confirmation": {
                    "type": "redirect",
                    "return_url": "https://test.test/test"
                },
                "capture": False,
                "save_payment_method": False,
                "metadata": {
                    "key": "data",
                    "float_value": 123.32
                }
            }))

        self.assertIsInstance(payment, PaymentResponse)
        self.assertIsInstance(payment.amount, Amount)
        self.assertIsInstance(payment.payment_method, PaymentDataBankCard)
Example #5
0
    def test_capture_request_validate(self):
        request = CapturePaymentRequest()
        request.amount = {'value': 0.0, 'currency': Currency.RUB}
        with self.assertRaises(ValueError):
            request.validate()

        request = CapturePaymentRequest()
        request.amount = {'value': 0.1, 'currency': Currency.RUB}
        request.receipt = {'tax_system_code': 1, 'items': [
            {
                "description": "Product 1",
                "quantity": 2.0,
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            },
            {
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": 100.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            }
        ]}

        with self.assertRaises(ValueError):
            request.validate()

        request = CapturePaymentRequest()
        request.amount = {'value': 0.1, 'currency': Currency.RUB}
        request.receipt = {'phone': '79990000000', 'items': [
            {
                "description": "Product 1",
                "quantity": 2.0,
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
            },
            {
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": 100.0,
                    "currency": Currency.RUB
                },
            }
        ]}

        with self.assertRaises(ValueError):
            request.validate()
Example #6
0
    def test_capture_request_cast(self):
        request = CapturePaymentRequest()
        request.receipt = Receipt({
            'phone':
            '79990000000',
            'email':
            '*****@*****.**',
            'tax_system_code':
            1,
            'items': [{
                "description": "Product 1",
                "quantity": 2.0,
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            }, {
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": 100.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            }]
        })
        request.amount = Amount({'value': 0.1, 'currency': Currency.RUB})
        request.airline = Airline({
            "booking_reference":
            "IIIKRV",
            "passengers": [{
                "first_name": "SERGEI",
                "last_name": "IVANOV"
            }],
            "legs": [{
                "departure_airport": "LED",
                "destination_airport": "AMS",
                "departure_date": "2018-06-20"
            }]
        })
        request.transfers.append(
            Transfer({
                'account_id': '79990000000',
                "amount": {
                    "value": 100.01,
                    "currency": Currency.RUB
                }
            }))

        self.assertEqual(
            {
                'amount': {
                    'value': 0.1,
                    'currency': Currency.RUB
                },
                'receipt': {
                    'customer': {
                        'email': '*****@*****.**',
                        'phone': '79990000000'
                    },
                    'phone':
                    '79990000000',
                    'email':
                    '*****@*****.**',
                    'items': [{
                        "description": "Product 1",
                        "quantity": 2.0,
                        "amount": {
                            "value": 250.0,
                            "currency": Currency.RUB
                        },
                        "vat_code": 2
                    }, {
                        "description": "Product 2",
                        "quantity": 1.0,
                        "amount": {
                            "value": 100.0,
                            "currency": Currency.RUB
                        },
                        "vat_code": 2
                    }],
                    'tax_system_code':
                    1,
                },
                "airline": {
                    "booking_reference":
                    "IIIKRV",
                    "passengers": [{
                        "first_name": "SERGEI",
                        "last_name": "IVANOV"
                    }],
                    "legs": [{
                        "departure_airport": "LED",
                        "destination_airport": "AMS",
                        "departure_date": "2018-06-20"
                    }]
                },
                'transfers': [{
                    'account_id': '79990000000',
                    "amount": {
                        "value": 100.01,
                        "currency": Currency.RUB
                    }
                }]
            }, dict(request))
 def __init__(self):
     self.__request = CapturePaymentRequest()