def customer(self, value):
     if isinstance(value, dict):
         self.__customer = ReceiptCustomer(value)
     elif isinstance(value, ReceiptCustomer):
         self.__customer = value
     else:
         raise TypeError('Invalid customer value type in receipt_request')
Exemple #2
0
    def test_create(self):
        self.maxDiff = None
        with patch('yandex_checkout.client.ApiClient.request') as request_mock:
            request_mock.return_value = {
                "id": "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9",
                "type": "payment",
                "refund_id": "215d8da0-000f-50be-b000-0003308c89be",
                "fiscal_document_number": "3986",
                "fiscal_storage_number": "9288000100115785",
                "fiscal_attribute": "2617603921",
                "registered_at": "2019-05-13T17:56:00.000+03:00",
                "fiscal_provider_id": "fd9e9404-eaca-4000-8ec9-dc228ead2345",
                "tax_system_code": 1,
                "receipt_registration": 'succeeded',
                "items": None,
                "settlements": [
                    {
                        "type": "cashless",
                        "amount": {
                            "value": "45.67",
                            "currency": "RUB"
                        }
                    }
                ],
                "on_behalf_of": "string"
            }

            params = {
                'type': ReceiptType.PAYMENT,
                'send': True,
                'email': '*****@*****.**',
                'phone': '79990000000',
                'items': [
                    {
                        'description': 'Product 1',
                        'quantity': 2.0,
                        'amount': Amount({
                            'value': 250.0,
                            'currency': Currency.RUB
                        }),
                        'vat_code': 2,
                        'payment_mode': 'full_payment',
                        'payment_subject': 'commodity',
                        'country_of_origin_code': 'CN',
                        'product_code': '00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00',
                        'customs_declaration_number': '10714040/140917/0090376',
                        'excise': '20.00',
                        'supplier': {
                            'name': 'string',
                            'phone': 'string',
                            'inn': 'string'
                        }
                    },
                    {
                        'description': 'Product 2',
                        'quantity': 1.0,
                        'amount': {
                            'value': 100.0,
                            'currency': Currency.RUB
                        },
                        'vat_code': 2,
                        'supplier': ReceiptItemSupplier({
                            'name': 'string',
                            'phone': 'string',
                            'inn': 'string'
                        })
                    }
                ],
                'settlements': [
                    {
                        'type': SettlementType.CASHLESS,
                        'amount': {
                            'value': 250.0,
                            'currency': Currency.RUB
                        }
                    }
                ],
                'tax_system_code': 1,
                'payment_id': '215d8da0-000f-50be-b000-0003308c89be',
                'on_behalf_of': 'string'
            }
            rec = Receipt.create(params)

            self.assertIsInstance(rec, ReceiptResponse)
            self.assertEqual(rec.type, ReceiptType.PAYMENT)

            request = ReceiptRequest()
            request.type = ReceiptType.PAYMENT
            request.send = True
            request.customer = ReceiptCustomer({'phone': '79990000000', 'email': '*****@*****.**'})
            request.items.append(
                ReceiptItemRequest({
                    "description": "Product 1",
                    "quantity": 2.0,
                    "amount": Amount({'value': 250.0, 'currency': Currency.RUB}),
                    "vat_code": 2
                }))
            request.items.append(
                ReceiptItemRequest({
                    "description": "Product 2",
                    "quantity": 1.0,
                    "amount": Amount({'value': 100.0, 'currency': Currency.RUB}),
                    "vat_code": 2
                }))
            request.settlements.append(
                Settlement({
                    'type': SettlementType.CASHLESS,
                    'amount': Amount({'value': 250.0, 'currency': Currency.RUB})
                }))
            request.tax_system_code = 1
            request.payment_id = '215d8da0-000f-50be-b000-0003308c89be'
            rec = Receipt.create(request)

            self.assertIsInstance(rec, ReceiptResponse)
            self.assertEqual(rec.type, "payment")

        with self.assertRaises(TypeError):
            Receipt.create('invalid data')
Exemple #3
0
    def test_request_validate(self):
        request = ReceiptRequest()

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

        request.type = ReceiptType.PAYMENT

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

        request.send = True

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

        request.customer = ReceiptCustomer({
            'phone': '79990000000',
            'email': '*****@*****.**'
        })

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

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

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

        request.settlements = [
            Settlement({
                'type': SettlementType.CASHLESS,
                'amount': {
                    'value': 250.0,
                    'currency': Currency.RUB
                }
            })
        ]

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

        request.tax_system_code = 1

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

        request.refund_id = '215d8da0-000f-50be-b000-0003308c89be'

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

        request.type = ReceiptType.REFUND
        request.payment_id = '215d8da0-000f-50be-b000-0003308c89be'

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

        request.items = None
        request.settlements = None
        with self.assertRaises(ValueError):
            request.validate()
