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

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

71
spec/fixtures/list_receipt_response.json поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,71 @@
{
"type": "list",
"items": [
{
"id": "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9",
"type": "payment",
"payment_id": "215d8da0-000f-50be-b000-0003308c89be",
"status": "succeeded",
"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",
"items": [
{
"description": "Сapybara",
"quantity": 5.000,
"amount": {
"value": "2500.50",
"currency": "RUB"
},
"vat_code": 2,
"payment_mode": "full_payment",
"payment_subject": "commodity"
}
],
"tax_system_code": 1
},
{
"id": "rt_2da5c87d-0384-50e8-a7f3-8d5646dd9e10",
"type": "payment",
"payment_id": "215d8da0-000f-50be-b000-0003308c89be",
"status": "pending",
"items": [
{
"description": "Сapybara",
"quantity": 5.000,
"amount": {
"value": "1500.30",
"currency": "RUB"
},
"vat_code": 2,
"payment_mode": "full_payment",
"payment_subject": "commodity"
}
],
"tax_system_code": 1
},
{
"id": "rt_37a5c87d-3984-51e8-a7f3-8de646d39ec15",
"type": "refund",
"refund_id": "234d8da0-000f-50be-b000-0003308c89be",
"status": "pending",
"items": [
{
"description": "Сapybara",
"quantity": 5.000,
"amount": {
"value": "2500.50",
"currency": "RUB"
},
"vat_code": 2,
"payment_mode": "full_payment",
"payment_subject": "commodity"
}
],
"tax_system_code": 1
}
],
"next_cursor": "rt_67a4g56e-8487-56d4-a7f3-7yu646s78ec48"
}

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

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

53
spec/fixtures/receipt_request.json поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,53 @@
{
"customer" : {
"full_name" : "Ivanov Ivan Ivanovich",
"email" : "email@email.ru",
"phone" : "79211234567",
"inn" : "6321341814"
},
"payment_id": "24b94598-000f-5000-9000-1b68e7b15f3f",
"type": "payment",
"send": "true",
"items": [
{
"description": "Наименование товара 1",
"quantity": 1.000,
"amount": {
"value": "14000.00",
"currency": "RUB"
},
"vat_code": "2",
"payment_mode": "full_payment",
"payment_subject": "commodity",
"country_of_origin_code": "CN"
},
{
"description": "Наименование товара 2",
"quantity": 1.000,
"amount": {
"value": "1000.00",
"currency": "RUB"
},
"vat_code": "2",
"payment_mode": "full_payment",
"payment_subject": "commodity",
"country_of_origin_code": "CN"
}
],
"settlements": [
{
"type": "prepayment",
"amount": {
"value": "8000.00",
"currency": "RUB"
}
},
{
"type": "prepayment",
"amount": {
"value": "7000.00",
"currency": "RUB"
}
}
]
}

49
spec/fixtures/receipt_response.json поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,49 @@
{
"id": "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9",
"type": "payment",
"payment_id": "215d8da0-000f-50be-b000-0003308c89be",
"status": "pending",
"items": [
{
"description": "Наименование товара 1",
"quantity": 1.000,
"amount": {
"value": "14000.00",
"currency": "RUB"
},
"vat_code": "2",
"payment_mode": "full_payment",
"payment_subject": "commodity",
"country_of_origin_code": "CN"
},
{
"description": "Наименование товара 2",
"quantity": 1.000,
"amount": {
"value": "1000.00",
"currency": "RUB"
},
"vat_code": "2",
"payment_mode": "full_payment",
"payment_subject": "commodity",
"country_of_origin_code": "CN"
}
],
"settlements": [
{
"type": "prepayment",
"amount": {
"value": "8000.00",
"currency": "RUB"
}
},
{
"type": "prepayment",
"amount": {
"value": "7000.00",
"currency": "RUB"
}
}
],
"tax_system_code": 1
}

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

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

