1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-03 17:55:51 +03:00
Этот коммит содержится в:
Ivan Shamatov
2021-11-09 01:01:13 +03:00
коммит произвёл GitHub
родитель 811ab20f05
Коммит c5c1e8a54e
13 изменённых файлов: 167 добавлений и 30 удалений

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

@@ -9,11 +9,11 @@ module Yookassa
# First 6 digits of the cards number (BIN). For payments with bank cards saved in YooMoney
# and other services, the specified BIN might not correspond with the last4, expiry_year, expiry_month values.
# For payments with bank cards saved in Apple Pay or Google Pay, the parameter contains Device Account Number.
attribute? :first6, Types::String
attribute? :first6, Types::Coercible::Integer
# last4 [string, required]
# Last 4 digits of the card's number.
attribute :last4, Types::String
attribute :last4, Types::Coercible::Integer
# expiry_month [string, required]
# Expiration date, month, MM.

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

@@ -0,0 +1,27 @@
# frozen_string_literal: true
require_relative "./types"
require_relative "./payment"
require_relative "./receipt"
require_relative "./refund"
module Yookassa
module Entity
class Collection < Dry::Struct
attribute :type, Types.Value("list")
attribute? :next_cursor, Types::String
end
class PaymentCollection < Collection
attribute :items, Types::Array.of(Payment)
end
class RefundCollection < Collection
attribute :items, Types::Array.of(Refund)
end
class ReceiptCollection < Collection
attribute :items, Types::Array.of(Receipt)
end
end
end

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

@@ -7,16 +7,8 @@ module Yookassa
module Entity
module PaymentMethod
class Base < Dry::Struct
# id [string, required]
# Payment method ID.
attribute :id, Types::String
# saved [boolean, required]
# Saving payment methods allows conducting automatic recurring payments .
attribute :saved, Types::Bool
# title [string, optional]
# Payment method name.
attribute? :title, Types::String
end
@@ -90,18 +82,18 @@ module Yookassa
end
end
PaymentMethods = PaymentMethod::BankCard |
PaymentMethod::Alfabank |
PaymentMethod::YooMoney |
PaymentMethod::Sberbank |
PaymentMethod::ApplePay |
PaymentMethod::Cash |
PaymentMethod::DirectCarrierBilling |
PaymentMethod::GooglePay |
PaymentMethod::Installments |
PaymentMethod::Qiwi |
PaymentMethod::Tinkoff |
PaymentMethod::Wechat |
PaymentMethod::Webmoney
PaymentMethods = PaymentMethod::BankCard |
PaymentMethod::Alfabank |
PaymentMethod::YooMoney |
PaymentMethod::Sberbank |
PaymentMethod::ApplePay |
PaymentMethod::Cash |
PaymentMethod::DirectCarrierBilling |
PaymentMethod::GooglePay |
PaymentMethod::Installments |
PaymentMethod::Qiwi |
PaymentMethod::Tinkoff |
PaymentMethod::Wechat |
PaymentMethod::Webmoney
end
end

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

@@ -17,11 +17,11 @@ module Yookassa
# 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
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::String
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.

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

@@ -5,8 +5,8 @@ require_relative "./types"
module Yookassa
module Entity
class Recipient < Dry::Struct
attribute :account_id, Types::String
attribute :gateway_id, Types::String
attribute :account_id, Types::Coercible::Integer
attribute :gateway_id, Types::Coercible::Integer
end
end
end

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

@@ -35,7 +35,7 @@ module Yookassa
# description [string, optional]
# Reason behind the refund.
attribute :description, Types::String
attribute? :description, Types::String
# sources [array, optional]
# Information about money held for refunds: the amount to be held and the stores getting the refunds.

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

@@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative "./entity/payment"
require_relative "./entity/collection"
module Yookassa
class Payments
@@ -28,6 +29,11 @@ module Yookassa
Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
end
def list(filters: {})
data = api.get("payments", query: filters)
Entity::PaymentCollection.new(**data)
end
private
attr_reader :api

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

@@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative "./entity/refund"
require_relative "./entity/collection"
module Yookassa
class Refunds
@@ -18,6 +19,11 @@ module Yookassa
Entity::Refund.new(**data.merge(idempotency_key: idempotency_key))
end
def list(filters: {})
data = api.get("refunds", query: filters)
Entity::RefundCollection.new(**data)
end
private
attr_reader :api

4
spec/fixtures/payment_response.json поставляемый
Просмотреть файл

@@ -19,8 +19,8 @@
"saved": false
},
"recipient": {
"account_id": "54401",
"gateway_id": "289250"
"account_id": 54401,
"gateway_id": 289250
},
"refundable": false,
"test": true

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

@@ -0,0 +1,42 @@
{
"type": "list",
"items": [
{
"id": "22e12f66-000f-5000-8000-18db351245c7",
"status": "waiting_for_capture",
"paid": true,
"amount": {
"value": 2,
"currency": "RUB"
},
"created_at": "2018-07-18T10:51:18.139Z",
"description": "Заказ №72",
"expires_at": "2018-07-25T10:52:00.233Z",
"metadata": {
},
"payment_method": {
"type": "bank_card",
"id": "22e12f66-000f-5000-8000-18db351245c7",
"saved": false,
"card": {
"first6": 555555,
"last4": 4444,
"expiry_month": 7,
"expiry_year": 2022,
"card_type": "MasterCard",
"issuer_country": "RU",
"issuer_name": "Sberbank"
},
"title": "Bank card *4444"
},
"recipient": {
"account_id": 100001,
"gateway_id": 1000001
},
"refundable": false,
"test": false
}
],
"next_cursor": "37a5c87d-3984-51e8-a7f3-8de646d39ec15"
}

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

@@ -0,0 +1,16 @@
{
"type": "list",
"items": [
{
"id": "216749f7-0016-50be-b000-078d43a63ae4",
"status": "succeeded",
"amount": {
"value": 1,
"currency": "RUB"
},
"created_at": "2017-10-04T19:27:51.407Z",
"payment_id": "216749da-000f-50be-b000-096747fad91e"
}
],
"next_cursor": "416746f8-0016-50be-b000-078d43a4578"
}

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

@@ -98,4 +98,28 @@ RSpec.describe Yookassa::Payments do
it_behaves_like "returns_payment_object"
end
describe "#list" do
let(:body) { File.read("spec/fixtures/payments_list_response.json") }
let(:filters) do
{
limit: 20,
"created_at.gt": "2018-07-18T10:51:18.139Z"
}
end
let(:url) { "https://api.yookassa.ru/v3/payments?limit=20&created_at.gt=2018-07-18T10:51:18.139Z" }
subject { payment.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::PaymentCollection
end
end
end

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

@@ -51,4 +51,28 @@ RSpec.describe Yookassa::Refunds do
it_behaves_like "returns_refund_object"
end
describe "#list" do
let(:body) { File.read("spec/fixtures/refunds_list_response.json") }
let(:filters) do
{
limit: 20,
"created_at.gt": "2018-07-18T10:51:18.139Z"
}
end
let(:url) { "https://api.yookassa.ru/v3/refunds?limit=20&created_at.gt=2018-07-18T10:51:18.139Z" }
subject { refund.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::RefundCollection
end
end
end