1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-04 02:05:51 +03:00
Этот коммит содержится в:
Ivan Shamatov
2021-11-09 10:05:01 +03:00
коммит произвёл GitHub
родитель 22b12409d0
Коммит 2e4efb4143
20 изменённых файлов: 459 добавлений и 26 удалений

Просмотреть файл

@@ -26,6 +26,6 @@ module Yookassa
@client ||= Client.new(shop_id: @config.shop_id, api_key: @config.api_key)
end
def_delegators :client, :payments, :refunds
def_delegators :client, :payments, :refunds, :receipts
end
end

Просмотреть файл

@@ -3,6 +3,7 @@
require "http"
require_relative "./payments"
require_relative "./refunds"
require_relative "./receipts"
require_relative "./entity/error"
module Yookassa
@@ -23,6 +24,10 @@ module Yookassa
@refunds ||= Refunds.new(self)
end
def receipts
@receipts ||= Receipts.new(self)
end
def get(endpoint, query: {})
api_call { http.get("#{API_URL}#{endpoint}", params: query) }
end

31
lib/yookassa/entity/payment_receipt.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,31 @@
# frozen_string_literal: true
require_relative "./types"
require_relative "./customer"
require_relative "./product"
module Yookassa
module Entity
class PaymentReceipt < 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::Coercible::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::Coercible::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

Просмотреть файл

@@ -1,22 +1,43 @@
# frozen_string_literal: true
require_relative "./types"
require_relative "./amount"
require_relative "./supplier"
module Yookassa
module Entity
class Product < Dry::Struct
VatCodes = Types::Coercible::Integer.enum(
1 => "VAT not included",
2 => "0% VAT rate",
3 => "10% VAT rate",
4 => "20% receipts VAT rate",
5 => "10/110 receipts estimate VAT rate",
6 => "20/120 receipts estimate VAT rate"
)
AgentTypes = Types::String.enum(
"banking_payment_agent",
"banking_payment_subagent",
"payment_agent",
"payment_subagent",
"attorney",
"commissioner",
"agent"
)
# 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
attribute :quantity, Types::Coercible::Float
# Product price
attribute :amount, Yookassa::Entity::Amount
attribute :amount, 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
attribute :vat_code, VatCodes
# Payment subject attribute. List of possible values: https://yookassa.ru/en/developers/54fz/parameters-values#payment-subject
attribute? :payment_subject, Types::String
@@ -42,6 +63,16 @@ module Yookassa
# 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
# Information about the supplier of product or service. You can specify this parameter if you send the data
# for creating the receipt using the Receipt after payment scenario.
attribute? :supplier, Supplier
# Type of agent selling goods or services. The parameter is provided for by the format of fiscal documents (FFD)
# and is considered mandatory for versions 1.1 and later. https://yookassa.ru/en/developers/54fz/parameters-values#agent-type
# You can send it if your online sales register is updated to FFD 1.1
# and if you send the data for creating the receipt using the Receipt after payment scenario
attribute? :agent_type, AgentTypes
end
end
end

Просмотреть файл

@@ -3,29 +3,62 @@
require_relative "./types"
require_relative "./customer"
require_relative "./product"
require_relative "./settlement"
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
TaxSystemCodes = Types::Coercible::Integer.enum(
1 => "General tax system",
2 => "Simplified (STS, income)",
3 => "Simplified (STS, income with costs deducted)",
4 => "Unified tax on imputed income (ENVD)",
5 => "Unified agricultural tax (ESN)",
6 => "Patent Based Tax System"
)
# List of products in an order (maximum 100 items).
attribute :items, Types::Array.of(Yookassa::Entity::Product)
# Receipt's ID in YooMoney.
attribute :id, Types::String
# 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::Coercible::Integer
# Type of receipt in the online sales register: payment (payment) or payment refund (refund).
attribute :type, Types::String.enum("payment", "refund")
# 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::Coercible::String
# ID of the payment that the receipt was created for.
attribute? :payment_id, 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
# ID of the refund that the receipt was created for. Not included in the payment receipt.
attribute? :refund_id, Types::String
# Delivery status of receipt data to online sales register (pending, succeeded, or canceled).
attribute :status, Types::String.enum("pending", "succeeded", "canceled")
# Fiscal document number.
attribute? :fiscal_document_number, Types::String
# Number of fiscal storage drive in online sales register.
attribute? :fiscal_storage_number, Types::String
# Fiscal attribute of the receipt. Created by the fiscal storage drive from the data sent for receipt registration.
attribute? :fiscal_attribute, Types::String
# Date and time of receipt creation in the fiscal storage drive, specified in the ISO 8601 format.
attribute? :registered_at, Types::JSON::DateTime
# Receipt's ID in online sales register. For successful receipt registration.
attribute? :fiscal_provider_id, Types::String
# Store's taxation system.
attribute? :tax_system_code, TaxSystemCodes
# List of products in the receipt (maximum 100 items).
attribute :items, Types::Array.of(Product)
# List of completed settlements.
attribute? :settlements, Types::Array.of(Settlement)
# ID of the store on behalf of which you're sending the receipt. Provided by YooMoney.
# The parameter is required if you use the YooMoney solution for marketplaces.
attribute? :on_behalf_of, Types::String
end
end
end

16
lib/yookassa/entity/settlement.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,16 @@
# frozen_string_literal: true
require_relative "./types"
require_relative "./amount"
module Yookassa
module Entity
class Settlement < Dry::Struct
# Type of settlement. List of possible values
attribute :type, Types::String.enum("cashless", "prepayment", "postpayment", "consideration")
# Settlement amount.
attribute :amount, Amount
end
end
end

23
lib/yookassa/entity/supplier.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,23 @@
# frozen_string_literal: true
require_relative "./types"
module Yookassa
module Entity
class Supplier < Dry::Struct
# Supplier name. The parameter is provided for by the format of fiscal documents (FFD)
# and is considered mandatory for versions 1.1 and later.
attribute? :name, Types::String
# Supplier's phone number. Specified in the ITU-T E.164 format, for example, 79000000000
# The parameter is provided for by the format of fiscal documents (FFD) and is considered mandatory
# for versions 1.1 and later.
attribute? :phone, Types::String
# Provider's masked INN/TIN.
# The parameter is provided for by the format of fiscal documents (FFD) and is considered mandatory
# for versions 1.05 and later.
attribute? :inn, Types::String
end
end
end

31
lib/yookassa/receipts.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,31 @@
# frozen_string_literal: true
require_relative "./entity/receipt"
require_relative "./entity/collection"
module Yookassa
class Receipts
def initialize(api)
@api = api
end
def find(receipt_id:)
data = api.get("receipts/#{receipt_id}")
Entity::Receipt.new(**data)
end
def create(payload:, idempotency_key: SecureRandom.hex(10))
data = api.post("receipts", payload: payload, idempotency_key: idempotency_key)
Entity::Receipt.new(**data.merge(idempotency_key: idempotency_key))
end
def list(filters: {})
data = api.get("receipts", query: filters)
Entity::ReceiptCollection.new(**data)
end
private
attr_reader :api
end
end