genesis_ruby 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/Gemfile.lock +50 -41
- data/README.md +20 -0
- data/VERSION +1 -1
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/order_by_fields.rb +33 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/response_fields.rb +67 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/transaction_types.rb +48 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/non_financial/sort_directions.rb +24 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/online_banking/payment_types.rb +3 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/refund/credit_reason_indicators.rb +30 -0
- data/lib/genesis_ruby/api/constants/transactions/parameters/refund/ticket_change_indicators.rb +24 -0
- data/lib/genesis_ruby/api/constants/transactions.rb +5 -0
- data/lib/genesis_ruby/api/mixins/requests/financial/bank_attributes.rb +26 -0
- data/lib/genesis_ruby/api/mixins/requests/financial/cards/installment_attributes.rb +18 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/billing_api/sort_attributes.rb +18 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/date_attributes.rb +64 -0
- data/lib/genesis_ruby/api/mixins/requests/non_financial/paging_attributes.rb +33 -0
- data/lib/genesis_ruby/api/mixins/requests/restricted_setter.rb +18 -0
- data/lib/genesis_ruby/api/request.rb +21 -1
- data/lib/genesis_ruby/api/requests/base/graphql.rb +60 -0
- data/lib/genesis_ruby/api/requests/base/versioned.rb +88 -0
- data/lib/genesis_ruby/api/requests/financial/capture.rb +6 -3
- data/lib/genesis_ruby/api/requests/financial/cards/authorize.rb +22 -19
- data/lib/genesis_ruby/api/requests/financial/cards/authorize3d.rb +26 -23
- data/lib/genesis_ruby/api/requests/financial/cards/sale.rb +22 -19
- data/lib/genesis_ruby/api/requests/financial/cards/sale3d.rb +26 -23
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/banco_do_brasil.rb +60 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/eps.rb +47 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_in.rb +55 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/idebit/pay_out.rb +28 -0
- data/lib/genesis_ruby/api/requests/financial/online_banking_payments/wechat.rb +53 -0
- data/lib/genesis_ruby/api/requests/financial/refund.rb +32 -12
- data/lib/genesis_ruby/api/requests/financial/sdd/recurring/init_recurring_sale.rb +23 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/recurring/recurring_sale.rb +28 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/refund.rb +26 -0
- data/lib/genesis_ruby/api/requests/financial/sdd/sale.rb +61 -0
- data/lib/genesis_ruby/api/requests/financial/wallets/alipay.rb +49 -0
- data/lib/genesis_ruby/api/requests/non_financial/billing_api/transactions.rb +203 -0
- data/lib/genesis_ruby/api/requests/non_financial/installments/fetch.rb +59 -0
- data/lib/genesis_ruby/api/requests/non_financial/installments/show.rb +58 -0
- data/lib/genesis_ruby/api/requests/non_financial/reconcile/date_range.rb +2 -50
- data/lib/genesis_ruby/builder.rb +7 -0
- data/lib/genesis_ruby/builders/graphql.rb +118 -0
- data/lib/genesis_ruby/builders/json.rb +30 -0
- data/lib/genesis_ruby/configuration.rb +11 -2
- data/lib/genesis_ruby/dependencies.rb +3 -0
- data/lib/genesis_ruby/network/adapter/net_http_adapter.rb +22 -6
- data/lib/genesis_ruby/network/base_network.rb +1 -14
- data/lib/genesis_ruby/parser.rb +3 -0
- data/lib/genesis_ruby/parsers/json.rb +18 -0
- data/lib/genesis_ruby/utils/formatters/response/formats/timestamp.rb +1 -1
- data/lib/genesis_ruby/utils/options/api_config.rb +28 -0
- data/lib/genesis_ruby/utils/options/network_adapter_config.rb +49 -14
- data/lib/genesis_ruby/utils/transactions/financial_types.rb +1 -1
- data/lib/genesis_ruby/utils/transactions/references/refundable_types.rb +1 -1
- data/lib/genesis_ruby/utils/transactions/wpf_types.rb +1 -1
- data/lib/genesis_ruby/version.rb +1 -1
- metadata +32 -3
- /data/lib/genesis_ruby/api/requests/financial/wallets/{pay_pay.rb → pay_pal.rb} +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module OnlineBankingPayments
|
6
|
+
# EPS is the main bank transfer payment method in Austria
|
7
|
+
class Eps < Base::Financial
|
8
|
+
|
9
|
+
include Api::Mixins::Requests::AddressInfoAttributes
|
10
|
+
include Api::Mixins::Requests::Financial::AsyncAttributes
|
11
|
+
include Api::Mixins::Requests::Financial::PaymentAttributes
|
12
|
+
include Api::Mixins::Requests::Financial::PendingPaymentAttributes
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# EPS transaction type
|
17
|
+
def transaction_type
|
18
|
+
Api::Constants::Transactions::EPS
|
19
|
+
end
|
20
|
+
|
21
|
+
# EPS field validations
|
22
|
+
def init_field_validations
|
23
|
+
required_fields.push *%i[transaction_id return_success_url return_failure_url
|
24
|
+
amount currency billing_country]
|
25
|
+
field_values.merge! currency: 'EUR',
|
26
|
+
billing_country: 'AT'
|
27
|
+
end
|
28
|
+
|
29
|
+
# EPS request structure
|
30
|
+
def payment_transaction_structure
|
31
|
+
payment_attributes_structure.merge(
|
32
|
+
{
|
33
|
+
return_success_url: return_success_url,
|
34
|
+
return_failure_url: return_failure_url,
|
35
|
+
return_pending_url: return_pending_url,
|
36
|
+
billing_address: billing_address_parameters_structure,
|
37
|
+
shipping_address: shipping_address_parameters_structure
|
38
|
+
}
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module OnlineBankingPayments
|
6
|
+
module Idebit
|
7
|
+
# iDebit PayIn transaction class
|
8
|
+
class PayIn < Requests::Base::Financial
|
9
|
+
|
10
|
+
include Api::Mixins::Requests::AddressInfoAttributes
|
11
|
+
include Api::Mixins::Requests::BirthDateAttributes
|
12
|
+
include Api::Mixins::Requests::Financial::PaymentAttributes
|
13
|
+
|
14
|
+
attr_reader :customer_account_id
|
15
|
+
|
16
|
+
# Customer account id parameter validation
|
17
|
+
def customer_account_id=(value)
|
18
|
+
limited_string attribute: __method__, value: value.to_s.empty? ? nil : value.to_s, max: 20
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
# iDebit PayIn transaction type
|
24
|
+
def transaction_type
|
25
|
+
Api::Constants::Transactions::IDEBIT_PAYIN
|
26
|
+
end
|
27
|
+
|
28
|
+
# iDebit PayIn field validations
|
29
|
+
def init_field_validations
|
30
|
+
required_fields.push *%i[transaction_id customer_account_id amount currency billing_country]
|
31
|
+
|
32
|
+
field_values.merge! billing_country: 'CA'
|
33
|
+
end
|
34
|
+
|
35
|
+
# iDebit PayIn parameters structure
|
36
|
+
def payment_transaction_structure
|
37
|
+
payment_attributes_structure.merge(
|
38
|
+
{
|
39
|
+
customer_email: customer_email,
|
40
|
+
customer_phone: customer_phone,
|
41
|
+
customer_account_id: customer_account_id,
|
42
|
+
birth_date: birth_date,
|
43
|
+
billing_address: billing_address_parameters_structure,
|
44
|
+
shipping_address: shipping_address_parameters_structure
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module OnlineBankingPayments
|
6
|
+
module Idebit
|
7
|
+
# iDebit PayOut transaction class
|
8
|
+
class PayOut < Requests::Base::Reference
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
# iDebit PayOut transaction type
|
13
|
+
def transaction_type
|
14
|
+
Constants::Transactions::IDEBIT_PAYOUT
|
15
|
+
end
|
16
|
+
|
17
|
+
# iDebit PayOut parameters structure
|
18
|
+
def reference_transaction_structure
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module OnlineBankingPayments
|
6
|
+
# WeChat Pay solution offers merchants access to the over 300 million
|
7
|
+
# WeChat users that have linked payment accounts to their WeChat account
|
8
|
+
class Wechat < Base::Financial
|
9
|
+
|
10
|
+
include Api::Mixins::Requests::AddressInfoAttributes
|
11
|
+
include Api::Mixins::Requests::Financial::PaymentAttributes
|
12
|
+
include Api::Mixins::Requests::Financial::AsyncAttributes
|
13
|
+
|
14
|
+
attr_accessor :product_code, :product_num, :product_desc
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
# WeChat transaction type
|
19
|
+
def transaction_type
|
20
|
+
Api::Constants::Transactions::WECHAT
|
21
|
+
end
|
22
|
+
|
23
|
+
# WeChat field validations
|
24
|
+
def init_field_validations
|
25
|
+
super
|
26
|
+
|
27
|
+
required_fields.push *%i[transaction_id usage return_success_url return_failure_url
|
28
|
+
amount currency billing_country]
|
29
|
+
end
|
30
|
+
|
31
|
+
# WeChat transaction request structure
|
32
|
+
def payment_transaction_structure # rubocop:disable Metrics/MethodLength
|
33
|
+
payment_attributes_structure.merge(
|
34
|
+
{
|
35
|
+
return_success_url: return_success_url,
|
36
|
+
return_failure_url: return_failure_url,
|
37
|
+
product_code: product_code,
|
38
|
+
product_num: product_num,
|
39
|
+
product_desc: product_desc,
|
40
|
+
customer_email: customer_email,
|
41
|
+
customer_phone: customer_phone,
|
42
|
+
billing_address: billing_address_parameters_structure,
|
43
|
+
shipping_address: shipping_address_parameters_structure
|
44
|
+
}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'genesis_ruby/api/constants/transactions/parameters/refund/bank_account_types'
|
2
|
+
require 'genesis_ruby/api/constants/transactions/parameters/refund/credit_reason_indicators'
|
3
|
+
require 'genesis_ruby/api/constants/transactions/parameters/refund/ticket_change_indicators'
|
2
4
|
|
5
|
+
# rubocop:disable Naming/VariableNumber
|
3
6
|
module GenesisRuby
|
4
7
|
module Api
|
5
8
|
module Requests
|
@@ -7,27 +10,34 @@ module GenesisRuby
|
|
7
10
|
# Refund reference transaction request
|
8
11
|
class Refund < Requests::Base::Reference
|
9
12
|
|
13
|
+
include Mixins::Requests::Financial::Cards::InstallmentAttributes
|
14
|
+
|
10
15
|
attr_accessor :beneficiary_bank_code, :beneficiary_name, :beneficiary_account_number, :bank, :bank_branch,
|
11
|
-
:bank_account
|
12
|
-
|
13
|
-
|
14
|
-
# The type of account
|
15
|
-
def bank_account_type=(value)
|
16
|
-
allowed_options attribute: __method__,
|
17
|
-
allowed: Api::Constants::Transactions::Parameters::Refund::BankAccountTypes.all,
|
18
|
-
value: value,
|
19
|
-
allow_empty: true
|
20
|
-
end
|
16
|
+
:bank_account, :bank_account_type, :credit_reason_indicator_1, :credit_reason_indicator_2,
|
17
|
+
:ticket_change_indicator
|
21
18
|
|
22
19
|
protected
|
23
20
|
|
21
|
+
# Field Validations
|
22
|
+
def init_field_validations
|
23
|
+
super
|
24
|
+
|
25
|
+
field_values.merge! bank_account_type: Constants::Transactions::Parameters::Refund::BankAccountTypes.all,
|
26
|
+
credit_reason_indicator_1: Constants::Transactions::Parameters::Refund::
|
27
|
+
CreditReasonIndicators.all,
|
28
|
+
credit_reason_indicator_2: Constants::Transactions::Parameters::Refund::
|
29
|
+
CreditReasonIndicators.all,
|
30
|
+
ticket_change_indicator: Constants::Transactions::Parameters::Refund::
|
31
|
+
TicketChangeIndicators.all
|
32
|
+
end
|
33
|
+
|
24
34
|
# Refund Transaction Request type
|
25
35
|
def transaction_type
|
26
36
|
Api::Constants::Transactions::REFUND
|
27
37
|
end
|
28
38
|
|
29
39
|
# Refund Transaction Request Structure
|
30
|
-
def reference_transaction_structure
|
40
|
+
def reference_transaction_structure # rubocop:disable Metrics/MethodLength
|
31
41
|
{
|
32
42
|
beneficiary_bank_code: beneficiary_bank_code,
|
33
43
|
beneficiary_name: beneficiary_name,
|
@@ -35,7 +45,16 @@ module GenesisRuby
|
|
35
45
|
bank: bank,
|
36
46
|
bank_branch: bank_branch,
|
37
47
|
bank_account: bank_account,
|
38
|
-
bank_account_type: bank_account_type
|
48
|
+
bank_account_type: bank_account_type,
|
49
|
+
installment_plan_id: installment_plan_id,
|
50
|
+
installment_plan_reference: installment_plan_reference,
|
51
|
+
travel: {
|
52
|
+
ticket: {
|
53
|
+
credit_reason_indicator_1: credit_reason_indicator_1,
|
54
|
+
credit_reason_indicator_2: credit_reason_indicator_2,
|
55
|
+
ticket_change_indicator: ticket_change_indicator
|
56
|
+
}
|
57
|
+
}
|
39
58
|
}
|
40
59
|
end
|
41
60
|
|
@@ -44,3 +63,4 @@ module GenesisRuby
|
|
44
63
|
end
|
45
64
|
end
|
46
65
|
end
|
66
|
+
# rubocop:enable Naming/VariableNumber
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module Sdd
|
6
|
+
module Recurring
|
7
|
+
# Sepa Direct Debit initial recurring
|
8
|
+
class InitRecurringSale < Api::Requests::Financial::Sdd::Sale
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
# SDD Sale transaction type
|
13
|
+
def transaction_type
|
14
|
+
Api::Constants::Transactions::SDD_INIT_RECURRING_SALE
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module Sdd
|
6
|
+
module Recurring
|
7
|
+
# Sepa Direct Debit Payment, popular in Germany.
|
8
|
+
class RecurringSale < Requests::Base::Reference
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
# SDD Recurring Sale transaction type
|
13
|
+
def transaction_type
|
14
|
+
Constants::Transactions::SDD_RECURRING_SALE
|
15
|
+
end
|
16
|
+
|
17
|
+
# Reference transaction request structure
|
18
|
+
def reference_transaction_structure
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module Sdd
|
6
|
+
# Sepa Direct Debit Payment, popular in Germany.
|
7
|
+
class Refund < Requests::Base::Reference
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
# SDD Refund transaction type
|
12
|
+
def transaction_type
|
13
|
+
Api::Constants::Transactions::SDD_REFUND
|
14
|
+
end
|
15
|
+
|
16
|
+
# Reference transaction request structure
|
17
|
+
def reference_transaction_structure
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module Sdd
|
6
|
+
# Sepa Direct Debit Payment, popular in Germany.
|
7
|
+
class Sale < Requests::Base::Financial
|
8
|
+
|
9
|
+
include Api::Mixins::Requests::CustomerAddress::BillingInfoAttributes
|
10
|
+
include Api::Mixins::Requests::CustomerAddress::ShippingInfoAttributes
|
11
|
+
include Api::Mixins::Requests::Financial::AsyncAttributes
|
12
|
+
include Api::Mixins::Requests::Financial::BankAttributes
|
13
|
+
include Api::Mixins::Requests::Financial::PaymentAttributes
|
14
|
+
include Api::Mixins::Requests::Financial::PendingPaymentAttributes
|
15
|
+
include Api::Mixins::Requests::Financial::DynamicDescriptorAttributes
|
16
|
+
|
17
|
+
attr_accessor :company_name, :mandate_reference
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
# SDD Sale transaction type
|
22
|
+
def transaction_type
|
23
|
+
Api::Constants::Transactions::SDD_SALE
|
24
|
+
end
|
25
|
+
|
26
|
+
# SDD field validation
|
27
|
+
def init_field_validations
|
28
|
+
super
|
29
|
+
|
30
|
+
required_fields.push *%i[
|
31
|
+
transaction_id usage amount currency iban billing_first_name billing_last_name billing_country
|
32
|
+
]
|
33
|
+
|
34
|
+
field_values.merge! currency: Api::Constants::Currencies::Iso4217.all.map(&:upcase),
|
35
|
+
billing_country: %w(AT BE CY EE FI FR DE GR IE IT LV LT LU MT MC NL PT SK SM SI ES)
|
36
|
+
end
|
37
|
+
|
38
|
+
# SDD Sale request structure
|
39
|
+
def payment_transaction_structure # rubocop:disable Metrics/MethodLength
|
40
|
+
payment_attributes_structure.merge(
|
41
|
+
{
|
42
|
+
iban: iban,
|
43
|
+
bic: bic,
|
44
|
+
company_name: company_name,
|
45
|
+
mandate_reference: mandate_reference,
|
46
|
+
return_success_url: return_success_url,
|
47
|
+
return_failure_url: return_failure_url,
|
48
|
+
return_pending_url: return_pending_url,
|
49
|
+
billing_address: billing_address_parameters_structure,
|
50
|
+
shipping_address: shipping_address_parameters_structure,
|
51
|
+
dynamic_descriptor_params: dynamic_descriptor_structure
|
52
|
+
}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module GenesisRuby
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
module Financial
|
5
|
+
module Wallets
|
6
|
+
# Alipay is an oBeP-style alternative payment method that allows you to pay directly with your ebank account.
|
7
|
+
class Alipay < Base::Financial
|
8
|
+
|
9
|
+
include Api::Mixins::Requests::AddressInfoAttributes
|
10
|
+
include Api::Mixins::Requests::BirthDateAttributes
|
11
|
+
include Api::Mixins::Requests::Financial::AsyncAttributes
|
12
|
+
include Api::Mixins::Requests::Financial::PaymentAttributes
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# Alipay transaction type
|
17
|
+
def transaction_type
|
18
|
+
Api::Constants::Transactions::ALIPAY
|
19
|
+
end
|
20
|
+
|
21
|
+
# Alipay Field Validations
|
22
|
+
def init_field_validations
|
23
|
+
super
|
24
|
+
|
25
|
+
required_fields.push *%i[transaction_id amount currency return_success_url return_failure_url]
|
26
|
+
field_values.merge! currency: %w(EUR CNY)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Alipay request structure
|
30
|
+
def payment_transaction_structure # rubocop:disable Metrics/MethodLength
|
31
|
+
payment_attributes_structure.merge(
|
32
|
+
{
|
33
|
+
return_success_url: return_success_url,
|
34
|
+
return_failure_url: return_failure_url,
|
35
|
+
customer_email: customer_email,
|
36
|
+
customer_phone: customer_phone,
|
37
|
+
birth_date: birth_date,
|
38
|
+
billing_address: billing_address_parameters_structure,
|
39
|
+
shipping_address: shipping_address_parameters_structure
|
40
|
+
}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/order_by_fields'
|
3
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/response_fields'
|
4
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/billing_api/transaction_types'
|
5
|
+
require 'genesis_ruby/api/constants/transactions/parameters/non_financial/sort_directions'
|
6
|
+
|
7
|
+
module GenesisRuby
|
8
|
+
module Api
|
9
|
+
module Requests
|
10
|
+
module NonFinancial
|
11
|
+
module BillingApi
|
12
|
+
# Billing Transactions API allows to programmatically retrieve information about billing transactions
|
13
|
+
# using given filters, pagination, and sort parameters.
|
14
|
+
class Transactions < Base::Graphql # rubocop:disable Metrics/ClassLength
|
15
|
+
|
16
|
+
include Api::Mixins::Requests::NonFinancial::BillingApi::SortAttributes
|
17
|
+
include Api::Mixins::Requests::NonFinancial::DateAttributes
|
18
|
+
include Api::Mixins::Requests::NonFinancial::PagingAttributes
|
19
|
+
|
20
|
+
def initialize(configuration, _builder_interface = nil)
|
21
|
+
super configuration
|
22
|
+
|
23
|
+
self.root_key = 'query'
|
24
|
+
self.request_name = 'billingTransactions'
|
25
|
+
self.request_path = 'billing_transactions'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Response Fields
|
29
|
+
def response_fields
|
30
|
+
@response_fields || []
|
31
|
+
end
|
32
|
+
|
33
|
+
# Response Fields
|
34
|
+
def response_fields=(value)
|
35
|
+
parse_array_of_strings attribute: __method__,
|
36
|
+
value: value,
|
37
|
+
allowed: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
38
|
+
ResponseFields.all
|
39
|
+
end
|
40
|
+
|
41
|
+
# List of billing transaction unique IDs. Max number of elements is 10000. Primary filter.
|
42
|
+
def unique_id
|
43
|
+
@unique_id || []
|
44
|
+
end
|
45
|
+
|
46
|
+
# List of billing transaction unique IDs. Max number of elements is 10000. Primary filter.
|
47
|
+
def unique_id=(value)
|
48
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
49
|
+
end
|
50
|
+
|
51
|
+
# List of billing statement names. Max number of elements allowed is 10. Primary filter.
|
52
|
+
def billing_statement
|
53
|
+
@billing_statement || []
|
54
|
+
end
|
55
|
+
|
56
|
+
# List of billing statement names. Max number of elements allowed is 10. Primary filter.
|
57
|
+
def billing_statement=(value)
|
58
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
59
|
+
end
|
60
|
+
|
61
|
+
# List of merchant transaction IDs. Max number of elements allowed is 10000. Primary filter.
|
62
|
+
def merchant_transaction_id
|
63
|
+
@merchant_transaction_id || []
|
64
|
+
end
|
65
|
+
|
66
|
+
# List of merchant transaction IDs. Max number of elements allowed is 10000. Primary filter.
|
67
|
+
def merchant_transaction_id=(value)
|
68
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
69
|
+
end
|
70
|
+
|
71
|
+
# List of master account names. Max number of elements allowed is 10. Secondary filter.
|
72
|
+
def master_account_name
|
73
|
+
@master_account_name || []
|
74
|
+
end
|
75
|
+
|
76
|
+
# List of master account names. Max number of elements allowed is 10. Secondary filter.
|
77
|
+
def master_account_name=(value)
|
78
|
+
parse_array_of_strings attribute: __method__, value: value, allow_empty: true
|
79
|
+
end
|
80
|
+
|
81
|
+
# List of billing transaction types. Max number of elements allowed is 10.
|
82
|
+
def transaction_type
|
83
|
+
@transaction_type || []
|
84
|
+
end
|
85
|
+
|
86
|
+
# List of billing transaction types. Max number of elements allowed is 10.
|
87
|
+
def transaction_type=(value)
|
88
|
+
parse_array_of_strings attribute: __method__,
|
89
|
+
value: value,
|
90
|
+
allowed: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
91
|
+
TransactionTypes.all,
|
92
|
+
allow_empty: true
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
|
97
|
+
# Billing API Authorization Token
|
98
|
+
def init_authorization_token
|
99
|
+
api_config.bearer_token = configuration.billing_api_token
|
100
|
+
end
|
101
|
+
|
102
|
+
# Billing API Transactions field validations
|
103
|
+
def init_field_validations
|
104
|
+
super
|
105
|
+
|
106
|
+
required_fields.push *%i[response_fields]
|
107
|
+
field_values.merge! sort_by_direction: Api::Constants::Transactions::Parameters::NonFinancial::
|
108
|
+
SortDirections.all,
|
109
|
+
sort_by_field: Api::Constants::Transactions::Parameters::NonFinancial::BillingApi::
|
110
|
+
OrderByFields.all
|
111
|
+
end
|
112
|
+
|
113
|
+
# Billing API Transactions custom validations
|
114
|
+
def check_requirements
|
115
|
+
super
|
116
|
+
|
117
|
+
validate_filters
|
118
|
+
validate_dates if @start_date || @end_date
|
119
|
+
validate_array_fields_size
|
120
|
+
end
|
121
|
+
|
122
|
+
# Transactions GraphQL query filters
|
123
|
+
def query_filters # rubocop:disable Metrics/MethodLength
|
124
|
+
{
|
125
|
+
filter: {
|
126
|
+
startDate: escape_argument(:start_date),
|
127
|
+
endDate: escape_argument(:end_date),
|
128
|
+
uniqueId: unique_id,
|
129
|
+
billingStatement: billing_statement,
|
130
|
+
merchantTransactionId: merchant_transaction_id,
|
131
|
+
masterAccountName: master_account_name,
|
132
|
+
transactionType: transaction_type
|
133
|
+
},
|
134
|
+
sort: {
|
135
|
+
byDirection: sort_by_direction,
|
136
|
+
byField: sort_by_field
|
137
|
+
},
|
138
|
+
paging: {
|
139
|
+
page: page,
|
140
|
+
perPage: per_page
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
# Transactions Response Fields
|
146
|
+
def query_response_fields
|
147
|
+
{
|
148
|
+
items: response_fields,
|
149
|
+
paging: paging_query_fields
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Format given timestamp string to GraphQL suitable argument
|
154
|
+
def escape_argument(attribute)
|
155
|
+
__send__(attribute).to_s.empty? ? nil : "\"#{__send__(attribute)}\""
|
156
|
+
end
|
157
|
+
|
158
|
+
# Validate Billing API Primary filters
|
159
|
+
def validate_filters
|
160
|
+
unless start_date.nil? && end_date.nil? && unique_id.empty? && billing_statement.empty? &&
|
161
|
+
merchant_transaction_id.empty?
|
162
|
+
return
|
163
|
+
end
|
164
|
+
|
165
|
+
raise ParameterError, 'At least one Primary filter is required!'
|
166
|
+
end
|
167
|
+
|
168
|
+
# Validate StartDate and EndDate
|
169
|
+
def validate_dates
|
170
|
+
message = 'If filter startDate is provided, then endDate should also be provided and vice versa.'
|
171
|
+
raise ParameterError, message unless @start_date.is_a?(DateTime) && @end_date.is_a?(DateTime)
|
172
|
+
|
173
|
+
raise ParameterError, 'EndData must be after StartDate!' if @start_date == @end_date
|
174
|
+
|
175
|
+
days_diff = @end_date - @start_date
|
176
|
+
message = 'Maximum difference between StartDate and EndDate is 7 days'
|
177
|
+
raise ParameterError, message unless days_diff >= 0 && days_diff <= 7
|
178
|
+
end
|
179
|
+
|
180
|
+
# Validate Billing API Array field requirements
|
181
|
+
def validate_array_fields_size
|
182
|
+
validate_array_size :unique_id, 10_000
|
183
|
+
validate_array_size :billing_statement, 10
|
184
|
+
validate_array_size :merchant_transaction_id, 10_000
|
185
|
+
validate_array_size :master_account_name, 10
|
186
|
+
validate_array_size :transaction_type, 10
|
187
|
+
end
|
188
|
+
|
189
|
+
# Validate Max size of the given Array attribute
|
190
|
+
def validate_array_size(attribute, size)
|
191
|
+
message = format 'Max array length on %{attribute} exceed allowed size of %{size}',
|
192
|
+
attribute: attribute,
|
193
|
+
size: size
|
194
|
+
|
195
|
+
raise ParameterError, message if __send__(attribute).length > size
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|