@@ -44,7 +44,7 @@ RSpec.describe Yookassa::Payments do
end
describe "#create" do
let(:params) { JSON.parse(File.read("spec/fixtures/payment.json")) }
let(:params) { JSON.parse(File.read("spec/fixtures/payment_request.json")) }
let(:url) { "https://api.yookassa.ru/v3/payments" }
subject { payment.create(payment: params, idempotency_key: idempotency_key) }
@@ -100,7 +100,7 @@ RSpec.describe Yookassa::Payments do
end
describe "#list" do
let(:body) { File.read("spec/fixtures/payments_list_response.json") }
let(:body) { File.read("spec/fixtures/list_payment_response.json") }
let(:filters) do
{

76
spec/yookassa/receipts_spec.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,76 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Receipts do
let(:config) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:client) { Yookassa::Client.new(**config) }
let(:idempotency_key) { SecureRandom.hex(1) }
let(:receipt) { client.receipts }
let(:body) { File.read("spec/fixtures/receipt_response.json") }
before { stub_request(:any, //).to_return(body: body, headers: { "Content-Type" => "application/json" }) }
shared_examples "returns_receipt_object" do
it "returns success" do
expect(subject).to be_a Yookassa::Entity::Receipt
expect(subject.id).to eq "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9"
expect(subject.payment_id).to eq "215d8da0-000f-50be-b000-0003308c89be"
expect(subject.status).to eq "pending"
expect(subject.items.count).to eq 2
expect(subject.items.first).to be_kind_of Yookassa::Entity::Product
expect(subject.settlements.count).to eq 2
expect(subject.settlements.first).to be_kind_of Yookassa::Entity::Settlement
end
end
describe "#create" do
let(:payload) { JSON.parse(File.read("spec/fixtures/receipt_request.json")) }
let(:url) { "https://api.yookassa.ru/v3/receipts" }
subject { receipt.create(payload: payload, idempotency_key: idempotency_key) }
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like "returns_receipt_object"
end
describe "#find" do
let(:receipt_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/receipts/#{receipt_id}" }
subject { receipt.find(receipt_id: receipt_id) }
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it_behaves_like "returns_receipt_object"
end
describe "#list" do
let(:body) { File.read("spec/fixtures/list_receipt_response.json") }
let(:filters) do
{
limit: 20,
"created_at.gt": "2018-07-18T10:51:18.139Z"
}
end
let(:url) { "https://api.yookassa.ru/v3/receipts?limit=20&created_at.gt=2018-07-18T10:51:18.139Z" }
subject { receipt.list(filters: filters) }
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it "returns a collection" do
expect(subject).to be_a Yookassa::Entity::ReceiptCollection
end
end
end

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

@@ -25,7 +25,7 @@ RSpec.describe Yookassa::Refunds do
end
describe "#create" do
let(:payload) { JSON.parse(File.read("spec/fixtures/refund.json")) }
let(:payload) { JSON.parse(File.read("spec/fixtures/refund_request.json")) }
let(:url) { "https://api.yookassa.ru/v3/refunds" }
subject { refund.create(payload: payload, idempotency_key: idempotency_key) }
@@ -53,7 +53,7 @@ RSpec.describe Yookassa::Refunds do
end
describe "#list" do
let(:body) { File.read("spec/fixtures/refunds_list_response.json") }
let(:body) { File.read("spec/fixtures/list_refund_response.json") }
let(:filters) do
{

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

@@ -41,4 +41,16 @@ RSpec.describe Yookassa do
expect(Yookassa.payments).to be_a(Yookassa::Payments)
end
end
describe ".refunds" do
it "delegates request to client and creates an instance" do
expect(Yookassa.refunds).to be_a(Yookassa::Refunds)
end
end
describe ".receipts" do
it "delegates request to client and creates an instance" do
expect(Yookassa.receipts).to be_a(Yookassa::Receipts)
end
end
end