зеркало из
https://github.com/glebtv/yookassa.git
synced 2026-09-08 03:45:51 +03:00
Lists support added (#18)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
811ab20f05
Коммит
c5c1e8a54e
@@ -9,11 +9,11 @@ module Yookassa
|
|||||||
# First 6 digits of the card’s number (BIN). For payments with bank cards saved in YooMoney
|
# First 6 digits of the card’s 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.
|
# 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.
|
# 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]
|
# last4 [string, required]
|
||||||
# Last 4 digits of the card's number.
|
# Last 4 digits of the card's number.
|
||||||
attribute :last4, Types::String
|
attribute :last4, Types::Coercible::Integer
|
||||||
|
|
||||||
# expiry_month [string, required]
|
# expiry_month [string, required]
|
||||||
# Expiration date, month, MM.
|
# Expiration date, month, MM.
|
||||||
|
|||||||
27
lib/yookassa/entity/collection.rb
Обычный файл
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 Entity
|
||||||
module PaymentMethod
|
module PaymentMethod
|
||||||
class Base < Dry::Struct
|
class Base < Dry::Struct
|
||||||
# id [string, required]
|
|
||||||
# Payment method ID.
|
|
||||||
attribute :id, Types::String
|
attribute :id, Types::String
|
||||||
|
|
||||||
# saved [boolean, required]
|
|
||||||
# Saving payment methods allows conducting automatic recurring payments .
|
|
||||||
attribute :saved, Types::Bool
|
attribute :saved, Types::Bool
|
||||||
|
|
||||||
# title [string, optional]
|
|
||||||
# Payment method name.
|
|
||||||
attribute? :title, Types::String
|
attribute? :title, Types::String
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -90,18 +82,18 @@ module Yookassa
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
PaymentMethods = PaymentMethod::BankCard |
|
PaymentMethods = PaymentMethod::BankCard |
|
||||||
PaymentMethod::Alfabank |
|
PaymentMethod::Alfabank |
|
||||||
PaymentMethod::YooMoney |
|
PaymentMethod::YooMoney |
|
||||||
PaymentMethod::Sberbank |
|
PaymentMethod::Sberbank |
|
||||||
PaymentMethod::ApplePay |
|
PaymentMethod::ApplePay |
|
||||||
PaymentMethod::Cash |
|
PaymentMethod::Cash |
|
||||||
PaymentMethod::DirectCarrierBilling |
|
PaymentMethod::DirectCarrierBilling |
|
||||||
PaymentMethod::GooglePay |
|
PaymentMethod::GooglePay |
|
||||||
PaymentMethod::Installments |
|
PaymentMethod::Installments |
|
||||||
PaymentMethod::Qiwi |
|
PaymentMethod::Qiwi |
|
||||||
PaymentMethod::Tinkoff |
|
PaymentMethod::Tinkoff |
|
||||||
PaymentMethod::Wechat |
|
PaymentMethod::Wechat |
|
||||||
PaymentMethod::Webmoney
|
PaymentMethod::Webmoney
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ module Yookassa
|
|||||||
# Store's tax system. The parameter is only required if you use several tax systems.
|
# 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:
|
# Otherwise, the parameter is not specified. List of possible values:
|
||||||
# https://yookassa.ru/en/developers/54fz/parameters-values#tax-systems
|
# 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.
|
# 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.
|
# !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.
|
# User's email address for sending the receipt.
|
||||||
# !DEPRECATED PARAMETER: we recommend specifying the details in the receipt.customer.email parameter.
|
# !DEPRECATED PARAMETER: we recommend specifying the details in the receipt.customer.email parameter.
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ require_relative "./types"
|
|||||||
module Yookassa
|
module Yookassa
|
||||||
module Entity
|
module Entity
|
||||||
class Recipient < Dry::Struct
|
class Recipient < Dry::Struct
|
||||||
attribute :account_id, Types::String
|
attribute :account_id, Types::Coercible::Integer
|
||||||
attribute :gateway_id, Types::String
|
attribute :gateway_id, Types::Coercible::Integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ module Yookassa
|
|||||||
|
|
||||||
# description [string, optional]
|
# description [string, optional]
|
||||||
# Reason behind the refund.
|
# Reason behind the refund.
|
||||||
attribute :description, Types::String
|
attribute? :description, Types::String
|
||||||
|
|
||||||
# sources [array, optional]
|
# sources [array, optional]
|
||||||
# Information about money held for refunds: the amount to be held and the stores getting the refunds.
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "./entity/payment"
|
require_relative "./entity/payment"
|
||||||
|
require_relative "./entity/collection"
|
||||||
|
|
||||||
module Yookassa
|
module Yookassa
|
||||||
class Payments
|
class Payments
|
||||||
@@ -28,6 +29,11 @@ module Yookassa
|
|||||||
Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
|
Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list(filters: {})
|
||||||
|
data = api.get("payments", query: filters)
|
||||||
|
Entity::PaymentCollection.new(**data)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :api
|
attr_reader :api
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "./entity/refund"
|
require_relative "./entity/refund"
|
||||||
|
require_relative "./entity/collection"
|
||||||
|
|
||||||
module Yookassa
|
module Yookassa
|
||||||
class Refunds
|
class Refunds
|
||||||
@@ -18,6 +19,11 @@ module Yookassa
|
|||||||
Entity::Refund.new(**data.merge(idempotency_key: idempotency_key))
|
Entity::Refund.new(**data.merge(idempotency_key: idempotency_key))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list(filters: {})
|
||||||
|
data = api.get("refunds", query: filters)
|
||||||
|
Entity::RefundCollection.new(**data)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :api
|
attr_reader :api
|
||||||
|
|||||||
4
spec/fixtures/payment_response.json
поставляемый
4
spec/fixtures/payment_response.json
поставляемый
@@ -19,8 +19,8 @@
|
|||||||
"saved": false
|
"saved": false
|
||||||
},
|
},
|
||||||
"recipient": {
|
"recipient": {
|
||||||
"account_id": "54401",
|
"account_id": 54401,
|
||||||
"gateway_id": "289250"
|
"gateway_id": 289250
|
||||||
},
|
},
|
||||||
"refundable": false,
|
"refundable": false,
|
||||||
"test": true
|
"test": true
|
||||||
|
|||||||
42
spec/fixtures/payments_list_response.json
поставляемый
Обычный файл
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
поставляемый
Обычный файл
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"
|
it_behaves_like "returns_payment_object"
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -51,4 +51,28 @@ RSpec.describe Yookassa::Refunds do
|
|||||||
|
|
||||||
it_behaves_like "returns_refund_object"
|
it_behaves_like "returns_refund_object"
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user