Exemple #4
0
    def test_request_cast(self):
        request = ReceiptRequest()
        request.type = ReceiptType.PAYMENT
        request.send = True
        request.customer = ReceiptCustomer({
            'phone': '79990000000',
            'email': '*****@*****.**'
        })
        request.items = [
            ReceiptItemRequest({
                "description": "Product 1",
                "quantity": 2.0,
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            }),
            ReceiptItemRequest({
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": 100.0,
                    "currency": Currency.RUB
                },
                "vat_code": 2
            })
        ]
        request.settlements = [
            Settlement({
                'type': SettlementType.CASHLESS,
                'amount': {
                    'value': 250.0,
                    'currency': Currency.RUB
                }
            })
        ]
        request.tax_system_code = 1
        request.payment_id = '215d8da0-000f-50be-b000-0003308c89be'

        self.assertEqual(
            {
                'type':
                ReceiptType.PAYMENT,
                'send':
                True,
                'customer': {
                    'email': '*****@*****.**',
                    'phone': '79990000000'
                },
                'email':
                '*****@*****.**',
                'phone':
                '79990000000',
                '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
                }],
                'settlements': [{
                    'type': SettlementType.CASHLESS,
                    'amount': {
                        'value': 250.0,
                        'currency': Currency.RUB
                    }
                }],
                'tax_system_code':
                1,
                'payment_id':
                '215d8da0-000f-50be-b000-0003308c89be'
            }, dict(request))
 def phone(self, value):
     if self.__customer is None:
         self.__customer = ReceiptCustomer()
     self.__customer.phone = str(value)
 def email(self, value):
     if self.__customer is None:
         self.__customer = ReceiptCustomer()
     self.__customer.email = str(value)
Exemple #7
0
    def test_receipt_cast(self):
        self.maxDiff = None
        receipt = Receipt()
        receipt.phone = '79990000000'
        receipt.email = '*****@*****.**'
        receipt.tax_system_code = 1
        receipt.items = [
            {
                "description": "Product 1",
                "quantity": '2.1',
                "amount": {
                    "value": 250.0,
                    "currency": Currency.RUB
                },
                "vat_code": "2"
            },
            ReceiptItem({
                "description": "Product 2",
                "quantity": 1.0,
                "amount": {
                    "value": '100.01',
                    "currency": Currency.RUB
                },
                "vat_code": 2,
                "payment_subject": PaymentSubject.AGENT_COMMISSION,
                "payment_mode": PaymentMode.ADVANCE,
                "product_code":
                "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00",
                "country_of_origin_code": "RU",
                "customs_declaration_number": "90/210",
                "excise": 2.00,
            })
        ]

        self.assertTrue(receipt.has_items())
        self.assertEqual(
            {
                'customer': {
                    'phone': '79990000000',
                    'email': '*****@*****.**',
                },
                'phone':
                '79990000000',
                'email':
                '*****@*****.**',
                'tax_system_code':
                1,
                'items': [{
                    "description": "Product 1",
                    "quantity": 2.1,
                    "amount": {
                        "value": 250.0,
                        "currency": Currency.RUB
                    },
                    "vat_code": 2
                }, {
                    "description": "Product 2",
                    "quantity": 1.0,
                    "amount": {
                        "value": 100.01,
                        "currency": Currency.RUB
                    },
                    "vat_code": 2,
                    'payment_subject': PaymentSubject.AGENT_COMMISSION,
                    'payment_mode': PaymentMode.ADVANCE,
                    "product_code":
                    "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00",
                    "country_of_origin_code": "RU",
                    "customs_declaration_number": "90/210",
                    "excise": 2.00,
                }]
            }, dict(receipt))

        customer = ReceiptCustomer({
            'phone': '79990000000',
            'email': '*****@*****.**'
        })
        self.assertEqual({
            'phone': '79990000000',
            'email': '*****@*****.**'
        }, dict(receipt.customer))
        self.assertEqual(dict(customer), dict(receipt.customer))

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

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

        with self.assertRaises(TypeError):
            receipt.items = [
                'invalid item value', {
                    "description": "Product 2",
                    "quantity": 1.0,
                    "amount": {
                        "value": 100.0,
                        "currency": Currency.RUB
                    },
                    "vat_code": 2,
                    "payment_subject": PaymentSubject.AGENT_COMMISSION,
                    "payment_mode": PaymentMode.ADVANCE,
                    "product_code":
                    "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00",
                    "country_of_origin_code": "RU",
                    "customs_declaration_number": "90/210",
                    "excise": 2.00,
                }
            ]