lunixi-sdk 1.2.2 → 2.0.2
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 +62 -0
- data/README.md +278 -10
- data/README.tr.md +282 -8
- data/docs/ruby.en.md +11 -1
- data/docs/ruby.tr.md +11 -1
- 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 +171 -0
- data/lib/lunixi/client.rb +57 -16
- data/lib/lunixi/direct_method_payment_request.rb +245 -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 +268 -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/order_details.rb +115 -0
- 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 +136 -0
- data/lib/lunixi/payment_links.rb +152 -0
- data/lib/lunixi/payment_values.rb +86 -0
- data/lib/lunixi/payments.rb +170 -8
- 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 +150 -0
- data/lib/lunixi/subscription_resources.rb +357 -0
- data/lib/lunixi/subscription_values.rb +233 -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 +407 -0
- data/lib/lunixi/wallet_routes.rb +126 -0
- data/lib/lunixi/wallet_values.rb +71 -0
- data/lib/lunixi/wire_money.rb +67 -0
- data/lib/lunixi.rb +58 -0
- metadata +59 -1
data/lib/lunixi/money.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Lunixi
|
|
|
5
5
|
module Money
|
|
6
6
|
MAX = 9_223_372_036_854_775_807
|
|
7
7
|
EXPONENTS = %w[TRY USD EUR GBP RUB AED SAR QAR CHF CAD AUD CNY AZN].to_h { |c| [c, 2] }.merge('JPY' => 0, 'KWD' => 3).freeze
|
|
8
|
+
|
|
8
9
|
module_function
|
|
9
10
|
|
|
10
11
|
def fiat_route?(path)
|
|
@@ -53,19 +54,21 @@ module Lunixi
|
|
|
53
54
|
next if entry.nil? || %w[metadata fields inputFields insuranceData].include?(key)
|
|
54
55
|
|
|
55
56
|
if %w[
|
|
56
|
-
amount amountMinor authorizedAmount availableBalance
|
|
57
|
+
amount amountMinor authorizedAmount availableBalance availableMinor availableWithoutOverdraftMinor balanceAfterMinor
|
|
58
|
+
balanceMinor blockedMinor buyerTotalCharge cancelledPremiumAmount
|
|
57
59
|
capturedAmount capturedAmountMinor chargeAmount collectedAmountMinor collectedPremiumAmount compensatedAmount
|
|
58
60
|
disputedAmount feeTotal fixedFee inForcePremiumAmount insuranceValueAmount legAmount legsAmount lineTotalMinor
|
|
59
|
-
maxAmount maxAmountMinor minAmount minAmountMinor nonRefundableAmount paidAmount paidPrice pendingBalance
|
|
61
|
+
maxAmount maxAmountMinor minAmount minAmountMinor nonRefundableAmount overdraftAvailableMinor paidAmount paidPrice pendingBalance
|
|
60
62
|
premiumAmount price refundAmount refundOpenPremiumAmount refundableAmount refundedAmount refundedAmountMinor
|
|
61
|
-
refundedPremiumAmount requestedAmount reservedBalance sourceAmountMinor targetAmountMinor
|
|
63
|
+
refundedPremiumAmount requestedAmount reservedBalance sourceAmountMinor sourceBalanceAfterMinor targetAmountMinor
|
|
64
|
+
targetBalanceAfterMinor taxAmountMinor taxTotal
|
|
62
65
|
totalAmount unitPriceMinor
|
|
63
66
|
].include?(key)
|
|
64
67
|
minor(entry, positive: !response && %w[amount price totalAmount].include?(key), signed: key.downcase.include?('balance'))
|
|
65
68
|
elsif %w[
|
|
66
69
|
data details items rows results payments operations balances wallets legs aggregate refund refunds totals
|
|
67
70
|
charge fees fee balance splits sellers basketItems promissoryNote schedule notes lines offers policies
|
|
68
|
-
reconciliation quotes payment transactions accounts settlements payouts limits
|
|
71
|
+
reconciliation quotes payment transactions accounts settlements payouts limits options quote
|
|
69
72
|
].include?(key)
|
|
70
73
|
validate_fields(entry, response: response)
|
|
71
74
|
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Order details every payment endpoint requires: the buyer, the billing address and at least one
|
|
5
|
+
# basket item; a basket with a PHYSICAL item also requires the shipping address. Payment providers do
|
|
6
|
+
# not start a payment without them.
|
|
7
|
+
#
|
|
8
|
+
# The gateway refuses a missing field with payment.order.field_required and an invalid one with
|
|
9
|
+
# payment.order.field_invalid; details.field is the dotted path of the first failing field. The SDK
|
|
10
|
+
# checks the same rule before sending and names the same paths. The same values as the Node, PHP and
|
|
11
|
+
# Python SDKs.
|
|
12
|
+
|
|
13
|
+
# Order objects required on every payment endpoint.
|
|
14
|
+
ORDER_DETAILS_REQUIRED_FIELDS = %w[buyer billingAddress basketItems].freeze
|
|
15
|
+
|
|
16
|
+
# buyer fields that must be nonempty strings. identityNumber: Turkish ID or passport number; email:
|
|
17
|
+
# ASCII; ip: the buyer's browser IP (IPv4 or IPv6).
|
|
18
|
+
BUYER_REQUIRED_FIELDS = %w[name surname identityNumber email gsmNumber city country zipCode ip].freeze
|
|
19
|
+
|
|
20
|
+
# buyer fields a checkout intent may leave out (payments.create_intent, payments.create_marketplace_intent,
|
|
21
|
+
# marketplace.create_checkout_intent): the Lunixi form takes the IP from the buyer's browser. A given
|
|
22
|
+
# ip is still sent and wins.
|
|
23
|
+
CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS = %w[ip].freeze
|
|
24
|
+
|
|
25
|
+
# Fields of billingAddress and shippingAddress that must be nonempty strings.
|
|
26
|
+
ADDRESS_REQUIRED_FIELDS = %w[contactName address city country zipCode].freeze
|
|
27
|
+
|
|
28
|
+
# Fields of each basketItems[] entry the gateway requires.
|
|
29
|
+
BASKET_ITEM_REQUIRED_FIELDS = %w[id name category1 itemType price].freeze
|
|
30
|
+
|
|
31
|
+
# Error codes of a missing or invalid order field.
|
|
32
|
+
module OrderFieldErrorCode
|
|
33
|
+
FIELD_REQUIRED = 'payment.order.field_required'
|
|
34
|
+
FIELD_INVALID = 'payment.order.field_invalid'
|
|
35
|
+
|
|
36
|
+
ALL = [FIELD_REQUIRED, FIELD_INVALID].freeze
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# details.reason of an order field error.
|
|
40
|
+
module OrderFieldReason
|
|
41
|
+
REQUIRED = 'required'
|
|
42
|
+
REQUIRED_WHEN_PHYSICAL = 'required_when_physical'
|
|
43
|
+
INVALID_TYPE = 'invalid_type'
|
|
44
|
+
INVALID_FORMAT = 'invalid_format'
|
|
45
|
+
TOO_LONG = 'too_long'
|
|
46
|
+
TOO_FEW_ITEMS = 'too_few_items'
|
|
47
|
+
|
|
48
|
+
ALL = [REQUIRED, REQUIRED_WHEN_PHYSICAL, INVALID_TYPE, INVALID_FORMAT, TOO_LONG, TOO_FEW_ITEMS].freeze
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The order details check of the payment endpoints.
|
|
52
|
+
module OrderDetails
|
|
53
|
+
PHYSICAL_ITEM_TYPE = 'PHYSICAL'
|
|
54
|
+
|
|
55
|
+
module_function
|
|
56
|
+
|
|
57
|
+
# Paths of the missing order fields of a payment body (String or Symbol keys), in the gateway's
|
|
58
|
+
# format: buyer, buyer.email, billingAddress.city, basketItems.0.category1, shippingAddress. An empty
|
|
59
|
+
# Array means the order details are complete. basket: false checks the buyer and the billing address
|
|
60
|
+
# only (card storage, wallet card top-up); checkout_intent: true does not require
|
|
61
|
+
# CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS.
|
|
62
|
+
def missing(body, basket: true, checkout_intent: false)
|
|
63
|
+
data = body.is_a?(Hash) ? JSON.parse(JsonBody.dump(body)) : {}
|
|
64
|
+
buyer_fields = checkout_intent ? BUYER_REQUIRED_FIELDS - CHECKOUT_INTENT_BUYER_OPTIONAL_FIELDS : BUYER_REQUIRED_FIELDS
|
|
65
|
+
paths = object_paths(data['buyer'], buyer_fields, 'buyer') +
|
|
66
|
+
object_paths(data['billingAddress'], ADDRESS_REQUIRED_FIELDS, 'billingAddress')
|
|
67
|
+
return paths unless basket
|
|
68
|
+
|
|
69
|
+
items = data['basketItems']
|
|
70
|
+
return paths << 'basketItems' unless items.is_a?(Array) && !items.empty?
|
|
71
|
+
|
|
72
|
+
paths.concat(basket_paths(items))
|
|
73
|
+
shipping = data['shippingAddress']
|
|
74
|
+
if shipping.nil?
|
|
75
|
+
paths << 'shippingAddress' if items.any? { |item| item.is_a?(Hash) && item['itemType'] == PHYSICAL_ITEM_TYPE }
|
|
76
|
+
else
|
|
77
|
+
paths.concat(object_paths(shipping, ADDRESS_REQUIRED_FIELDS, 'shippingAddress'))
|
|
78
|
+
end
|
|
79
|
+
paths
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Raises ConfigurationError naming the missing order fields (see missing); label names the request
|
|
83
|
+
# ("A payment intent").
|
|
84
|
+
def check!(body, label, basket: true, checkout_intent: false)
|
|
85
|
+
paths = missing(body, basket: basket, checkout_intent: checkout_intent)
|
|
86
|
+
raise ConfigurationError, "#{label} requires the order details: #{paths.join(', ')}." unless paths.empty?
|
|
87
|
+
|
|
88
|
+
body
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def object_paths(value, fields, path)
|
|
92
|
+
return [path] unless value.is_a?(Hash)
|
|
93
|
+
|
|
94
|
+
fields.reject { |field| filled?(value[field]) }.map { |field| "#{path}.#{field}" }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def basket_paths(items)
|
|
98
|
+
items.each_with_index.flat_map do |item, index|
|
|
99
|
+
next ["basketItems.#{index}"] unless item.is_a?(Hash)
|
|
100
|
+
|
|
101
|
+
BASKET_ITEM_REQUIRED_FIELDS.select { |field| blank?(item[field]) }.map { |field| "basketItems.#{index}.#{field}" }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def filled?(value)
|
|
106
|
+
value.is_a?(String) && !value.strip.empty?
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def blank?(value)
|
|
110
|
+
value.nil? || (value.is_a?(String) && value.strip.empty?)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private_class_method :object_paths, :basket_paths, :filled?, :blank?
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Lunixi
|
|
6
|
+
# Local checks of the payment-link list filters (links, attempts and payments of a link).
|
|
7
|
+
module PaymentLinkFilters
|
|
8
|
+
LINK_LIST_FILTERS = %w[limit cursor includeTotal state usage amountMode environment tag branchCode createdById query
|
|
9
|
+
createdFrom createdTo].freeze
|
|
10
|
+
ATTEMPT_LIST_FILTERS = %w[limit cursor includeTotal state].freeze
|
|
11
|
+
PAYMENT_LIST_FILTERS = %w[limit cursor includeTotal].freeze
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# Lists accept an Array for state, usage and amountMode (sent as a comma list) and a Time for the
|
|
16
|
+
# createdFrom / createdTo window.
|
|
17
|
+
def list_query!(filters, allowed, operation)
|
|
18
|
+
data = filters.transform_keys(&:to_s)
|
|
19
|
+
unknown = data.keys - allowed
|
|
20
|
+
raise ConfigurationError, "#{operation} does not take #{unknown.join(', ')}; filters: #{allowed.join(', ')}" unless unknown.empty?
|
|
21
|
+
|
|
22
|
+
allowed.each_with_object({}) do |key, query|
|
|
23
|
+
value = data[key]
|
|
24
|
+
next if value.nil? || value == ''
|
|
25
|
+
|
|
26
|
+
value = value.join(',') if value.is_a?(Array)
|
|
27
|
+
value = value.getutc.iso8601(3) if value.is_a?(Time)
|
|
28
|
+
query[key] = value unless value == ''
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Lunixi
|
|
6
|
+
# Local checks of the payment-link image uploads: the create body, the bytes, the upload target the
|
|
7
|
+
# gateway hands back and the confirmed image.
|
|
8
|
+
module PaymentLinkImageRules
|
|
9
|
+
FILE_NAME_MAX_LENGTH = 255
|
|
10
|
+
UPLOAD_HEADER_NAME = /\A[A-Za-z0-9-]{1,64}\z/
|
|
11
|
+
UPLOAD_HEADER_VALUE_MAX = 1024
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def asset_id!(value)
|
|
16
|
+
raise ConfigurationError, "asset_id must be the image's asset id (UUID)" unless value.is_a?(String) && value.match?(PAYMENT_LINK_ASSET_ID_PATTERN)
|
|
17
|
+
|
|
18
|
+
value
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def image_body!(file_name, content_type, size_bytes)
|
|
22
|
+
unless file_name.is_a?(String) && !file_name.strip.empty? && file_name.length <= FILE_NAME_MAX_LENGTH
|
|
23
|
+
raise ConfigurationError, "file_name must be 1–#{FILE_NAME_MAX_LENGTH} characters"
|
|
24
|
+
end
|
|
25
|
+
unless PaymentLinkImageContentType::ALL.include?(content_type)
|
|
26
|
+
raise ConfigurationError, "Image content_type must be one of #{PaymentLinkImageContentType::ALL.join(', ')} (SVG is not accepted)"
|
|
27
|
+
end
|
|
28
|
+
unless size_bytes.is_a?(Integer) && size_bytes.between?(1, JsonBody::MAX_SAFE_INTEGER)
|
|
29
|
+
raise ConfigurationError, 'Image size_bytes must be the file size in bytes (a positive integer)'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
{ 'fileName' => file_name, 'contentType' => content_type, 'sizeBytes' => size_bytes }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def image_content!(content)
|
|
36
|
+
raise ConfigurationError, 'Image content must be a nonempty binary String' unless content.is_a?(String) && !content.empty?
|
|
37
|
+
|
|
38
|
+
content.b
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# An upload target is used only if the SDK can PUT to it as documented: an asset id, an HTTPS URL
|
|
42
|
+
# without credentials, the PUT method and string headers. Anything else fails before a byte is sent.
|
|
43
|
+
def upload_target!(envelope)
|
|
44
|
+
target = envelope.is_a?(Hash) ? envelope['data'] : nil
|
|
45
|
+
usable = target.is_a?(Hash) && target['assetId'].is_a?(String) && target['assetId'].match?(PAYMENT_LINK_ASSET_ID_PATTERN) &&
|
|
46
|
+
upload_url?(target['uploadUrl']) && target['uploadMethod'] == 'PUT' && upload_headers?(target['uploadHeaders'])
|
|
47
|
+
raise ApiError.new(status: 502, code: 'invalid_image_upload_target') unless usable
|
|
48
|
+
|
|
49
|
+
target
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def published_image!(envelope)
|
|
53
|
+
image = envelope.is_a?(Hash) ? envelope['data'] : nil
|
|
54
|
+
return if image.is_a?(Hash) && image['assetId'].is_a?(String) && image['state'] == 'PUBLISHED'
|
|
55
|
+
|
|
56
|
+
raise ApiError.new(status: 502, code: 'image_not_published')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# S3-compatible storage answers errors as XML: <Error><Code>AccessDenied</Code>…
|
|
60
|
+
def storage_error_code(body)
|
|
61
|
+
match = body.to_s.b.match(%r{<Code>([A-Za-z0-9.]{1,64})</Code>})
|
|
62
|
+
match && match[1]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def upload_url?(value)
|
|
66
|
+
uri = URI.parse(value)
|
|
67
|
+
uri.is_a?(URI::HTTPS) && !uri.host.to_s.empty? && uri.userinfo.nil? && uri.fragment.nil? && value.bytesize <= 8192
|
|
68
|
+
rescue URI::InvalidURIError, TypeError
|
|
69
|
+
false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def upload_headers?(headers)
|
|
73
|
+
return false unless headers.is_a?(Hash) && headers.size <= 32
|
|
74
|
+
|
|
75
|
+
headers.all? { |name, value| upload_header?(name, value) }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def upload_header?(name, value)
|
|
79
|
+
name.is_a?(String) && name.match?(UPLOAD_HEADER_NAME) && value.is_a?(String) &&
|
|
80
|
+
value.bytesize <= UPLOAD_HEADER_VALUE_MAX && !value.match?(/[\x00-\x1f\x7f]/)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private_class_method :upload_url?, :upload_headers?, :upload_header?
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Lunixi
|
|
6
|
+
# Local checks of the payment-link bodies (list filters: PaymentLinkFilters; image uploads:
|
|
7
|
+
# PaymentLinkImageRules).
|
|
8
|
+
module PaymentLinkRules
|
|
9
|
+
CREATE_FIELDS = (['environment'] + PAYMENT_LINK_SPEC_FIELDS).freeze
|
|
10
|
+
UPDATE_FIELDS = PAYMENT_LINK_SPEC_FIELDS
|
|
11
|
+
TIME_FIELDS = %w[startsAt expiresAt eventAt].freeze
|
|
12
|
+
LINK_ACTIONS = %w[pause resume deactivate].freeze
|
|
13
|
+
QR_MIN_SIZE = 128
|
|
14
|
+
QR_MAX_SIZE = 2048
|
|
15
|
+
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
def create_body!(body)
|
|
19
|
+
data = root!(body, 'Payment link request')
|
|
20
|
+
known!(data, CREATE_FIELDS, 'create')
|
|
21
|
+
times(data)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Only the given keys are updated; nil clears a field.
|
|
25
|
+
def update_body!(changes)
|
|
26
|
+
data = root!(changes, 'Payment link changes')
|
|
27
|
+
raise ConfigurationError, 'Payment link update needs at least one changed field' if data.empty?
|
|
28
|
+
|
|
29
|
+
fixed = data.keys.find { |key| PAYMENT_LINK_IMMUTABLE_FIELDS.include?(key) }
|
|
30
|
+
raise ConfigurationError, "'#{fixed}' is fixed when a payment link is created and cannot be updated; create a new link instead" if fixed
|
|
31
|
+
|
|
32
|
+
known!(data, UPDATE_FIELDS, 'update')
|
|
33
|
+
times(data)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# pause / resume / deactivate body: expectedRowVersion (optional) and reason.
|
|
37
|
+
def action_body!(action, expected_row_version, reason)
|
|
38
|
+
raise ConfigurationError, "Payment link action must be one of #{LINK_ACTIONS.join(', ')}" unless LINK_ACTIONS.include?(action.to_s)
|
|
39
|
+
|
|
40
|
+
body = {}
|
|
41
|
+
body['expectedRowVersion'] = row_version!(expected_row_version) unless expected_row_version.nil?
|
|
42
|
+
body['reason'] = reason.to_s unless reason.nil?
|
|
43
|
+
body
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def send_body!(channel, recipient_email, recipient_phone, locale)
|
|
47
|
+
unless PaymentLinkDeliveryChannel::ALL.include?(channel)
|
|
48
|
+
raise ConfigurationError, "Send channel must be one of #{PaymentLinkDeliveryChannel::ALL.join(', ')}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
body = { 'channel' => channel }
|
|
52
|
+
body['recipientEmail'] = recipient_email.to_s unless recipient_email.nil?
|
|
53
|
+
body['recipientPhone'] = recipient_phone.to_s unless recipient_phone.nil?
|
|
54
|
+
unless locale.nil?
|
|
55
|
+
raise ConfigurationError, "Send locale must be one of #{PaymentLinkLocale::ALL.join(', ')}" unless PaymentLinkLocale::ALL.include?(locale)
|
|
56
|
+
|
|
57
|
+
body['locale'] = locale
|
|
58
|
+
end
|
|
59
|
+
body
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def qr_query!(format, size)
|
|
63
|
+
raise ConfigurationError, "QR format must be one of #{PaymentLinkQrFormat::ALL.join(', ')}" unless PaymentLinkQrFormat::ALL.include?(format)
|
|
64
|
+
|
|
65
|
+
query = { 'format' => format }
|
|
66
|
+
return query if size.nil?
|
|
67
|
+
unless size.is_a?(Integer) && size.between?(QR_MIN_SIZE, QR_MAX_SIZE)
|
|
68
|
+
raise ConfigurationError, "QR size must be an integer in pixels, #{QR_MIN_SIZE}-#{QR_MAX_SIZE}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
query.merge('size' => size)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def row_version!(value)
|
|
75
|
+
unless value.is_a?(Integer) && value.between?(0, JsonBody::MAX_SAFE_INTEGER)
|
|
76
|
+
raise ConfigurationError, "expectedRowVersion must be the link's current rowVersion (a nonnegative integer)"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
value
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def link_id!(value)
|
|
83
|
+
raise ConfigurationError, 'link_id is required' unless value.is_a?(String) && value.match?(/\A[a-zA-Z0-9_-]{1,256}\z/)
|
|
84
|
+
|
|
85
|
+
value
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def root!(body, name)
|
|
89
|
+
raise ConfigurationError, "#{name} must be an object" unless body.is_a?(Hash)
|
|
90
|
+
|
|
91
|
+
body.each_with_object({}) do |(key, value), data|
|
|
92
|
+
raise ConfigurationError, "#{name} keys must be strings or symbols" unless key.is_a?(String) || key.is_a?(Symbol)
|
|
93
|
+
raise ConfigurationError, "#{name} repeats the key #{key}" if data.key?(key.to_s)
|
|
94
|
+
|
|
95
|
+
data[key.to_s] = value
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def known!(data, allowed, operation)
|
|
100
|
+
unknown = data.keys - allowed
|
|
101
|
+
return if unknown.empty?
|
|
102
|
+
|
|
103
|
+
raise ConfigurationError, "Unknown payment link #{operation} field(s): #{unknown.join(', ')}; the gateway rejects unknown fields with 400"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# A Time is sent as ISO 8601 (UTC, milliseconds); a String as given; nil clears the value.
|
|
107
|
+
def times(data)
|
|
108
|
+
TIME_FIELDS.each do |key|
|
|
109
|
+
next unless data.key?(key)
|
|
110
|
+
|
|
111
|
+
value = data[key]
|
|
112
|
+
next if value.nil?
|
|
113
|
+
|
|
114
|
+
data[key] = time_value!(value, key)
|
|
115
|
+
end
|
|
116
|
+
data
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def time_value!(value, key)
|
|
120
|
+
return iso8601(value) if value.is_a?(Time)
|
|
121
|
+
return value if value.is_a?(String) && !value.strip.empty?
|
|
122
|
+
|
|
123
|
+
raise ConfigurationError, "#{key} must be a Time, an ISO 8601 string or nil"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def iso8601(time)
|
|
127
|
+
time.getutc.iso8601(3)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private_class_method :root!, :known!, :times, :time_value!, :iso8601
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Closed value sets of the payment-link API (/api/v1/payments/links). The gateway answers an unknown
|
|
5
|
+
# value with 400.
|
|
6
|
+
module PaymentLinkUsage
|
|
7
|
+
# Can be paid once: an invoice or a personal payment request.
|
|
8
|
+
SINGLE_USE = 'SINGLE_USE'
|
|
9
|
+
# Can be paid many times: donations, tickets, a product page.
|
|
10
|
+
MULTI_USE = 'MULTI_USE'
|
|
11
|
+
|
|
12
|
+
ALL = [SINGLE_USE, MULTI_USE].freeze
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module PaymentLinkAmountMode
|
|
16
|
+
# The merchant sets the amount (amountMinor).
|
|
17
|
+
FIXED = 'FIXED'
|
|
18
|
+
# The buyer enters the amount, bounded by minAmountMinor / maxAmountMinor.
|
|
19
|
+
OPEN = 'OPEN'
|
|
20
|
+
# The buyer picks quantities from items; the amount is the sum of the lines.
|
|
21
|
+
ITEMIZED = 'ITEMIZED'
|
|
22
|
+
|
|
23
|
+
ALL = [FIXED, OPEN, ITEMIZED].freeze
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module PaymentLinkState
|
|
27
|
+
ACTIVE = 'ACTIVE'
|
|
28
|
+
PAUSED = 'PAUSED'
|
|
29
|
+
COMPLETED = 'COMPLETED'
|
|
30
|
+
EXPIRED = 'EXPIRED'
|
|
31
|
+
DEACTIVATED = 'DEACTIVATED'
|
|
32
|
+
# Removed by Lunixi. Every write on the link answers 409 payment_link.link.taken_down.
|
|
33
|
+
TAKEN_DOWN = 'TAKEN_DOWN'
|
|
34
|
+
|
|
35
|
+
ALL = [ACTIVE, PAUSED, COMPLETED, EXPIRED, DEACTIVATED, TAKEN_DOWN].freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module PaymentLinkAttemptState
|
|
39
|
+
OPEN = 'OPEN'
|
|
40
|
+
BOUND = 'BOUND'
|
|
41
|
+
SUCCEEDED = 'SUCCEEDED'
|
|
42
|
+
FAILED = 'FAILED'
|
|
43
|
+
EXPIRED = 'EXPIRED'
|
|
44
|
+
ABANDONED = 'ABANDONED'
|
|
45
|
+
NEEDS_REVIEW = 'NEEDS_REVIEW'
|
|
46
|
+
|
|
47
|
+
ALL = [OPEN, BOUND, SUCCEEDED, FAILED, EXPIRED, ABANDONED, NEEDS_REVIEW].freeze
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
module PaymentLinkEnvironment
|
|
51
|
+
TEST = 'TEST'
|
|
52
|
+
LIVE = 'LIVE'
|
|
53
|
+
|
|
54
|
+
ALL = [TEST, LIVE].freeze
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Value of a buyerFields entry (name, email, phone, address, identityNumber). Payment providers
|
|
58
|
+
# require the buyer, the identity number and the billing address, so the link page always asks all
|
|
59
|
+
# five fields: REQUIRED is the only value (the gateway answers any other with 400; leaving a field
|
|
60
|
+
# out means REQUIRED).
|
|
61
|
+
module BuyerFieldRequirement
|
|
62
|
+
REQUIRED = 'REQUIRED'
|
|
63
|
+
|
|
64
|
+
ALL = [REQUIRED].freeze
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module CustomFieldType
|
|
68
|
+
TEXT = 'TEXT'
|
|
69
|
+
NUMBER = 'NUMBER'
|
|
70
|
+
EMAIL = 'EMAIL'
|
|
71
|
+
PHONE = 'PHONE'
|
|
72
|
+
DATE = 'DATE'
|
|
73
|
+
SELECT = 'SELECT'
|
|
74
|
+
CHECKBOX = 'CHECKBOX'
|
|
75
|
+
TCKN = 'TCKN'
|
|
76
|
+
VKN = 'VKN'
|
|
77
|
+
|
|
78
|
+
ALL = [TEXT, NUMBER, EMAIL, PHONE, DATE, SELECT, CHECKBOX, TCKN, VKN].freeze
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
module PaymentLinkButtonLabel
|
|
82
|
+
PAY = 'PAY'
|
|
83
|
+
DONATE = 'DONATE'
|
|
84
|
+
BUY = 'BUY'
|
|
85
|
+
BOOK = 'BOOK'
|
|
86
|
+
|
|
87
|
+
ALL = [PAY, DONATE, BUY, BOOK].freeze
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
module PaymentLinkDeliveryChannel
|
|
91
|
+
EMAIL = 'EMAIL'
|
|
92
|
+
SMS = 'SMS'
|
|
93
|
+
|
|
94
|
+
ALL = [EMAIL, SMS].freeze
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
module PaymentLinkQrFormat
|
|
98
|
+
SVG = 'svg'
|
|
99
|
+
PNG = 'png'
|
|
100
|
+
|
|
101
|
+
ALL = [SVG, PNG].freeze
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
module PaymentLinkLocale
|
|
105
|
+
TR = 'tr'
|
|
106
|
+
EN = 'en'
|
|
107
|
+
|
|
108
|
+
ALL = [TR, EN].freeze
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Types a payment-link image can be declared as. On confirmation the stored file's own bytes are
|
|
112
|
+
# checked against the declared type; SVG is never accepted.
|
|
113
|
+
module PaymentLinkImageContentType
|
|
114
|
+
PNG = 'image/png'
|
|
115
|
+
JPEG = 'image/jpeg'
|
|
116
|
+
WEBP = 'image/webp'
|
|
117
|
+
|
|
118
|
+
ALL = [PNG, JPEG, WEBP].freeze
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Every field of a payment-link definition in the gateway's spelling. Create and update bodies may
|
|
122
|
+
# carry only these keys (plus environment on create); the gateway rejects any other key with 400.
|
|
123
|
+
PAYMENT_LINK_SPEC_FIELDS = %w[
|
|
124
|
+
usage amountMode currency amountMinor minAmountMinor maxAmountMinor suggestedAmountsMinor quantityEnabled
|
|
125
|
+
minQuantity maxQuantity items capacity title description imageAssetId successMessage successRedirectUrl taxNote
|
|
126
|
+
locale startsAt expiresAt eventAt buttonLabelKey requireTermsAcceptance buyerFields customFields recipient prefill
|
|
127
|
+
verification reminders checkout reference tags branchCode salesChannel campaign agentCode merchantNotifyEmails
|
|
128
|
+
metadata
|
|
129
|
+
].freeze
|
|
130
|
+
|
|
131
|
+
# Fixed when the link is created; an update that names one answers 422 payment_link.link.immutable_field.
|
|
132
|
+
PAYMENT_LINK_IMMUTABLE_FIELDS = %w[usage amountMode currency].freeze
|
|
133
|
+
|
|
134
|
+
# Shape of a media asset id (a UUID); ownership and state are checked by the gateway.
|
|
135
|
+
PAYMENT_LINK_ASSET_ID_PATTERN = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
|
|
136
|
+
end
|