From 811ab20f05a814cb0fae4d00db7e1f1474d44426 Mon Sep 17 00:00:00 2001 From: Ivan Shamatov Date: Sun, 7 Nov 2021 14:58:02 +0300 Subject: [PATCH] Receipt structs added (#17) --- lib/yookassa/entity/customer.rb | 28 ++++++++++++++++++++ lib/yookassa/entity/product.rb | 47 +++++++++++++++++++++++++++++++++ lib/yookassa/entity/receipt.rb | 31 ++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 lib/yookassa/entity/customer.rb create mode 100644 lib/yookassa/entity/product.rb create mode 100644 lib/yookassa/entity/receipt.rb diff --git a/lib/yookassa/entity/customer.rb b/lib/yookassa/entity/customer.rb new file mode 100644 index 0000000..7b68d81 --- /dev/null +++ b/lib/yookassa/entity/customer.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require_relative "./types" + +module Yookassa + module Entity + class Customer < Dry::Struct + # Name of the organization for companies, full name for sole proprietors and individuals. + # If the individual doesn't have a Tax Identification Number (INN), + # specify their passport information in this parameter. Maximum 256 characters. + # Online sales register that support this parameter: Orange Data, ATOL Online. + attribute? :full_name, Types::String + + # User's Tax Identification Number (INN) (10 or 12 digits). If the individual doesn't have an INN, + # specify their passport information in the full_name parameter. + # Online sales register that support this parameter: Orange Data, ATOL Online. + attribute? :inn, Types::String + + # User's email address for sending the receipt. + # Required parameter if phone isn't specified. + attribute? :email, Types::String + + # User's phone number for sending the receipt. Specified in the ITU-T E.164 format, for example, 79000000000. + # Required parameter if email isn't specified. + attribute? :phone, Types::String + end + end +end diff --git a/lib/yookassa/entity/product.rb b/lib/yookassa/entity/product.rb new file mode 100644 index 0000000..c0d09dc --- /dev/null +++ b/lib/yookassa/entity/product.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require_relative "./amount" + +module Yookassa + module Entity + class Product < Dry::Struct + # Product name (maximum 128 characters). + attribute :description, Types::String + + # Product quantity. Maximum possible value depends on the model of your online sales register. + attribute :quantity, Types::String + + # Product price + attribute :amount, Yookassa::Entity::Amount + + # VAT rate. Possible value is a number from 1 to 6. More about VAT rates codes + # https://yookassa.ru/en/developers/54fz/parameters-values#vat-codes + attribute :vat_code, Types::Integer + + # Payment subject attribute. List of possible values: https://yookassa.ru/en/developers/54fz/parameters-values#payment-subject + attribute? :payment_subject, Types::String + + # Payment method attribute. List of possible values: https://yookassa.ru/en/developers/54fz/parameters-values#payment-mode + attribute? :payment_mode, Types::String + + # Product code is a unique number assigned to a unit of product during marking process. + # Format: hexadecimal number with spaces. Maximum length is 32 bytes. + # Example: 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. + # Required parameter for marked products. http://docs.cntd.ru/document/557297080 + attribute? :product_code, Types::String + + # Country of origin code according to the Russian classifier of world countries (OK (MK (ISO 3166) 004-97) 025-2001). + # Example: RU. + # Online sales register tthat support this parameter: Orange Data, Kit Invest. + attribute? :country_of_origin_code, Types::String + + # Customs declaration number (1 to 32 characters). + # Online sales register that support this parameter: Orange Data, Kit Invest. + attribute? :customs_declaration_number, Types::String + + # Amount of excise tax on products including kopeks. Decimal number with 2 digits after the period. + # Online sales register that support this parameter: Orange Data, Kit Invest. + attribute? :excise + end + end +end diff --git a/lib/yookassa/entity/receipt.rb b/lib/yookassa/entity/receipt.rb new file mode 100644 index 0000000..ba91048 --- /dev/null +++ b/lib/yookassa/entity/receipt.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require_relative "./types" +require_relative "./customer" +require_relative "./product" + +module Yookassa + module Entity + class Receipt < Dry::Struct + # User details. You should specify at least the basic contact information: + # email address (customer.email) or phone number (customer.phone) + attribute? :customer, Yookassa::Entity::Customer + + # List of products in an order (maximum 100 items). + attribute :items, Types::Array.of(Yookassa::Entity::Product) + + # Store's tax system. The parameter is only required if you use several tax systems. + # Otherwise, the parameter is not specified. List of possible values: + # https://yookassa.ru/en/developers/54fz/parameters-values#tax-systems + attribute? :tax_system_code, Types::Integer + + # User's phone number for sending the receipt. Set in the ITU-T E.164 format, for example, 79000000000. + # !DEPRECATED PARAMETER: we recommend specifying the details in the receipt.customer.phone parameter. + attribute? :phone, Types::String + + # User's email address for sending the receipt. + # !DEPRECATED PARAMETER: we recommend specifying the details in the receipt.customer.email parameter. + attribute? :email, Types::String + end + end +end