lunixi-sdk 1.2.2 → 1.3.1
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 +45 -0
- data/README.md +262 -9
- data/README.tr.md +266 -7
- data/lib/lunixi/bank_connect.rb +340 -0
- data/lib/lunixi/bank_connect_filters.rb +114 -0
- data/lib/lunixi/bank_connect_values.rb +205 -0
- data/lib/lunixi/bank_transfer.rb +106 -0
- data/lib/lunixi/card_requests.rb +150 -0
- data/lib/lunixi/client.rb +57 -16
- data/lib/lunixi/direct_method_payment_request.rb +243 -0
- data/lib/lunixi/enabled_installments.rb +28 -0
- data/lib/lunixi/errors.rb +69 -3
- data/lib/lunixi/fraud.rb +81 -5
- data/lib/lunixi/identity.rb +94 -0
- data/lib/lunixi/identity_values.rb +28 -0
- data/lib/lunixi/insurance.rb +294 -0
- data/lib/lunixi/insurance_request.rb +134 -0
- data/lib/lunixi/insurance_values.rb +200 -0
- data/lib/lunixi/kyc.rb +189 -0
- data/lib/lunixi/kyc_values.rb +158 -0
- data/lib/lunixi/marketplace.rb +264 -0
- data/lib/lunixi/marketplace_values.rb +86 -0
- data/lib/lunixi/method_fields.rb +142 -0
- data/lib/lunixi/money.rb +7 -4
- data/lib/lunixi/payment_link_filters.rb +32 -0
- data/lib/lunixi/payment_link_image_rules.rb +85 -0
- data/lib/lunixi/payment_link_rules.rb +132 -0
- data/lib/lunixi/payment_link_values.rb +134 -0
- data/lib/lunixi/payment_links.rb +152 -0
- data/lib/lunixi/payment_values.rb +86 -0
- data/lib/lunixi/payments.rb +154 -5
- data/lib/lunixi/physical_pos.rb +183 -0
- data/lib/lunixi/physical_pos_card_data.rb +117 -0
- data/lib/lunixi/physical_pos_card_number.rb +65 -0
- data/lib/lunixi/physical_pos_device_identity.rb +44 -0
- data/lib/lunixi/physical_pos_filters.rb +58 -0
- data/lib/lunixi/physical_pos_gateway.rb +153 -0
- data/lib/lunixi/physical_pos_identifiers.rb +62 -0
- data/lib/lunixi/physical_pos_management.rb +326 -0
- data/lib/lunixi/physical_pos_money.rb +46 -0
- data/lib/lunixi/physical_pos_request.rb +126 -0
- data/lib/lunixi/physical_pos_responses.rb +102 -0
- data/lib/lunixi/physical_pos_results.rb +52 -0
- data/lib/lunixi/physical_pos_settlement_policies.rb +71 -0
- data/lib/lunixi/physical_pos_value.rb +43 -0
- data/lib/lunixi/physical_pos_values.rb +203 -0
- data/lib/lunixi/physical_pos_webhook.rb +147 -0
- data/lib/lunixi/product_webhooks.rb +106 -0
- data/lib/lunixi/promissory_note.rb +155 -0
- data/lib/lunixi/reference.rb +41 -0
- data/lib/lunixi/route_request.rb +121 -0
- data/lib/lunixi/route_response.rb +101 -0
- data/lib/lunixi/route_table.rb +128 -0
- data/lib/lunixi/route_value.rb +60 -0
- data/lib/lunixi/sanction.rb +244 -0
- data/lib/lunixi/sanction_values.rb +132 -0
- data/lib/lunixi/split_payment.rb +145 -0
- data/lib/lunixi/subscription_resources.rb +355 -0
- data/lib/lunixi/subscription_values.rb +220 -0
- data/lib/lunixi/subscriptions.rb +202 -0
- data/lib/lunixi/version.rb +1 -1
- data/lib/lunixi/wallet.rb +153 -0
- data/lib/lunixi/wallet_resources.rb +402 -0
- data/lib/lunixi/wallet_routes.rb +123 -0
- data/lib/lunixi/wallet_values.rb +71 -0
- data/lib/lunixi/wire_money.rb +67 -0
- data/lib/lunixi.rb +57 -0
- metadata +58 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Method blocks a non-card split leg can carry. Meal card, open banking, shopping loan and bank
|
|
5
|
+
# transfer cannot be split payment legs.
|
|
6
|
+
SPLIT_LEG_BLOCK_FIELDS = %w[mobileBilling wallet promissoryNote].freeze
|
|
7
|
+
|
|
8
|
+
# Fields of one split leg.
|
|
9
|
+
SPLIT_PAYMENT_LEG_FIELDS = (%w[paymentMethod cardToken amount force3D installment installmentQuoteToken] + SPLIT_LEG_BLOCK_FIELDS).freeze
|
|
10
|
+
|
|
11
|
+
# Filters of payments.list_splits (GET /payments/split).
|
|
12
|
+
LIST_SPLIT_PAYMENTS_FILTERS = %w[status currency createdFrom createdTo orderId ownerRef limit after].freeze
|
|
13
|
+
|
|
14
|
+
# Put this key into a webhook endpoint's event types to also receive the events of each leg. It is
|
|
15
|
+
# not an event type and payment.* does not include it.
|
|
16
|
+
SPLIT_LEG_EVENTS_SUBSCRIPTION = 'payment.split.leg_events'
|
|
17
|
+
|
|
18
|
+
# Status of a split payment (status).
|
|
19
|
+
module SplitPaymentStatus
|
|
20
|
+
COMPOSING = 'COMPOSING'
|
|
21
|
+
AUTHORIZING = 'AUTHORIZING'
|
|
22
|
+
AWAITING_3DS = 'AWAITING_3DS'
|
|
23
|
+
AWAITING_ACTION = 'AWAITING_ACTION'
|
|
24
|
+
AWAITING_CREDIT_APPROVAL = 'AWAITING_CREDIT_APPROVAL'
|
|
25
|
+
AWAITING_REPLACEMENT_CARD = 'AWAITING_REPLACEMENT_CARD'
|
|
26
|
+
AUTHORIZED = 'AUTHORIZED'
|
|
27
|
+
CAPTURING = 'CAPTURING'
|
|
28
|
+
COMPLETED = 'COMPLETED'
|
|
29
|
+
COMPENSATING = 'COMPENSATING'
|
|
30
|
+
VOIDED = 'VOIDED'
|
|
31
|
+
FAILED = 'FAILED'
|
|
32
|
+
RECONCILIATION_REQUIRED = 'RECONCILIATION_REQUIRED'
|
|
33
|
+
|
|
34
|
+
ALL = [COMPOSING, AUTHORIZING, AWAITING_3DS, AWAITING_ACTION, AWAITING_CREDIT_APPROVAL, AWAITING_REPLACEMENT_CARD,
|
|
35
|
+
AUTHORIZED, CAPTURING, COMPLETED, COMPENSATING, VOIDED, FAILED, RECONCILIATION_REQUIRED].freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Webhook events of a split payment. The result of the main payment arrives as payment.captured /
|
|
39
|
+
# payment.failed with settlementMode SPLIT; deliver the order on that event.
|
|
40
|
+
module SplitPaymentEvents
|
|
41
|
+
COMPLETED = 'payment.split.completed'
|
|
42
|
+
VOIDED = 'payment.split.voided'
|
|
43
|
+
COMPENSATING = 'payment.split.compensating'
|
|
44
|
+
# The non-reversible leg's result is being confirmed; card holds are kept until then.
|
|
45
|
+
OUTCOME_PENDING = 'payment.split.outcome_pending'
|
|
46
|
+
# The order could not be fully collected.
|
|
47
|
+
RECONCILIATION_REQUIRED = 'payment.split.reconciliation_required'
|
|
48
|
+
# Leg event: a charged leg is being refunded and retried until it succeeds.
|
|
49
|
+
LEG_REFUND_PENDING = 'payment.split.leg_refund_pending'
|
|
50
|
+
|
|
51
|
+
ALL = [COMPLETED, VOIDED, COMPENSATING, OUTCOME_PENDING, RECONCILIATION_REQUIRED, LEG_REFUND_PENDING].freeze
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Leg and list rules of the split payment endpoints.
|
|
55
|
+
module SplitPaymentRules
|
|
56
|
+
LIST_MAX_LIMIT = 100
|
|
57
|
+
LIST_MAX_VALUES = 20
|
|
58
|
+
FILTER_TEXT_MAX_LENGTH = 200
|
|
59
|
+
AFTER_MAX_LENGTH = 2048
|
|
60
|
+
ISO_8601 = /\A\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:?\d{2})?)?\z/
|
|
61
|
+
|
|
62
|
+
module_function
|
|
63
|
+
|
|
64
|
+
# A card leg (paymentMethod omitted, empty or CARD) carries no method block; a non-card leg carries
|
|
65
|
+
# only its own block, which must be one of SPLIT_LEG_BLOCK_FIELDS.
|
|
66
|
+
def leg!(leg, path)
|
|
67
|
+
excluded = (METHOD_BLOCK_FIELDS - SPLIT_LEG_BLOCK_FIELDS).find { |field| !leg[field].nil? }
|
|
68
|
+
raise ConfigurationError, "#{path}: the '#{excluded}' block cannot be sent in a split payment leg" if excluded
|
|
69
|
+
|
|
70
|
+
method = leg['paymentMethod']
|
|
71
|
+
if [nil, '', PaymentMethod::CARD].include?(method)
|
|
72
|
+
block = SPLIT_LEG_BLOCK_FIELDS.find { |field| !leg[field].nil? }
|
|
73
|
+
raise ConfigurationError, "#{path} is a card leg and cannot carry the '#{block}' block" if block
|
|
74
|
+
|
|
75
|
+
return
|
|
76
|
+
end
|
|
77
|
+
method_leg!(leg, path, MethodFields.normalize_payment_method(method))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Query of GET /payments/split; status and currency may be a value or a list (repeated parameters).
|
|
81
|
+
def list_query!(filters)
|
|
82
|
+
data = filters.transform_keys(&:to_s)
|
|
83
|
+
unknown = data.keys - LIST_SPLIT_PAYMENTS_FILTERS
|
|
84
|
+
raise ConfigurationError, "list_splits does not take #{unknown.join(', ')}; filters: #{LIST_SPLIT_PAYMENTS_FILTERS.join(', ')}" unless unknown.empty?
|
|
85
|
+
|
|
86
|
+
LIST_SPLIT_PAYMENTS_FILTERS.each_with_object({}) do |key, query|
|
|
87
|
+
value = data[key]
|
|
88
|
+
next if value.nil? || value == ''
|
|
89
|
+
|
|
90
|
+
query[key] = filter_value!(key, value)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def method_leg!(leg, path, method)
|
|
95
|
+
block_name = MethodFields.block_name_of(method)
|
|
96
|
+
unless SPLIT_LEG_BLOCK_FIELDS.include?(block_name)
|
|
97
|
+
raise ConfigurationError, "#{path}: paymentMethod #{method} cannot be a split leg; a non-card leg carries one of #{SPLIT_LEG_BLOCK_FIELDS.join(', ')}"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
other = SPLIT_LEG_BLOCK_FIELDS.find { |field| field != block_name && !leg[field].nil? }
|
|
101
|
+
raise ConfigurationError, "#{path}: paymentMethod #{method} takes only the '#{block_name}' block" if other
|
|
102
|
+
|
|
103
|
+
block = leg[block_name]
|
|
104
|
+
raise ConfigurationError, "#{path}: paymentMethod #{method} requires the '#{block_name}' block" unless block.is_a?(Hash)
|
|
105
|
+
|
|
106
|
+
fields = block.except('providerCode')
|
|
107
|
+
MethodFields.provider_code!(block['providerCode']) unless block['providerCode'].nil?
|
|
108
|
+
MethodFields.method_fields!(fields, "#{path}.#{block_name}")
|
|
109
|
+
return unless method == PaymentMethod::PROMISSORY_NOTE
|
|
110
|
+
raise ConfigurationError, "#{path}.#{block_name}.schedule cannot be sent in a split leg; use noteCount" unless fields['schedule'].nil?
|
|
111
|
+
|
|
112
|
+
PromissoryNotePlan.note_count!(fields['noteCount'], "#{path}.#{block_name}.noteCount")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def filter_value!(key, value)
|
|
116
|
+
case key
|
|
117
|
+
when 'status' then values!(key, value) { |entry| SplitPaymentStatus::ALL.include?(entry) }
|
|
118
|
+
when 'currency' then values!(key, value) { |entry| entry.is_a?(String) && entry.match?(/\A[A-Z]{3}\z/) }
|
|
119
|
+
when 'createdFrom', 'createdTo'
|
|
120
|
+
raise ConfigurationError, "#{key} must be an ISO 8601 date-time" unless value.is_a?(String) && value.match?(ISO_8601)
|
|
121
|
+
|
|
122
|
+
value
|
|
123
|
+
when 'limit'
|
|
124
|
+
raise ConfigurationError, "limit must be an integer from 1 to #{LIST_MAX_LIMIT}" unless value.is_a?(Integer) && value.between?(1, LIST_MAX_LIMIT)
|
|
125
|
+
|
|
126
|
+
value.to_s
|
|
127
|
+
else
|
|
128
|
+
max = key == 'after' ? AFTER_MAX_LENGTH : FILTER_TEXT_MAX_LENGTH
|
|
129
|
+
return value if value.is_a?(String) && !value.strip.empty? && value.length <= max
|
|
130
|
+
|
|
131
|
+
raise ConfigurationError, "#{key} must be a nonempty string of at most #{max} characters"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def values!(key, value, &)
|
|
136
|
+
values = Array(value)
|
|
137
|
+
raise ConfigurationError, "#{key} takes 1 to #{LIST_MAX_VALUES} values" if values.empty? || values.size > LIST_MAX_VALUES
|
|
138
|
+
raise ConfigurationError, "#{key} contains an invalid value" unless values.all?(&)
|
|
139
|
+
|
|
140
|
+
values
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
private_class_method :method_leg!, :filter_value!, :values!
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# subscriptions.plans: the templates a subscription is created against.
|
|
5
|
+
class SubscriptionPlans
|
|
6
|
+
def initialize(routes)
|
|
7
|
+
@routes = routes
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# { productId, code, name, price, currency, billing, description?, trialPeriodDays?,
|
|
11
|
+
# maxDunningAttempts?, dunningScheduleDays?, gracePeriodDays?, metadata? }. price is a minor-unit
|
|
12
|
+
# string ("0" for a free plan); billing is { frequency, interval?, byMonthDay?, byWeekDay?, timezone?,
|
|
13
|
+
# lastDayOfMonthFix?, count? } (interval defaults to 1).
|
|
14
|
+
def create(request, idempotency_key: nil)
|
|
15
|
+
@routes.data('plans.create', body: SubscriptionRules.plan!(request), idempotency_key: idempotency_key)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(plan_id)
|
|
19
|
+
@routes.data('plans.get', params: { 'planId' => plan_id })
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Filters: productId, includeArchived, pageSize, pageToken.
|
|
23
|
+
def list(**filters)
|
|
24
|
+
@routes.token_page('plans.list', query: filters)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def iterate(**filters, &block)
|
|
28
|
+
RouteResponse.each_item(filters, block, :pageToken) { |query| list(**query) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Price, billing, metadata ...; a price is a minor-unit string.
|
|
32
|
+
def update(plan_id, changes)
|
|
33
|
+
@routes.data('plans.update', params: { 'planId' => plan_id }, body: changes)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def archive(plan_id)
|
|
37
|
+
@routes.data('plans.archive', params: { 'planId' => plan_id })
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def translations(plan_id)
|
|
41
|
+
@routes.data('plans.translations', params: { 'planId' => plan_id })
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def upsert_translation(plan_id, locale, translation)
|
|
45
|
+
@routes.data('plans.upsertTranslation', params: { 'planId' => plan_id, 'locale' => locale }, body: translation)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# subscriptions.customers, upserted by your own externalId (one stable customer per user).
|
|
50
|
+
class SubscriptionCustomers
|
|
51
|
+
def initialize(routes)
|
|
52
|
+
@routes = routes
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# { externalId, email?, name?, phone?, locale?, metadata? }.
|
|
56
|
+
def upsert(request, idempotency_key: nil)
|
|
57
|
+
@routes.data('customers.upsert', body: request, idempotency_key: idempotency_key)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def get(customer_id)
|
|
61
|
+
@routes.data('customers.get', params: { 'customerId' => customer_id })
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def get_by_external_id(external_id)
|
|
65
|
+
@routes.data('customers.getByExternalId', params: { 'externalId' => external_id })
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Filters: search, includeArchived, pageSize, pageToken.
|
|
69
|
+
def list(**filters)
|
|
70
|
+
@routes.token_page('customers.list', query: filters)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def iterate(**filters, &block)
|
|
74
|
+
RouteResponse.each_item(filters, block, :pageToken) { |query| list(**query) }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def credit_balance(customer_id)
|
|
78
|
+
@routes.data('customers.creditBalance', params: { 'customerId' => customer_id })
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Grants or deducts credit: { amountMinor, currency, reason, type, ... } (amountMinor a minor-unit
|
|
82
|
+
# string).
|
|
83
|
+
def adjust_credit(customer_id, adjustment)
|
|
84
|
+
@routes.data('customers.adjustCredit', params: { 'customerId' => customer_id }, body: adjustment)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def archive(customer_id)
|
|
88
|
+
@routes.data('customers.archive', params: { 'customerId' => customer_id })
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# subscriptions.cards: saved cards for automatic charges. A card is added from the checkout SDK's
|
|
93
|
+
# paymentMethodToken; a card number or security code is never sent (the field is refused and the error
|
|
94
|
+
# names only the field).
|
|
95
|
+
class SubscriptionCards
|
|
96
|
+
def initialize(routes)
|
|
97
|
+
@routes = routes
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# { customerId, paymentMethodToken, brand?, last4?, bin?, expireMonth?, expireYear?, cardholderName?,
|
|
101
|
+
# isDefault?, nickname?, verificationMode?, supportedCurrencies? }.
|
|
102
|
+
def add(request, idempotency_key: nil)
|
|
103
|
+
@routes.data('cards.add', body: SubscriptionRules.card!(request), idempotency_key: idempotency_key)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def get(card_id)
|
|
107
|
+
@routes.data('cards.get', params: { 'cardId' => card_id })
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# A customer's cards.
|
|
111
|
+
def list(customer_id, include_inactive: false, page_token: nil, page_size: nil)
|
|
112
|
+
query = { 'customerId' => RouteValue.text!(customer_id, 'customerId'), 'includeInactive' => include_inactive,
|
|
113
|
+
'pageToken' => page_token, 'pageSize' => page_size }
|
|
114
|
+
@routes.token_page('cards.list', query: RouteRequest.compact(query))
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def iterate(customer_id, include_inactive: false, page_size: nil, &block)
|
|
118
|
+
filters = RouteRequest.compact(include_inactive: include_inactive, page_size: page_size)
|
|
119
|
+
RouteResponse.each_item(filters, block, :page_token) { |query| list(customer_id, **query) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def set_default(card_id) # rubocop:disable Naming/AccessorMethodName -- catalog operation cards.setDefault
|
|
123
|
+
@routes.data('cards.setDefault', params: { 'cardId' => card_id })
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def deactivate(card_id, reason: nil)
|
|
127
|
+
@routes.data('cards.deactivate', params: { 'cardId' => card_id },
|
|
128
|
+
body: RouteRequest.compact('reason' => RouteValue.optional_text(reason, 'reason')))
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Verifies a saved card (a small authorisation or a 3-D check); options as the gateway documents them.
|
|
132
|
+
def verify(card_id, options = {})
|
|
133
|
+
@routes.data('cards.verify', params: { 'cardId' => card_id }, body: options)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Card metadata (label, expiry, billing ...); never a card number.
|
|
137
|
+
def update(card_id, changes)
|
|
138
|
+
@routes.data('cards.update', params: { 'cardId' => card_id }, body: changes)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# subscriptions.invoices: billing history, void and charge retry.
|
|
143
|
+
class SubscriptionInvoices
|
|
144
|
+
def initialize(routes)
|
|
145
|
+
@routes = routes
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Filters: subscriptionId, status, pageSize, pageToken.
|
|
149
|
+
def list(**filters)
|
|
150
|
+
@routes.token_page('invoices.list', query: filters)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def iterate(**filters, &block)
|
|
154
|
+
RouteResponse.each_item(filters, block, :pageToken) { |query| list(**query) }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def get(invoice_id)
|
|
158
|
+
@routes.data('invoices.get', params: { 'invoiceId' => invoice_id })
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def void(invoice_id, reason: nil)
|
|
162
|
+
@routes.data('invoices.void', params: { 'invoiceId' => invoice_id },
|
|
163
|
+
body: RouteRequest.compact('reason' => RouteValue.optional_text(reason, 'reason')))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def retry_charge(invoice_id, idempotency_key: nil)
|
|
167
|
+
@routes.data('invoices.retryCharge', params: { 'invoiceId' => invoice_id }, idempotency_key: idempotency_key)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# subscriptions.portal: the customer portal. Embedded: create_sdk_session mints an origin-bound session
|
|
172
|
+
# for the browser portal SDK (origin must be allow-listed). Hosted: create_portal_link returns a link
|
|
173
|
+
# whose token opens the hosted portal (Lunixi::Subscriptions.portal_url(link)); the customer verifies
|
|
174
|
+
# with a one-time code.
|
|
175
|
+
class SubscriptionPortal
|
|
176
|
+
def initialize(routes)
|
|
177
|
+
@routes = routes
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Returns { portalToken, sessionProof, proofNonce, proofExpiresAt, ... } (the gateway answers at the
|
|
181
|
+
# envelope root); hand those four to the browser.
|
|
182
|
+
def create_sdk_session(customer_id, origin, sdk_mode: nil, portal_link_id: nil)
|
|
183
|
+
RouteValue.one_of!(sdk_mode, SubscriptionPortalSdkMode::ALL, 'sdkMode') unless sdk_mode.nil? || sdk_mode == ''
|
|
184
|
+
body = RouteRequest.compact('customerId' => RouteValue.text!(customer_id, 'customerId'), 'origin' => RouteValue.text!(origin, 'origin'),
|
|
185
|
+
'sdkMode' => RouteValue.optional_text(sdk_mode, 'sdkMode'),
|
|
186
|
+
'portalLinkId' => RouteValue.optional_text(portal_link_id, 'portalLinkId'))
|
|
187
|
+
session = RouteResponse.merge_root(@routes.call('portal.createSdkSession', body: body))
|
|
188
|
+
session['proofNonce'] = session['nonce'] if !session.key?('proofNonce') && session.key?('nonce')
|
|
189
|
+
session['proofExpiresAt'] = session['expiresAt'] if !session.key?('proofExpiresAt') && session.key?('expiresAt')
|
|
190
|
+
session
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# options: allowedPlanIds, defaultPlanId, permissions, sessionDurationMinutes, expiresAt,
|
|
194
|
+
# requireEmailVerification ...
|
|
195
|
+
def create_portal_link(customer_id, options = {})
|
|
196
|
+
body = RouteRequest.wire_hash!(options, 'create_portal_link options').merge('customerId' => RouteValue.text!(customer_id, 'customerId'))
|
|
197
|
+
@routes.data('portal.createPortalLink', body: body)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Filters: customerId, status, limit.
|
|
201
|
+
def list_links(**filters)
|
|
202
|
+
@routes.page('portal.listLinks', query: filters)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def get_link(link_id)
|
|
206
|
+
@routes.data('portal.getLink', params: { 'linkId' => link_id })
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def update_link(link_id, changes)
|
|
210
|
+
@routes.data('portal.updateLink', params: { 'linkId' => link_id }, body: changes)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def revoke_link(link_id, reason: nil)
|
|
214
|
+
@routes.data('portal.revokeLink', params: { 'linkId' => link_id },
|
|
215
|
+
body: RouteRequest.compact('reason' => RouteValue.optional_text(reason, 'reason')))
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def link_activity(link_id)
|
|
219
|
+
@routes.data('portal.linkActivity', params: { 'linkId' => link_id })
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Emails a portal invite: { customerId, email?, allowedPlanIds?, ... }.
|
|
223
|
+
def send_invite(invite)
|
|
224
|
+
@routes.data('portal.sendInvite', body: invite)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Portal settings (branding, allowed origins).
|
|
228
|
+
def get_settings # rubocop:disable Naming/AccessorMethodName -- catalog operation portal.getSettings
|
|
229
|
+
@routes.data('portal.getSettings')
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def update_settings(settings)
|
|
233
|
+
@routes.data('portal.updateSettings', body: settings)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# subscriptions.products: catalog products (groups of plans).
|
|
238
|
+
class SubscriptionProducts
|
|
239
|
+
def initialize(routes)
|
|
240
|
+
@routes = routes
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def create(product)
|
|
244
|
+
@routes.data('products.create', body: product)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Filters: limit, cursor, active.
|
|
248
|
+
def list(**filters)
|
|
249
|
+
@routes.page('products.list', query: filters)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def iterate(**filters, &block)
|
|
253
|
+
RouteResponse.each_item(filters, block) { |query| list(**query) }
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def get(product_id)
|
|
257
|
+
@routes.data('products.get', params: { 'productId' => product_id })
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def update(product_id, changes)
|
|
261
|
+
@routes.data('products.update', params: { 'productId' => product_id }, body: changes)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def archive(product_id)
|
|
265
|
+
@routes.data('products.archive', params: { 'productId' => product_id })
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def translations(product_id)
|
|
269
|
+
@routes.data('products.translations', params: { 'productId' => product_id })
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def upsert_translation(product_id, locale, translation)
|
|
273
|
+
@routes.data('products.upsertTranslation', params: { 'productId' => product_id, 'locale' => locale }, body: translation)
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# subscriptions.features: entitlement features.
|
|
278
|
+
class SubscriptionFeatures
|
|
279
|
+
def initialize(routes)
|
|
280
|
+
@routes = routes
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def create(feature)
|
|
284
|
+
@routes.data('features.create', body: feature)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Any scalar filter is forwarded.
|
|
288
|
+
def list(**filters)
|
|
289
|
+
@routes.page('features.list', query: filters)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def get(feature_id)
|
|
293
|
+
@routes.data('features.get', params: { 'featureId' => feature_id })
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def update(feature_id, changes)
|
|
297
|
+
@routes.data('features.update', params: { 'featureId' => feature_id }, body: changes)
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def delete(feature_id)
|
|
301
|
+
@routes.data('features.delete', params: { 'featureId' => feature_id })
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def translations(feature_id)
|
|
305
|
+
@routes.data('features.translations', params: { 'featureId' => feature_id })
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def upsert_translation(feature_id, locale, translation)
|
|
309
|
+
@routes.data('features.upsertTranslation', params: { 'featureId' => feature_id, 'locale' => locale }, body: translation)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# subscriptions.addons.
|
|
314
|
+
class SubscriptionAddons
|
|
315
|
+
def initialize(routes)
|
|
316
|
+
@routes = routes
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def create(addon)
|
|
320
|
+
@routes.data('addons.create', body: addon)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Any scalar filter is forwarded.
|
|
324
|
+
def list(**filters)
|
|
325
|
+
@routes.page('addons.list', query: filters)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def update(addon_id, changes)
|
|
329
|
+
@routes.data('addons.update', params: { 'addonId' => addon_id }, body: changes)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def deactivate(addon_id)
|
|
333
|
+
@routes.data('addons.deactivate', params: { 'addonId' => addon_id })
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# subscriptions.usage: metered usage and entitlement checks.
|
|
338
|
+
class SubscriptionUsage
|
|
339
|
+
def initialize(routes)
|
|
340
|
+
@routes = routes
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
# A metered-usage event: { customerId | subscriptionId, featureKey, quantity, timestamp?,
|
|
344
|
+
# idempotencyKey?, ... }.
|
|
345
|
+
def record(usage)
|
|
346
|
+
@routes.data('usage.record', body: usage)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Whether the customer is entitled / has quota left: { customerId | subscriptionId, featureKey,
|
|
350
|
+
# requested?, ... }.
|
|
351
|
+
def check_entitlement(check)
|
|
352
|
+
@routes.data('usage.checkEntitlement', body: check)
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end
|