From 2f5a64794d77f27fb626bb54591a4179129e336a Mon Sep 17 00:00:00 2001 From: Ivan Shamatov Date: Sun, 31 Oct 2021 23:19:28 +0300 Subject: [PATCH] Reworked payment_methods --- lib/yookassa/entity/card.rb | 41 ++++++++-- lib/yookassa/entity/payment.rb | 6 +- lib/yookassa/entity/payment_method.rb | 16 ---- lib/yookassa/entity/payment_methods.rb | 107 +++++++++++++++++++++++++ lib/yookassa/entity/recipient.rb | 12 +++ 5 files changed, 159 insertions(+), 23 deletions(-) delete mode 100644 lib/yookassa/entity/payment_method.rb create mode 100644 lib/yookassa/entity/payment_methods.rb create mode 100644 lib/yookassa/entity/recipient.rb diff --git a/lib/yookassa/entity/card.rb b/lib/yookassa/entity/card.rb index 599220e..20904e4 100644 --- a/lib/yookassa/entity/card.rb +++ b/lib/yookassa/entity/card.rb @@ -5,12 +5,41 @@ require_relative "./types" module Yookassa module Entity class Card < Dry::Struct - attribute :first6, Types::Integer - attribute :last4, Types::Integer - attribute :expiry_month, Types::Integer - attribute :expiry_year, Types::Integer - attribute :card_type, Types::String - attribute :source, Types::String + # first6 [string, optional] + # 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. + # For payments with bank cards saved in Apple Pay or Google Pay, the parameter contains Device Account Number. + attribute? :first6, Types::String + + # last4 [string, required] + # Last 4 digits of the card's number. + attribute :last4, Types::String + + # expiry_month [string, required] + # Expiration date, month, MM. + attribute :expiry_month, Types::Coercible::Integer + + # expiry_year [string, required] + # Expiration date, year, YYYY. + attribute :expiry_year, Types::Coercible::Integer + + # card_type [string, required] + # Type of bank card. Possible values: MasterCard (for Mastercard and Maestro cards), Visa (for Visa and Visa Electron cards), + # Mir, UnionPay, JCB, AmericanExpress, DinersClub, and Unknown. + attribute :card_type, Types::String.enum("MasterCard", "Visa", "Mir", "UnionPay", "JCB", "AmericanExpress", "DinersClub", "Unknown") + + # issuer_country [string, optional] + # Code of the country where the bank card was issued according to ISO-3166 alpha-2. Example: RU. + attribute? :issuer_country, Types::String + + # issuer_name [string, optional] + # Name of the issuing bank. + attribute? :issuer_name, Types::String + + # source [string, optional] + # Source of bank card details. Possible values: apple_pay, google_pay. + # For payments where the user selects a card saved in Apple Pay or Google Pay. + attribute? :source, Types::String.enum("apple_pay", "google_pay") end end end diff --git a/lib/yookassa/entity/payment.rb b/lib/yookassa/entity/payment.rb index f18e5b9..a60e869 100644 --- a/lib/yookassa/entity/payment.rb +++ b/lib/yookassa/entity/payment.rb @@ -2,8 +2,12 @@ require_relative "./types" require_relative "./amount" -require_relative "./payment_method" +require_relative "./payment_methods" require_relative "./confirmation" +require_relative "./recipient" +require_relative "./cancelation_details" +require_relative "./authorization_details" +require_relative "./transfer" module Yookassa module Entity diff --git a/lib/yookassa/entity/payment_method.rb b/lib/yookassa/entity/payment_method.rb deleted file mode 100644 index 47358cc..0000000 --- a/lib/yookassa/entity/payment_method.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative "./types" -require_relative "./card" - -module Yookassa - module Entity - class PaymentMethod < Dry::Struct - attribute :type, Types::String - attribute :id, Types::String - attribute :saved, Types::Bool - attribute? :card, Entity::Card - attribute? :title, Types::String - end - end -end diff --git a/lib/yookassa/entity/payment_methods.rb b/lib/yookassa/entity/payment_methods.rb new file mode 100644 index 0000000..5239d9f --- /dev/null +++ b/lib/yookassa/entity/payment_methods.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require_relative "./types" +require_relative "./card" + +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 + + class BankCard < Base + attribute :type, Types.Value('bank_card') + + # login [string, optional] + # User's login in Alfa-Click (linked phone number or the additional login). + attribute? :card, Entity::Card + end + + class Alfabank < Base + attribute :type, Types.Value('alfabank') + + # login [string, optional] + # User's login in Alfa-Click (linked phone number or the additional login). + attribute? :login, Types::String + end + + class YooMoney < Base + attribute :type, Types.Value('yoo_money') + + # account_number [string, optional] + # The number of the YooMoney wallet used for making the payment. + attribute? :account_number, Types::String + end + + class Sberbank < Base + attribute :type, Types.Value('sberbank') + + # phone [string, optional] + # TThe phone number specified during the registration process of the SberBank Online/SberPay account, + # specified in the ITU-T E.164 format, for example, 79000000000. + attribute? :phone, Types::String + end + + class ApplePay < Base + attribute :type, Types.Value('apple_pay') + end + + class Cash < Base + attribute :type, Types.Value('cash') + end + + class DirectCarrierBilling < Base + attribute :type, Types.Value('mobile_balance') + end + + class GooglePay < Base + attribute :type, Types.Value('google_pay') + end + + class Installments < Base + attribute :type, Types.Value('installments') + end + + class Qiwi < Base + attribute :type, Types.Value('qiwi') + end + + class Tinkoff < Base + attribute :type, Types.Value('tinkoff_bank') + end + + class Wechat < Base + attribute :type, Types.Value('wechat') + end + + class Webmoney < Base + attribute :type, Types.Value('webmoney') + 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 + end +end diff --git a/lib/yookassa/entity/recipient.rb b/lib/yookassa/entity/recipient.rb new file mode 100644 index 0000000..bc928c6 --- /dev/null +++ b/lib/yookassa/entity/recipient.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require_relative "./types" + +module Yookassa + module Entity + class Recipient < Dry::Struct + attribute :account_id, Types::String + attribute :gateway_id, Types::String + end + end +end