def test_decimal_calc(self): 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" }, { "description": "Product 2", "quantity": 1.0, "amount": { "value": '100.01', "currency": Currency.RUB }, "vat_code": "2" }] summ = round(receipt.items[0].amount.value * receipt.items[0].quantity, 2) self.assertEqual(Decimal('525.00'), Decimal(summ)) summ = round(receipt.items[1].amount.value * receipt.items[1].quantity, 2) self.assertEqual(Decimal('100.01'), Decimal(summ))
def receipt(self, value): if isinstance(value, dict): self.__receipt = Receipt(value) elif isinstance(value, Receipt): self.__receipt = value else: raise TypeError('Invalid receipt value type')
def test_receipt_customer(self): receipt = Receipt( {'customer': { 'email': '*****@*****.**', 'inn': '4815162342', }}) self.assertEqual( { 'customer': { 'email': '*****@*****.**', 'inn': '4815162342', }, 'email': '*****@*****.**', }, dict(receipt))
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 test_receipt_cast(self): self.maxDiff = None receipt = Receipt() receipt.phone = '79990000000' receipt.email = 'test@email' receipt.tax_system_code = 1 receipt.items = [{ "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": "2" }, ReceiptItem({ "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2 })] self.assertTrue(receipt.has_items()) self.assertEqual( { '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 }] }, dict(receipt)) with self.assertRaises(TypeError): receipt.tax_system_code = 'invalid type' with self.assertRaises(ValueError): receipt.phone = 'invalid phone' 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 } ]
def test_request_cast(self): self.maxDiff = None request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.description = 'Test description' request.recipient = Recipient({ 'account_id': '213', 'gateway_id': '123' }) request.save_payment_method = True request.capture = False request.payment_method_data = PaymentDataWebmoney() 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.payment_method_id = '123' request.payment_token = '99091209012' request.confirmation = ConfirmationRedirect( {'return_url': 'return.url'}) request.client_ip = '192.0.0.0' request.metadata = {'key': 'value'} self.assertEqual( { 'amount': { 'value': 0.1, 'currency': Currency.RUB }, 'recipient': { 'account_id': '213', 'gateway_id': '123' }, 'description': 'Test description', 'save_payment_method': True, 'capture': False, 'payment_method_data': { 'type': PaymentMethodType.WEBMONEY }, '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 }] }, 'payment_method_id': '123', 'payment_token': '99091209012', 'confirmation': { 'type': ConfirmationType.REDIRECT, 'return_url': 'return.url' }, 'client_ip': '192.0.0.0', 'metadata': { 'key': 'value' } }, dict(request))
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.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": "2" }, ReceiptItem({ "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, }) ] self.assertTrue(receipt.has_items()) self.assertEqual( { 'customer': { 'phone': '79990000000', 'email': '*****@*****.**', }, '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, '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)) with self.assertRaises(TypeError): receipt.tax_system_code = 'invalid type' with self.assertRaises(ValueError): receipt.phone = 'invalid phone' 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, } ]
def test_refund_cast(self): self.maxDiff = None request = RefundRequest() request.payment_id = '21a632d2-000f-5061-a000-01e90bc2de12' request.description = 'test comment' 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( { 'payment_id': '21a632d2-000f-5061-a000-01e90bc2de12', 'description': 'test comment', '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 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 test_request_cast(self): self.maxDiff = None request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.description = 'Test description' request.recipient = Recipient({ 'account_id': '213', 'gateway_id': '123' }) request.save_payment_method = True request.capture = False request.payment_method_data = PaymentDataWebmoney() 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.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.payment_method_id = '123' request.payment_token = '99091209012' request.confirmation = ConfirmationRedirect({ 'locale': 'ru_RU', 'return_url': 'return.url' }) request.client_ip = '192.0.0.0' request.metadata = {'key': 'value'} request.transfers.append( Transfer({ 'account_id': '79990000000', "amount": { "value": 100.01, "currency": Currency.RUB } })) self.assertEqual( { 'amount': { 'value': 0.1, 'currency': Currency.RUB }, 'recipient': { 'account_id': '213', 'gateway_id': '123' }, 'description': 'Test description', 'save_payment_method': True, 'capture': False, 'payment_method_data': { 'type': PaymentMethodType.WEBMONEY }, 'receipt': { 'customer': { 'email': '*****@*****.**', 'phone': '79990000000' }, '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 }] }, 'payment_method_id': '123', 'payment_token': '99091209012', 'confirmation': { 'type': ConfirmationType.REDIRECT, 'locale': 'ru_RU', 'return_url': 'return.url' }, 'client_ip': '192.0.0.0', 'metadata': { 'key': 'value' }, "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))