add payment settting
This commit is contained in:
1 parent
0971158e98
commit
b8455625b5
21 files changed
+1760
-12
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
@@ -0,0 +1,18 @@
|
|||||||
|
-- Reverse 20260918130000_add_payment_settings_and_visamaster_pay.up.sql
|
||||||
|
ALTER TABLE visa_master_payment_orders
|
||||||
|
DROP COLUMN IF EXISTS amount_usd,
|
||||||
|
DROP COLUMN IF EXISTS exchange_rate,
|
||||||
|
DROP COLUMN IF EXISTS exchange_rate_rub,
|
||||||
|
DROP COLUMN IF EXISTS amount_tmt,
|
||||||
|
DROP COLUMN IF EXISTS bank_fee_tmt,
|
||||||
|
DROP COLUMN IF EXISTS gbus_fee_tmt,
|
||||||
|
DROP COLUMN IF EXISTS tveb_fee_usd,
|
||||||
|
DROP COLUMN IF EXISTS tveb_fee_tmt,
|
||||||
|
DROP COLUMN IF EXISTS total_amount_tmt,
|
||||||
|
DROP COLUMN IF EXISTS payment_period,
|
||||||
|
DROP COLUMN IF EXISTS gateway_status,
|
||||||
|
DROP COLUMN IF EXISTS gateway_reference,
|
||||||
|
DROP COLUMN IF EXISTS gateway_response,
|
||||||
|
DROP COLUMN IF EXISTS paid_at;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS payment_settings;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-- Adds the "Töleg" payment feature for Visa/Master/Sber money-transfer
|
||||||
|
-- orders:
|
||||||
|
-- 1. payment_settings is a single-row settings table for the admin-
|
||||||
|
-- configurable commission fees used on every payment. Visa/Master
|
||||||
|
-- orders use bank_fee_tmt + gbus_fee_tmt; Sber orders use their own
|
||||||
|
-- sber_bank_fee_tmt plus a USD-denominated tveb_fee_usd (converted to
|
||||||
|
-- TMT at payout time via the USD rate) - Sber has no GBÜS fee.
|
||||||
|
-- 2. visa_master_payment_orders gains the requested USD amount plus the
|
||||||
|
-- payout columns (rate(s), TMT amount, fees, total, gateway result)
|
||||||
|
-- filled in once the order is paid out. The Sber-specific columns
|
||||||
|
-- (exchange_rate_rub, tveb_fee_usd, tveb_fee_tmt) stay null for
|
||||||
|
-- non-Sber orders, same as gbus_fee_tmt stays null for Sber ones.
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS payment_settings (
|
||||||
|
id smallint PRIMARY KEY DEFAULT 1,
|
||||||
|
bank_fee_tmt numeric(12, 2) NOT NULL DEFAULT 100,
|
||||||
|
gbus_fee_tmt numeric(12, 2) NOT NULL DEFAULT 15,
|
||||||
|
sber_bank_fee_tmt numeric(12, 2) NOT NULL DEFAULT 100,
|
||||||
|
tveb_fee_usd numeric(12, 2) NOT NULL DEFAULT 18,
|
||||||
|
updated_by bigint,
|
||||||
|
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
|
||||||
|
CONSTRAINT payment_settings_single_row CHECK (id = 1),
|
||||||
|
CONSTRAINT payment_settings_updated_by_fkey
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO payment_settings (id, bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt, tveb_fee_usd)
|
||||||
|
VALUES (1, 100, 15, 100, 18)
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
ALTER TABLE visa_master_payment_orders
|
||||||
|
ADD COLUMN amount_usd numeric(18, 2),
|
||||||
|
ADD COLUMN exchange_rate numeric(18, 8),
|
||||||
|
ADD COLUMN exchange_rate_rub numeric(18, 8),
|
||||||
|
ADD COLUMN amount_tmt numeric(18, 2),
|
||||||
|
ADD COLUMN bank_fee_tmt numeric(12, 2),
|
||||||
|
ADD COLUMN gbus_fee_tmt numeric(12, 2),
|
||||||
|
ADD COLUMN tveb_fee_usd numeric(12, 2),
|
||||||
|
ADD COLUMN tveb_fee_tmt numeric(12, 2),
|
||||||
|
ADD COLUMN total_amount_tmt numeric(18, 2),
|
||||||
|
ADD COLUMN payment_period date,
|
||||||
|
ADD COLUMN gateway_status character varying(32) NOT NULL DEFAULT 'pending',
|
||||||
|
ADD COLUMN gateway_reference character varying(255),
|
||||||
|
ADD COLUMN gateway_response jsonb,
|
||||||
|
ADD COLUMN paid_at TIMESTAMP;
|
||||||
+343
-2
@@ -393,7 +393,7 @@ const docTemplate = `{
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a branch-user assignment, or updates the user's existing branch if one is already assigned",
|
"description": "Assigns a user to a branch. Users and branches are many-to-many: a user keeps their other branch assignments, and re-assigning the same pair is a no-op.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -4897,6 +4897,86 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-settings": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the admin-configurable bank and GBÜS commission fees used on loan payments",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-settings"
|
||||||
|
],
|
||||||
|
"summary": "Get payment settings",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.PaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Updates the bank and GBÜS commission fees used on loan payments",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-settings"
|
||||||
|
],
|
||||||
|
"summary": "Update payment settings",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Payment settings payload",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.UpdatePaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.PaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/permission-roles": {
|
"/permission-roles": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -6497,7 +6577,7 @@ const docTemplate = `{
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Returns paginated users with role user, including roleId",
|
"description": "Returns paginated users, including roleId. Admin-guard callers (admin, superadmin, and other admin-guard roles) see users of every role; branch-scoped operators see role=user only, scoped to their branches.",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -7193,6 +7273,122 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/visa-master-payment-orders/{id}/pay": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Charges the payment gateway and marks the order paid on success",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"visa-master-payment-orders"
|
||||||
|
],
|
||||||
|
"summary": "Pay out a visa/master/sber order",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Visa/master payment order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Payment payload",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PayOrderDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PaymentResultDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Not Found",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/visa-master-payment-orders/{id}/quote": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the current rate, configured fees, and max payable amount for an order's payout",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"visa-master-payment-orders"
|
||||||
|
],
|
||||||
|
"summary": "Quote a visa/master/sber payment",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Visa/master payment order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PaymentQuoteDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Not Found",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
@@ -9064,6 +9260,49 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"sberBankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paymentsettings.UpdatePaymentSettingsDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"bankFeeTmt",
|
||||||
|
"gbusFeeTmt",
|
||||||
|
"sberBankFeeTmt",
|
||||||
|
"tvebFeeUsd"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"sberBankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"permission.CreatePermissionDTO": {
|
"permission.CreatePermissionDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -9401,6 +9640,7 @@ const docTemplate = `{
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"address",
|
"address",
|
||||||
|
"amountUsd",
|
||||||
"branchId",
|
"branchId",
|
||||||
"passportName",
|
"passportName",
|
||||||
"passportSurname",
|
"passportSurname",
|
||||||
@@ -9415,6 +9655,9 @@ const docTemplate = `{
|
|||||||
"address": {
|
"address": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"branchId": {
|
"branchId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -9493,6 +9736,7 @@ const docTemplate = `{
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"address",
|
"address",
|
||||||
|
"amountUsd",
|
||||||
"branchId",
|
"branchId",
|
||||||
"passportName",
|
"passportName",
|
||||||
"passportSurname",
|
"passportSurname",
|
||||||
@@ -9507,6 +9751,9 @@ const docTemplate = `{
|
|||||||
"address": {
|
"address": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"branchId": {
|
"branchId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -9580,6 +9827,100 @@ const docTemplate = `{
|
|||||||
"type": "integer"
|
"type": "integer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PayOrderDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PaymentQuoteDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"maxAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PaymentResultDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gatewayReference": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gatewayStatus": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"paid": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"paidAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"totalAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
|
|||||||
+343
-2
@@ -387,7 +387,7 @@
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a branch-user assignment, or updates the user's existing branch if one is already assigned",
|
"description": "Assigns a user to a branch. Users and branches are many-to-many: a user keeps their other branch assignments, and re-assigning the same pair is a no-op.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -4891,6 +4891,86 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/payment-settings": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the admin-configurable bank and GBÜS commission fees used on loan payments",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-settings"
|
||||||
|
],
|
||||||
|
"summary": "Get payment settings",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.PaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Updates the bank and GBÜS commission fees used on loan payments",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"payment-settings"
|
||||||
|
],
|
||||||
|
"summary": "Update payment settings",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Payment settings payload",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.UpdatePaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/paymentsettings.PaymentSettingsDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/permission-roles": {
|
"/permission-roles": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -6491,7 +6571,7 @@
|
|||||||
"BearerAuth": []
|
"BearerAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Returns paginated users with role user, including roleId",
|
"description": "Returns paginated users, including roleId. Admin-guard callers (admin, superadmin, and other admin-guard roles) see users of every role; branch-scoped operators see role=user only, scoped to their branches.",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -7187,6 +7267,122 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/visa-master-payment-orders/{id}/pay": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Charges the payment gateway and marks the order paid on success",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"visa-master-payment-orders"
|
||||||
|
],
|
||||||
|
"summary": "Pay out a visa/master/sber order",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Visa/master payment order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Payment payload",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PayOrderDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PaymentResultDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Not Found",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/visa-master-payment-orders/{id}/quote": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Returns the current rate, configured fees, and max payable amount for an order's payout",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"visa-master-payment-orders"
|
||||||
|
],
|
||||||
|
"summary": "Quote a visa/master/sber payment",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Visa/master payment order ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/visamasterpay.PaymentQuoteDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Not Found",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/appresult.AppError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
@@ -9058,6 +9254,49 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paymentsettings.PaymentSettingsDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"sberBankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"updatedAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paymentsettings.UpdatePaymentSettingsDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"bankFeeTmt",
|
||||||
|
"gbusFeeTmt",
|
||||||
|
"sberBankFeeTmt",
|
||||||
|
"tvebFeeUsd"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"sberBankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"permission.CreatePermissionDTO": {
|
"permission.CreatePermissionDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@@ -9395,6 +9634,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"address",
|
"address",
|
||||||
|
"amountUsd",
|
||||||
"branchId",
|
"branchId",
|
||||||
"passportName",
|
"passportName",
|
||||||
"passportSurname",
|
"passportSurname",
|
||||||
@@ -9409,6 +9649,9 @@
|
|||||||
"address": {
|
"address": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"branchId": {
|
"branchId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -9487,6 +9730,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"address",
|
"address",
|
||||||
|
"amountUsd",
|
||||||
"branchId",
|
"branchId",
|
||||||
"passportName",
|
"passportName",
|
||||||
"passportSurname",
|
"passportSurname",
|
||||||
@@ -9501,6 +9745,9 @@
|
|||||||
"address": {
|
"address": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"branchId": {
|
"branchId": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
@@ -9574,6 +9821,100 @@
|
|||||||
"type": "integer"
|
"type": "integer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PayOrderDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PaymentQuoteDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"maxAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visamasterpay.PaymentResultDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"amountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"amountUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"bankFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateRub": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"exchangeRateUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"gatewayReference": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gatewayStatus": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"gbusFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"orderId": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"paid": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"paidAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"paymentPeriod": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"totalAmountTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeTmt": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"tvebFeeUsd": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
|
|||||||
+229
-3
@@ -1295,6 +1295,35 @@ definitions:
|
|||||||
- price
|
- price
|
||||||
- title
|
- title
|
||||||
type: object
|
type: object
|
||||||
|
paymentsettings.PaymentSettingsDTO:
|
||||||
|
properties:
|
||||||
|
bankFeeTmt:
|
||||||
|
type: number
|
||||||
|
gbusFeeTmt:
|
||||||
|
type: number
|
||||||
|
sberBankFeeTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeUsd:
|
||||||
|
type: number
|
||||||
|
updatedAt:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
paymentsettings.UpdatePaymentSettingsDTO:
|
||||||
|
properties:
|
||||||
|
bankFeeTmt:
|
||||||
|
type: number
|
||||||
|
gbusFeeTmt:
|
||||||
|
type: number
|
||||||
|
sberBankFeeTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeUsd:
|
||||||
|
type: number
|
||||||
|
required:
|
||||||
|
- bankFeeTmt
|
||||||
|
- gbusFeeTmt
|
||||||
|
- sberBankFeeTmt
|
||||||
|
- tvebFeeUsd
|
||||||
|
type: object
|
||||||
permission.CreatePermissionDTO:
|
permission.CreatePermissionDTO:
|
||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
@@ -1526,6 +1555,8 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
address:
|
address:
|
||||||
type: string
|
type: string
|
||||||
|
amountUsd:
|
||||||
|
type: number
|
||||||
branchId:
|
branchId:
|
||||||
type: integer
|
type: integer
|
||||||
documents:
|
documents:
|
||||||
@@ -1576,6 +1607,7 @@ definitions:
|
|||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- address
|
- address
|
||||||
|
- amountUsd
|
||||||
- branchId
|
- branchId
|
||||||
- passportName
|
- passportName
|
||||||
- passportSurname
|
- passportSurname
|
||||||
@@ -1590,6 +1622,8 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
address:
|
address:
|
||||||
type: string
|
type: string
|
||||||
|
amountUsd:
|
||||||
|
type: number
|
||||||
branchId:
|
branchId:
|
||||||
type: integer
|
type: integer
|
||||||
documents:
|
documents:
|
||||||
@@ -1640,6 +1674,7 @@ definitions:
|
|||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- address
|
- address
|
||||||
|
- amountUsd
|
||||||
- branchId
|
- branchId
|
||||||
- passportName
|
- passportName
|
||||||
- passportSurname
|
- passportSurname
|
||||||
@@ -1650,6 +1685,68 @@ definitions:
|
|||||||
- senderPassportNumber
|
- senderPassportNumber
|
||||||
- senderPassportSerie
|
- senderPassportSerie
|
||||||
type: object
|
type: object
|
||||||
|
visamasterpay.PayOrderDTO:
|
||||||
|
properties:
|
||||||
|
amountTmt:
|
||||||
|
type: number
|
||||||
|
paymentPeriod:
|
||||||
|
format: date
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
visamasterpay.PaymentQuoteDTO:
|
||||||
|
properties:
|
||||||
|
bankFeeTmt:
|
||||||
|
type: number
|
||||||
|
exchangeRateRub:
|
||||||
|
type: number
|
||||||
|
exchangeRateUsd:
|
||||||
|
type: number
|
||||||
|
gbusFeeTmt:
|
||||||
|
type: number
|
||||||
|
maxAmountTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeUsd:
|
||||||
|
type: number
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
visamasterpay.PaymentResultDTO:
|
||||||
|
properties:
|
||||||
|
amountTmt:
|
||||||
|
type: number
|
||||||
|
amountUsd:
|
||||||
|
type: number
|
||||||
|
bankFeeTmt:
|
||||||
|
type: number
|
||||||
|
exchangeRateRub:
|
||||||
|
type: number
|
||||||
|
exchangeRateUsd:
|
||||||
|
type: number
|
||||||
|
gatewayReference:
|
||||||
|
type: string
|
||||||
|
gatewayStatus:
|
||||||
|
type: string
|
||||||
|
gbusFeeTmt:
|
||||||
|
type: number
|
||||||
|
orderId:
|
||||||
|
type: integer
|
||||||
|
paid:
|
||||||
|
type: boolean
|
||||||
|
paidAt:
|
||||||
|
type: string
|
||||||
|
paymentPeriod:
|
||||||
|
type: string
|
||||||
|
totalAmountTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeTmt:
|
||||||
|
type: number
|
||||||
|
tvebFeeUsd:
|
||||||
|
type: number
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
host: localhost:5005
|
host: localhost:5005
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
@@ -1899,8 +1996,9 @@ paths:
|
|||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Creates a branch-user assignment, or updates the user's existing
|
description: 'Assigns a user to a branch. Users and branches are many-to-many:
|
||||||
branch if one is already assigned
|
a user keeps their other branch assignments, and re-assigning the same pair
|
||||||
|
is a no-op.'
|
||||||
parameters:
|
parameters:
|
||||||
- description: Branch-user payload
|
- description: Branch-user payload
|
||||||
in: body
|
in: body
|
||||||
@@ -4792,6 +4890,57 @@ paths:
|
|||||||
summary: Update payment card active
|
summary: Update payment card active
|
||||||
tags:
|
tags:
|
||||||
- payment-card
|
- payment-card
|
||||||
|
/payment-settings:
|
||||||
|
get:
|
||||||
|
description: Returns the admin-configurable bank and GBÜS commission fees used
|
||||||
|
on loan payments
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/paymentsettings.PaymentSettingsDTO'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Get payment settings
|
||||||
|
tags:
|
||||||
|
- payment-settings
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Updates the bank and GBÜS commission fees used on loan payments
|
||||||
|
parameters:
|
||||||
|
- description: Payment settings payload
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/paymentsettings.UpdatePaymentSettingsDTO'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/paymentsettings.PaymentSettingsDTO'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Update payment settings
|
||||||
|
tags:
|
||||||
|
- payment-settings
|
||||||
/permission-roles:
|
/permission-roles:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -5816,7 +5965,9 @@ paths:
|
|||||||
- auth
|
- auth
|
||||||
/users:
|
/users:
|
||||||
get:
|
get:
|
||||||
description: Returns paginated users with role user, including roleId
|
description: Returns paginated users, including roleId. Admin-guard callers
|
||||||
|
(admin, superadmin, and other admin-guard roles) see users of every role;
|
||||||
|
branch-scoped operators see role=user only, scoped to their branches.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Search by username, first name, or last name
|
- description: Search by username, first name, or last name
|
||||||
in: query
|
in: query
|
||||||
@@ -6271,6 +6422,81 @@ paths:
|
|||||||
summary: Update visa/master payment order
|
summary: Update visa/master payment order
|
||||||
tags:
|
tags:
|
||||||
- visa-master-payment-orders
|
- visa-master-payment-orders
|
||||||
|
/visa-master-payment-orders/{id}/pay:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Charges the payment gateway and marks the order paid on success
|
||||||
|
parameters:
|
||||||
|
- description: Visa/master payment order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
- description: Payment payload
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/visamasterpay.PayOrderDTO'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/visamasterpay.PaymentResultDTO'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Pay out a visa/master/sber order
|
||||||
|
tags:
|
||||||
|
- visa-master-payment-orders
|
||||||
|
/visa-master-payment-orders/{id}/quote:
|
||||||
|
get:
|
||||||
|
description: Returns the current rate, configured fees, and max payable amount
|
||||||
|
for an order's payout
|
||||||
|
parameters:
|
||||||
|
- description: Visa/master payment order ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/visamasterpay.PaymentQuoteDTO'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/appresult.AppError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: Quote a visa/master/sber payment
|
||||||
|
tags:
|
||||||
|
- visa-master-payment-orders
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
BearerAuth:
|
BearerAuth:
|
||||||
in: header
|
in: header
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ var orderWritableColumns = []string{
|
|||||||
"status", "notes",
|
"status", "notes",
|
||||||
"sender_full_name", "sender_passport_serie", "sender_passport_number", "sender_deposit_account",
|
"sender_full_name", "sender_passport_serie", "sender_passport_number", "sender_deposit_account",
|
||||||
"reciever_full_name", "reciever_passport_serie", "reciever_passport_number", "reciever_deposit_account",
|
"reciever_full_name", "reciever_passport_serie", "reciever_passport_number", "reciever_deposit_account",
|
||||||
"paid",
|
"amount_usd", "paid",
|
||||||
}
|
}
|
||||||
|
|
||||||
var orderColumns = append(append([]string{"id"}, orderWritableColumns...), "created_at", "updated_at")
|
var orderColumns = append(append([]string{"id"}, orderWritableColumns...), "created_at", "updated_at")
|
||||||
@@ -81,7 +81,7 @@ func createArgs(dto visamaster.CreateVisaMasterPaymentOrderDTO) []interface{} {
|
|||||||
resolveStatus(dto.Status), dto.Notes,
|
resolveStatus(dto.Status), dto.Notes,
|
||||||
dto.SenderFullName, dto.SenderPassportSerie, dto.SenderPassportNumber, dto.SenderDepositAccount,
|
dto.SenderFullName, dto.SenderPassportSerie, dto.SenderPassportNumber, dto.SenderDepositAccount,
|
||||||
dto.RecieverFullName, dto.RecieverPassportSerie, dto.RecieverPassportNumber, dto.RecieverDepositAccount,
|
dto.RecieverFullName, dto.RecieverPassportSerie, dto.RecieverPassportNumber, dto.RecieverDepositAccount,
|
||||||
resolvePaid(dto.Paid),
|
dto.AmountUsd, resolvePaid(dto.Paid),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func updateArgs(dto visamaster.UpdateVisaMasterPaymentOrderDTO) []interface{} {
|
|||||||
resolveStatus(dto.Status), dto.Notes,
|
resolveStatus(dto.Status), dto.Notes,
|
||||||
dto.SenderFullName, dto.SenderPassportSerie, dto.SenderPassportNumber, dto.SenderDepositAccount,
|
dto.SenderFullName, dto.SenderPassportSerie, dto.SenderPassportNumber, dto.SenderDepositAccount,
|
||||||
dto.RecieverFullName, dto.RecieverPassportSerie, dto.RecieverPassportNumber, dto.RecieverDepositAccount,
|
dto.RecieverFullName, dto.RecieverPassportSerie, dto.RecieverPassportNumber, dto.RecieverDepositAccount,
|
||||||
dto.Paid,
|
dto.AmountUsd, dto.Paid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ func scanOrder(row genericrepo.Scanner) (visamaster.VisaMasterPaymentOrderDTO, e
|
|||||||
&item.Status, &item.Notes,
|
&item.Status, &item.Notes,
|
||||||
&item.SenderFullName, &item.SenderPassportSerie, &item.SenderPassportNumber, &item.SenderDepositAccount,
|
&item.SenderFullName, &item.SenderPassportSerie, &item.SenderPassportNumber, &item.SenderDepositAccount,
|
||||||
&item.RecieverFullName, &item.RecieverPassportSerie, &item.RecieverPassportNumber, &item.RecieverDepositAccount,
|
&item.RecieverFullName, &item.RecieverPassportSerie, &item.RecieverPassportNumber, &item.RecieverDepositAccount,
|
||||||
&item.Paid, &item.CreatedAt, &item.UpdatedAt,
|
&item.AmountUsd, &item.Paid, &item.CreatedAt, &item.UpdatedAt,
|
||||||
®ionNameJSON, &branchNameJSON, &item.Branch.UniqueCode, &branchRegion, &item.Branch.ProvinceId, &provinceNameJSON,
|
®ionNameJSON, &branchNameJSON, &item.Branch.UniqueCode, &branchRegion, &item.Branch.ProvinceId, &provinceNameJSON,
|
||||||
&userName, &userUsername, &userPhone, &userEmail,
|
&userName, &userUsername, &userPhone, &userEmail,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ type VisaMasterPaymentOrderDTO struct {
|
|||||||
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
||||||
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
||||||
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
||||||
|
AmountUsd *float64 `json:"amountUsd"`
|
||||||
Paid bool `json:"paid"`
|
Paid bool `json:"paid"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
@@ -73,6 +74,7 @@ type CreateVisaMasterPaymentOrderDTO struct {
|
|||||||
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
||||||
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
||||||
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
||||||
|
AmountUsd float64 `json:"amountUsd" binding:"required"`
|
||||||
Paid *bool `json:"paid"`
|
Paid *bool `json:"paid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +102,7 @@ type UpdateVisaMasterPaymentOrderDTO struct {
|
|||||||
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
||||||
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
||||||
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
||||||
|
AmountUsd float64 `json:"amountUsd" binding:"required"`
|
||||||
Paid bool `json:"paid"`
|
Paid bool `json:"paid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ import (
|
|||||||
"online-back/internal/identity/rbac"
|
"online-back/internal/identity/rbac"
|
||||||
"online-back/internal/lending"
|
"online-back/internal/lending"
|
||||||
"online-back/internal/org"
|
"online-back/internal/org"
|
||||||
|
"online-back/internal/payment"
|
||||||
"online-back/pkg/logging"
|
"online-back/pkg/logging"
|
||||||
|
"online-back/pkg/paymentgateway"
|
||||||
|
|
||||||
"github.com/gin-contrib/cors"
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -68,7 +70,9 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.
|
|||||||
org.Register(adminGroup, client, logger)
|
org.Register(adminGroup, client, logger)
|
||||||
lending.Register(adminGroup, client, logger)
|
lending.Register(adminGroup, client, logger)
|
||||||
cards.Register(adminGroup, client, logger)
|
cards.Register(adminGroup, client, logger)
|
||||||
currency.NewHandler(logger, currencydb.NewRepository(client, logger)).Register(adminGroup)
|
currencyRepo := currencydb.NewRepository(client, logger)
|
||||||
|
payment.Register(adminGroup, client, logger, currencyRepo, paymentgateway.NewLogClient(logger))
|
||||||
|
currency.NewHandler(logger, currencyRepo).Register(adminGroup)
|
||||||
dashboard.NewHandler(logger, dashboarddb.NewRepository(client, logger)).Register(adminGroup)
|
dashboard.NewHandler(logger, dashboarddb.NewRepository(client, logger)).Register(adminGroup)
|
||||||
|
|
||||||
backupDir := filepath.Join(cfg.PublicFilePath, "backups")
|
backupDir := filepath.Join(cfg.PublicFilePath, "backups")
|
||||||
|
|||||||
@@ -622,6 +622,9 @@ func adminPathPermission(method, path string) string {
|
|||||||
|
|
||||||
case matchesPrefix(rest, []string{"/currencies"}):
|
case matchesPrefix(rest, []string{"/currencies"}):
|
||||||
return viewOrManage(method, "currencies")
|
return viewOrManage(method, "currencies")
|
||||||
|
|
||||||
|
case matchesPrefix(rest, []string{"/payment-settings"}):
|
||||||
|
return viewOrManage(method, "payment-settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
@@ -675,4 +678,5 @@ var operatorGetPrefixes = []string{
|
|||||||
"/provinces",
|
"/provinces",
|
||||||
"/branches",
|
"/branches",
|
||||||
"/currencies",
|
"/currencies",
|
||||||
|
"/payment-settings",
|
||||||
}
|
}
|
||||||
@@ -400,6 +400,8 @@ func TestAdminPathPermission(t *testing.T) {
|
|||||||
{http.MethodPost, "/api/admin/backups", "backups.manage"},
|
{http.MethodPost, "/api/admin/backups", "backups.manage"},
|
||||||
{http.MethodGet, "/api/admin/currencies", "currencies.view"},
|
{http.MethodGet, "/api/admin/currencies", "currencies.view"},
|
||||||
{http.MethodPost, "/api/admin/currencies", "currencies.manage"},
|
{http.MethodPost, "/api/admin/currencies", "currencies.manage"},
|
||||||
|
{http.MethodGet, "/api/admin/payment-settings", "payment-settings.view"},
|
||||||
|
{http.MethodPut, "/api/admin/payment-settings", "payment-settings.manage"},
|
||||||
{http.MethodGet, "/api/admin/dashboard", ""},
|
{http.MethodGet, "/api/admin/dashboard", ""},
|
||||||
{http.MethodGet, "/api/admin/profile", ""},
|
{http.MethodGet, "/api/admin/profile", ""},
|
||||||
{http.MethodPost, "/api/admin/file", ""},
|
{http.MethodPost, "/api/admin/file", ""},
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"online-back/internal/payment/paymentsettings"
|
||||||
|
"online-back/pkg/client/postgresql"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
)
|
||||||
|
|
||||||
|
type repository struct {
|
||||||
|
client postgresql.Client
|
||||||
|
logger *logging.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(client postgresql.Client, logger *logging.Logger) paymentsettings.Repository {
|
||||||
|
return &repository{client: client, logger: logger}
|
||||||
|
}
|
||||||
|
|
||||||
|
const settingsColumnsSQL = `bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt, tveb_fee_usd, updated_by, updated_at`
|
||||||
|
|
||||||
|
func (r *repository) Get(ctx context.Context) (paymentsettings.PaymentSettingsDTO, error) {
|
||||||
|
row := r.client.QueryRow(ctx, `SELECT `+settingsColumnsSQL+` FROM payment_settings WHERE id = 1`)
|
||||||
|
return scanSettings(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *repository) Update(ctx context.Context, dto paymentsettings.UpdatePaymentSettingsDTO) (paymentsettings.PaymentSettingsDTO, error) {
|
||||||
|
query := `
|
||||||
|
UPDATE payment_settings SET
|
||||||
|
bank_fee_tmt = $1, gbus_fee_tmt = $2, sber_bank_fee_tmt = $3, tveb_fee_usd = $4, updated_by = $5,
|
||||||
|
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
|
||||||
|
WHERE id = 1
|
||||||
|
RETURNING ` + settingsColumnsSQL
|
||||||
|
|
||||||
|
return scanSettings(r.client.QueryRow(ctx, query,
|
||||||
|
dto.BankFeeTmt, dto.GbusFeeTmt, dto.SberBankFeeTmt, dto.TvebFeeUsd, dto.UpdatedBy,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanSettings(row interface {
|
||||||
|
Scan(dest ...interface{}) error
|
||||||
|
}) (paymentsettings.PaymentSettingsDTO, error) {
|
||||||
|
var item paymentsettings.PaymentSettingsDTO
|
||||||
|
if err := row.Scan(
|
||||||
|
&item.BankFeeTmt, &item.GbusFeeTmt, &item.SberBankFeeTmt, &item.TvebFeeUsd, &item.UpdatedById, &item.UpdatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return paymentsettings.PaymentSettingsDTO{}, err
|
||||||
|
}
|
||||||
|
return item, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package paymentsettings
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type PaymentSettingsDTO struct {
|
||||||
|
BankFeeTmt float64 `json:"bankFeeTmt"`
|
||||||
|
GbusFeeTmt float64 `json:"gbusFeeTmt"`
|
||||||
|
SberBankFeeTmt float64 `json:"sberBankFeeTmt"`
|
||||||
|
TvebFeeUsd float64 `json:"tvebFeeUsd"`
|
||||||
|
UpdatedById *int64 `json:"-"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePaymentSettingsDTO struct {
|
||||||
|
BankFeeTmt float64 `json:"bankFeeTmt" binding:"required"`
|
||||||
|
GbusFeeTmt float64 `json:"gbusFeeTmt" binding:"required"`
|
||||||
|
SberBankFeeTmt float64 `json:"sberBankFeeTmt" binding:"required"`
|
||||||
|
TvebFeeUsd float64 `json:"tvebFeeUsd" binding:"required"`
|
||||||
|
UpdatedBy *int64 `json:"-"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package paymentsettings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"online-back/internal/appresult"
|
||||||
|
"online-back/internal/handlers"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const baseURL = "/payment-settings"
|
||||||
|
|
||||||
|
type handler struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
repository Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler {
|
||||||
|
return &handler{logger: logger, repository: repository}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) Register(router *gin.RouterGroup) {
|
||||||
|
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
||||||
|
group.GET("", h.get)
|
||||||
|
group.PUT("", h.update)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get godoc
|
||||||
|
// @Summary Get payment settings
|
||||||
|
// @Description Returns the admin-configurable bank and GBÜS commission fees used on loan payments
|
||||||
|
// @Tags payment-settings
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Success 200 {object} PaymentSettingsDTO
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /payment-settings [get]
|
||||||
|
func (h *handler) get(c *gin.Context) {
|
||||||
|
item, err := h.repository.Get(c.Request.Context())
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Errorf("get payment settings failed: %v", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
|
||||||
|
}
|
||||||
|
|
||||||
|
// update godoc
|
||||||
|
// @Summary Update payment settings
|
||||||
|
// @Description Updates the bank and GBÜS commission fees used on loan payments
|
||||||
|
// @Tags payment-settings
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param body body UpdatePaymentSettingsDTO true "Payment settings payload"
|
||||||
|
// @Success 200 {object} PaymentSettingsDTO
|
||||||
|
// @Failure 400 {object} appresult.AppError
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /payment-settings [put]
|
||||||
|
func (h *handler) update(c *gin.Context) {
|
||||||
|
var dto UpdatePaymentSettingsDTO
|
||||||
|
if err := c.ShouldBindJSON(&dto); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dto.UpdatedBy = currentUserID(c)
|
||||||
|
|
||||||
|
item, err := h.repository.Update(c.Request.Context(), dto)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.Errorf("update payment settings failed: %v", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
|
||||||
|
}
|
||||||
|
|
||||||
|
func currentUserID(c *gin.Context) *int64 {
|
||||||
|
rawID, exists := c.Get("id")
|
||||||
|
if !exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch id := rawID.(type) {
|
||||||
|
case int64:
|
||||||
|
if id > 0 {
|
||||||
|
return &id
|
||||||
|
}
|
||||||
|
case int:
|
||||||
|
if id > 0 {
|
||||||
|
v := int64(id)
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
case string:
|
||||||
|
parsed, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err == nil && parsed > 0 {
|
||||||
|
return &parsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package paymentsettings
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Repository interface {
|
||||||
|
Get(ctx context.Context) (PaymentSettingsDTO, error)
|
||||||
|
Update(ctx context.Context, dto UpdatePaymentSettingsDTO) (PaymentSettingsDTO, error)
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Package payment groups the payment processing bounded context (admin-
|
||||||
|
// configurable fee settings, gateway integrations, and payout actions for
|
||||||
|
// orders owned by other bounded contexts) as its own module, following the
|
||||||
|
// same pattern as cards, lending, and org.
|
||||||
|
package payment
|
||||||
|
|
||||||
|
import (
|
||||||
|
"online-back/internal/currency"
|
||||||
|
"online-back/internal/handlers"
|
||||||
|
"online-back/internal/payment/paymentsettings"
|
||||||
|
paymentsettingsdb "online-back/internal/payment/paymentsettings/db"
|
||||||
|
"online-back/internal/payment/visamasterpay"
|
||||||
|
visamasterpaydb "online-back/internal/payment/visamasterpay/db"
|
||||||
|
"online-back/pkg/client/postgresql"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
"online-back/pkg/paymentgateway"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register wires every payment module's handler onto router.
|
||||||
|
func Register(router *gin.RouterGroup, client postgresql.Client, logger *logging.Logger, currencyRepo currency.Repository, gateway paymentgateway.Client) {
|
||||||
|
for _, h := range Handlers(client, logger, currencyRepo, gateway) {
|
||||||
|
h.Register(router)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Handlers(client postgresql.Client, logger *logging.Logger, currencyRepo currency.Repository, gateway paymentgateway.Client) []handlers.Handler {
|
||||||
|
settingsRepo := paymentsettingsdb.NewRepository(client, logger)
|
||||||
|
return []handlers.Handler{
|
||||||
|
paymentsettings.NewHandler(logger, settingsRepo),
|
||||||
|
visamasterpay.NewHandler(logger, visamasterpaydb.NewRepository(client, logger, currencyRepo, settingsRepo, gateway)),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"online-back/internal/currency"
|
||||||
|
"online-back/internal/payment/paymentsettings"
|
||||||
|
"online-back/internal/payment/visamasterpay"
|
||||||
|
"online-back/pkg/client/postgresql"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
"online-back/pkg/paymentgateway"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
// orderTypeSber identifies Sber orders (case-insensitive, matched against
|
||||||
|
// visa_master_payment_orders.type), which use a different fee/rate model
|
||||||
|
// than the default Visa/Master orders: no GBÜS fee, their own bank fee,
|
||||||
|
// and a USD-denominated TVEB fee, plus a RUB reference rate.
|
||||||
|
const orderTypeSber = "sber"
|
||||||
|
|
||||||
|
type repository struct {
|
||||||
|
client postgresql.Client
|
||||||
|
currencyRepo currency.Repository
|
||||||
|
settingsRepo paymentsettings.Repository
|
||||||
|
gateway paymentgateway.Client
|
||||||
|
logger *logging.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(
|
||||||
|
client postgresql.Client,
|
||||||
|
logger *logging.Logger,
|
||||||
|
currencyRepo currency.Repository,
|
||||||
|
settingsRepo paymentsettings.Repository,
|
||||||
|
gateway paymentgateway.Client,
|
||||||
|
) visamasterpay.Repository {
|
||||||
|
return &repository{
|
||||||
|
client: client,
|
||||||
|
currencyRepo: currencyRepo,
|
||||||
|
settingsRepo: settingsRepo,
|
||||||
|
gateway: gateway,
|
||||||
|
logger: logger,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OwnerInfo returns the order's owner/branch for rbac.GuardOrder, so the
|
||||||
|
// handler can authorize a request without importing cards/visamaster.
|
||||||
|
func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error) {
|
||||||
|
var userID *int64
|
||||||
|
var branchID int64
|
||||||
|
err := r.client.QueryRow(ctx,
|
||||||
|
`SELECT user_id, branch_id FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||||
|
).Scan(&userID, &branchID)
|
||||||
|
return userID, branchID, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *repository) Quote(ctx context.Context, orderID int64) (visamasterpay.PaymentQuoteDTO, error) {
|
||||||
|
var orderType *string
|
||||||
|
var amountUsd *float64
|
||||||
|
var paid bool
|
||||||
|
err := r.client.QueryRow(ctx,
|
||||||
|
`SELECT type, amount_usd, paid FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||||
|
).Scan(&orderType, &amountUsd, &paid)
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, err
|
||||||
|
}
|
||||||
|
if paid {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, visamasterpay.ErrAlreadyPaid
|
||||||
|
}
|
||||||
|
if amountUsd == nil {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, visamasterpay.ErrAmountNotSet
|
||||||
|
}
|
||||||
|
|
||||||
|
usdRate, err := r.fetchRate(ctx, "USD")
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
settings, err := r.settingsRepo.Get(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
quote := visamasterpay.PaymentQuoteDTO{
|
||||||
|
Type: derefOrEmpty(orderType),
|
||||||
|
ExchangeRateUsd: usdRate,
|
||||||
|
MaxAmountTmt: round2(*amountUsd * usdRate),
|
||||||
|
}
|
||||||
|
|
||||||
|
if isSber(orderType) {
|
||||||
|
rubRate, err := r.fetchRate(ctx, "RUB")
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentQuoteDTO{}, err
|
||||||
|
}
|
||||||
|
tvebFeeTmt := round2(settings.TvebFeeUsd * usdRate)
|
||||||
|
|
||||||
|
quote.ExchangeRateRub = &rubRate
|
||||||
|
quote.BankFeeTmt = settings.SberBankFeeTmt
|
||||||
|
quote.TvebFeeUsd = &settings.TvebFeeUsd
|
||||||
|
quote.TvebFeeTmt = &tvebFeeTmt
|
||||||
|
} else {
|
||||||
|
quote.BankFeeTmt = settings.BankFeeTmt
|
||||||
|
quote.GbusFeeTmt = &settings.GbusFeeTmt
|
||||||
|
}
|
||||||
|
|
||||||
|
return quote, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pay charges the gateway, then persists the result with a single atomic
|
||||||
|
// UPDATE guarded by `paid = false`. No explicit transaction/row lock is
|
||||||
|
// needed - unlike a running balance, this is a one-time state flip, so the
|
||||||
|
// guarded UPDATE is itself the race check (zero rows affected means
|
||||||
|
// someone else paid it first). A gateway failure is not returned as a Go
|
||||||
|
// error: it's written into gateway_status and returned normally, matching
|
||||||
|
// how this codebase already models order lifecycle via status columns.
|
||||||
|
func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.PayOrderDTO) (visamasterpay.PaymentResultDTO, error) {
|
||||||
|
var orderType *string
|
||||||
|
var amountUsd *float64
|
||||||
|
var paid bool
|
||||||
|
var senderAccount string
|
||||||
|
err := r.client.QueryRow(ctx,
|
||||||
|
`SELECT type, amount_usd, paid, sender_deposit_account FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`,
|
||||||
|
orderID,
|
||||||
|
).Scan(&orderType, &amountUsd, &paid, &senderAccount)
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, err
|
||||||
|
}
|
||||||
|
if paid {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, visamasterpay.ErrAlreadyPaid
|
||||||
|
}
|
||||||
|
if amountUsd == nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, visamasterpay.ErrAmountNotSet
|
||||||
|
}
|
||||||
|
|
||||||
|
usdRate, err := r.fetchRate(ctx, "USD")
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
settings, err := r.settingsRepo.Get(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
maxAmountTmt := round2(*amountUsd * usdRate)
|
||||||
|
amountTmt := maxAmountTmt
|
||||||
|
if dto.AmountTmt != nil {
|
||||||
|
if *dto.AmountTmt <= 0 || *dto.AmountTmt > maxAmountTmt {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, visamasterpay.ErrAmountExceedsMax
|
||||||
|
}
|
||||||
|
amountTmt = round2(*dto.AmountTmt)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rubRate *float64
|
||||||
|
var bankFeeTmt float64
|
||||||
|
var gbusFeeTmt, tvebFeeUsd, tvebFeeTmt *float64
|
||||||
|
var total float64
|
||||||
|
|
||||||
|
if isSber(orderType) {
|
||||||
|
rate, err := r.fetchRate(ctx, "RUB")
|
||||||
|
if err != nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, err
|
||||||
|
}
|
||||||
|
tveb := round2(settings.TvebFeeUsd * usdRate)
|
||||||
|
|
||||||
|
rubRate = &rate
|
||||||
|
bankFeeTmt = settings.SberBankFeeTmt
|
||||||
|
tvebFeeUsd = &settings.TvebFeeUsd
|
||||||
|
tvebFeeTmt = &tveb
|
||||||
|
total = round2(amountTmt + bankFeeTmt + tveb)
|
||||||
|
} else {
|
||||||
|
bankFeeTmt = settings.BankFeeTmt
|
||||||
|
gbusFeeTmt = &settings.GbusFeeTmt
|
||||||
|
total = round2(amountTmt + bankFeeTmt + settings.GbusFeeTmt)
|
||||||
|
}
|
||||||
|
|
||||||
|
period := time.Now()
|
||||||
|
if dto.PaymentPeriod != nil {
|
||||||
|
period = dto.PaymentPeriod.Time()
|
||||||
|
}
|
||||||
|
|
||||||
|
reference := fmt.Sprintf("vmo-%d-%d", orderID, time.Now().UnixNano())
|
||||||
|
result, chargeErr := r.gateway.Charge(ctx, paymentgateway.ChargeRequest{
|
||||||
|
Reference: reference,
|
||||||
|
AccountNumber: senderAccount,
|
||||||
|
AmountTmt: fmt.Sprintf("%.2f", amountTmt),
|
||||||
|
})
|
||||||
|
|
||||||
|
status := "success"
|
||||||
|
var gatewayRef *string
|
||||||
|
if chargeErr != nil || result.Status != "success" {
|
||||||
|
status = "failed"
|
||||||
|
if r.logger != nil && chargeErr != nil {
|
||||||
|
r.logger.Errorf("visa master payment gateway charge failed for order %d: %v", orderID, chargeErr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gatewayRef = nonEmptyRef(result.ProviderReference)
|
||||||
|
}
|
||||||
|
paidNow := status == "success"
|
||||||
|
|
||||||
|
query := `
|
||||||
|
UPDATE visa_master_payment_orders SET
|
||||||
|
exchange_rate = $1, exchange_rate_rub = $2, amount_tmt = $3,
|
||||||
|
bank_fee_tmt = $4, gbus_fee_tmt = $5, tveb_fee_usd = $6, tveb_fee_tmt = $7,
|
||||||
|
total_amount_tmt = $8, payment_period = $9, gateway_status = $10, gateway_reference = $11,
|
||||||
|
paid = $12, paid_at = CASE WHEN $12 THEN (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') ELSE paid_at END,
|
||||||
|
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
|
||||||
|
WHERE id = $13 AND paid = false
|
||||||
|
RETURNING id, type, paid, amount_usd, exchange_rate, exchange_rate_rub, amount_tmt,
|
||||||
|
bank_fee_tmt, gbus_fee_tmt, tveb_fee_usd, tveb_fee_tmt, total_amount_tmt,
|
||||||
|
payment_period, gateway_status, gateway_reference, paid_at`
|
||||||
|
|
||||||
|
item, err := scanResult(r.client.QueryRow(ctx, query,
|
||||||
|
usdRate, rubRate, amountTmt,
|
||||||
|
bankFeeTmt, gbusFeeTmt, tvebFeeUsd, tvebFeeTmt,
|
||||||
|
total, period, status, gatewayRef, paidNow, orderID,
|
||||||
|
))
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, visamasterpay.ErrAlreadyPaid
|
||||||
|
}
|
||||||
|
return item, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *repository) fetchRate(ctx context.Context, from string) (float64, error) {
|
||||||
|
result, err := r.currencyRepo.List(ctx, currency.ListFilter{CurrencyFrom: from, CurrencyTo: "TMT", Page: 1, Limit: 1})
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if len(result.Currencies) == 0 {
|
||||||
|
return 0, pgx.ErrNoRows
|
||||||
|
}
|
||||||
|
return strconv.ParseFloat(result.Currencies[0].Value.String(), 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSber(orderType *string) bool {
|
||||||
|
return orderType != nil && strings.EqualFold(strings.TrimSpace(*orderType), orderTypeSber)
|
||||||
|
}
|
||||||
|
|
||||||
|
func derefOrEmpty(s *string) string {
|
||||||
|
if s == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *s
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanResult(row pgx.Row) (visamasterpay.PaymentResultDTO, error) {
|
||||||
|
var item visamasterpay.PaymentResultDTO
|
||||||
|
var orderType *string
|
||||||
|
var amountUsd *float64
|
||||||
|
if err := row.Scan(
|
||||||
|
&item.OrderId, &orderType, &item.Paid, &amountUsd, &item.ExchangeRateUsd, &item.ExchangeRateRub, &item.AmountTmt,
|
||||||
|
&item.BankFeeTmt, &item.GbusFeeTmt, &item.TvebFeeUsd, &item.TvebFeeTmt, &item.TotalAmountTmt,
|
||||||
|
&item.PaymentPeriod, &item.GatewayStatus, &item.GatewayReference, &item.PaidAt,
|
||||||
|
); err != nil {
|
||||||
|
return visamasterpay.PaymentResultDTO{}, err
|
||||||
|
}
|
||||||
|
item.Type = derefOrEmpty(orderType)
|
||||||
|
if amountUsd != nil {
|
||||||
|
item.AmountUsd = *amountUsd
|
||||||
|
}
|
||||||
|
return item, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func round2(v float64) float64 {
|
||||||
|
return math.Round(v*100) / 100
|
||||||
|
}
|
||||||
|
|
||||||
|
func nonEmptyRef(s string) *string {
|
||||||
|
if s == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &s
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package visamasterpay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"online-back/internal/shared"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PaymentQuoteDTO is what the "Töleg" modal loads before the operator picks
|
||||||
|
// an amount. Which fields are populated depends on the order's type:
|
||||||
|
// Visa/Master orders use BankFeeTmt + GbusFeeTmt against the USD rate;
|
||||||
|
// Sber orders have no GBÜS fee but add a USD-denominated TVEB fee (shown
|
||||||
|
// both as-is and converted to TMT) and also show the RUB rate for
|
||||||
|
// reference, using their own SberBankFeeTmt instead of BankFeeTmt.
|
||||||
|
type PaymentQuoteDTO struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
ExchangeRateUsd float64 `json:"exchangeRateUsd"`
|
||||||
|
ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"`
|
||||||
|
BankFeeTmt float64 `json:"bankFeeTmt"`
|
||||||
|
GbusFeeTmt *float64 `json:"gbusFeeTmt,omitempty"`
|
||||||
|
TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"`
|
||||||
|
TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"`
|
||||||
|
MaxAmountTmt float64 `json:"maxAmountTmt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PayOrderDTO submits a payout for a visa/master/sber order. AmountTmt is
|
||||||
|
// optional: if omitted, the full requested amount (amount_usd * rate) is
|
||||||
|
// paid; if provided (the modal's amount field is editable, capped at the
|
||||||
|
// max), it's validated against that max instead. PaymentPeriod is
|
||||||
|
// optional too - only the Visa/Master modal shows a payment-month picker;
|
||||||
|
// Sber orders default to the current month when omitted.
|
||||||
|
type PayOrderDTO struct {
|
||||||
|
PaymentPeriod *shared.FlexibleTime `json:"paymentPeriod" swaggertype:"string" format:"date"`
|
||||||
|
AmountTmt *float64 `json:"amountTmt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PaymentResultDTO is a flat, payment-focused view of the order's payout
|
||||||
|
// state — deliberately not the full order+branch+user DTO owned by
|
||||||
|
// cards/visamaster (fetch that separately via GET /visa-master-payment-orders/:id).
|
||||||
|
type PaymentResultDTO struct {
|
||||||
|
OrderId int64 `json:"orderId"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Paid bool `json:"paid"`
|
||||||
|
AmountUsd float64 `json:"amountUsd"`
|
||||||
|
ExchangeRateUsd float64 `json:"exchangeRateUsd"`
|
||||||
|
ExchangeRateRub *float64 `json:"exchangeRateRub,omitempty"`
|
||||||
|
AmountTmt float64 `json:"amountTmt"`
|
||||||
|
BankFeeTmt float64 `json:"bankFeeTmt"`
|
||||||
|
GbusFeeTmt *float64 `json:"gbusFeeTmt,omitempty"`
|
||||||
|
TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"`
|
||||||
|
TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"`
|
||||||
|
TotalAmountTmt float64 `json:"totalAmountTmt"`
|
||||||
|
PaymentPeriod *time.Time `json:"paymentPeriod,omitempty"`
|
||||||
|
GatewayStatus string `json:"gatewayStatus"`
|
||||||
|
GatewayReference *string `json:"gatewayReference,omitempty"`
|
||||||
|
PaidAt *time.Time `json:"paidAt,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package visamasterpay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"online-back/internal/appresult"
|
||||||
|
"online-back/internal/handlers"
|
||||||
|
"online-back/internal/identity/rbac"
|
||||||
|
"online-back/internal/shared"
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
const baseURL = "/visa-master-payment-orders"
|
||||||
|
|
||||||
|
type handler struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
repository Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler {
|
||||||
|
return &handler{logger: logger, repository: repository}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) Register(router *gin.RouterGroup) {
|
||||||
|
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
||||||
|
group.GET("/:id/quote", h.quote)
|
||||||
|
group.POST("/:id/pay", h.pay)
|
||||||
|
}
|
||||||
|
|
||||||
|
// quote godoc
|
||||||
|
// @Summary Quote a visa/master/sber payment
|
||||||
|
// @Description Returns the current rate, configured fees, and max payable amount for an order's payout
|
||||||
|
// @Tags visa-master-payment-orders
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path int true "Visa/master payment order ID"
|
||||||
|
// @Success 200 {object} PaymentQuoteDTO
|
||||||
|
// @Failure 400 {object} appresult.AppError
|
||||||
|
// @Failure 404 {object} appresult.AppError
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /visa-master-payment-orders/{id}/quote [get]
|
||||||
|
func (h *handler) quote(c *gin.Context) {
|
||||||
|
id, ok := shared.ParseID(c.Param("id"))
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !h.guardOrder(c, id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.repository.Quote(c.Request.Context(), id)
|
||||||
|
if h.handleQuoteOrPayError(c, err, "quote") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
// pay godoc
|
||||||
|
// @Summary Pay out a visa/master/sber order
|
||||||
|
// @Description Charges the payment gateway and marks the order paid on success
|
||||||
|
// @Tags visa-master-payment-orders
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path int true "Visa/master payment order ID"
|
||||||
|
// @Param body body PayOrderDTO true "Payment payload"
|
||||||
|
// @Success 200 {object} PaymentResultDTO
|
||||||
|
// @Failure 400 {object} appresult.AppError
|
||||||
|
// @Failure 404 {object} appresult.AppError
|
||||||
|
// @Failure 500 {object} appresult.AppError
|
||||||
|
// @Router /visa-master-payment-orders/{id}/pay [post]
|
||||||
|
func (h *handler) pay(c *gin.Context) {
|
||||||
|
id, ok := shared.ParseID(c.Param("id"))
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !h.guardOrder(c, id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var dto PayOrderDTO
|
||||||
|
if err := c.ShouldBindJSON(&dto); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.repository.Pay(c.Request.Context(), id, dto)
|
||||||
|
if h.handleQuoteOrPayError(c, err, "pay") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) guardOrder(c *gin.Context, id int64) bool {
|
||||||
|
if rbac.SkipRecordGuard(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
userID, branchID, err := h.repository.OwnerInfo(c.Request.Context(), id)
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return rbac.GuardOrder(c, userID, branchID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleQuoteOrPayError writes the appropriate response for a Quote/Pay
|
||||||
|
// error and reports whether the caller should stop (true) or continue with
|
||||||
|
// a successful result (false).
|
||||||
|
func (h *handler) handleQuoteOrPayError(c *gin.Context, err error, action string) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, pgx.ErrNoRows):
|
||||||
|
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||||
|
case errors.Is(err, ErrAlreadyPaid), errors.Is(err, ErrAmountNotSet), errors.Is(err, ErrAmountExceedsMax):
|
||||||
|
c.JSON(http.StatusBadRequest, appresult.ErrNotAcceptable)
|
||||||
|
default:
|
||||||
|
h.logger.Errorf("%s visa master payment order failed: %v", action, err)
|
||||||
|
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package visamasterpay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ErrAlreadyPaid is returned when the order has already been paid out (or
|
||||||
|
// was paid by a concurrent request that won the race).
|
||||||
|
var ErrAlreadyPaid = errors.New("order already paid")
|
||||||
|
|
||||||
|
// ErrAmountNotSet is returned when the order has no amount_usd set yet.
|
||||||
|
var ErrAmountNotSet = errors.New("order has no requested amount")
|
||||||
|
|
||||||
|
// ErrAmountExceedsMax is returned when the submitted amountTmt is above
|
||||||
|
// what the order's amount_usd converts to at the current rate.
|
||||||
|
var ErrAmountExceedsMax = errors.New("amount exceeds the order's requested amount")
|
||||||
|
|
||||||
|
type Repository interface {
|
||||||
|
// OwnerInfo returns the order's owner/branch so the handler can run
|
||||||
|
// rbac.GuardOrder without importing cards/visamaster.
|
||||||
|
OwnerInfo(ctx context.Context, orderID int64) (userID *int64, branchID int64, err error)
|
||||||
|
Quote(ctx context.Context, orderID int64) (PaymentQuoteDTO, error)
|
||||||
|
Pay(ctx context.Context, orderID int64, dto PayOrderDTO) (PaymentResultDTO, error)
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package paymentgateway
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"online-back/pkg/logging"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChargeRequest describes a single debit to submit to the external payment
|
||||||
|
// gateway ("GBÜS") for a loan payment.
|
||||||
|
type ChargeRequest struct {
|
||||||
|
Reference string
|
||||||
|
AccountNumber string
|
||||||
|
AmountTmt string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChargeResult is the outcome of a Charge call.
|
||||||
|
type ChargeResult struct {
|
||||||
|
Status string // "success" or "failed"
|
||||||
|
ProviderReference string
|
||||||
|
RawResponse []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client charges a customer's account through the external gateway. Plug
|
||||||
|
// your real provider in by implementing this interface once GBÜS's API
|
||||||
|
// contract (base URL, auth, request/response shape) is available.
|
||||||
|
type Client interface {
|
||||||
|
Charge(ctx context.Context, req ChargeRequest) (ChargeResult, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogClient is a stand-in used until a real GBÜS client is wired in. It
|
||||||
|
// logs the charge and reports success so the loan payment flow is usable
|
||||||
|
// end-to-end in the meantime.
|
||||||
|
type LogClient struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLogClient(logger *logging.Logger) *LogClient {
|
||||||
|
return &LogClient{logger: logger}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *LogClient) Charge(_ context.Context, req ChargeRequest) (ChargeResult, error) {
|
||||||
|
reference := fmt.Sprintf("LOG-%s-%d", req.Reference, time.Now().UnixNano())
|
||||||
|
if c.logger != nil {
|
||||||
|
c.logger.Infof("payment gateway charge (stub): account=%s amount=%s reference=%s", req.AccountNumber, req.AmountTmt, reference)
|
||||||
|
}
|
||||||
|
return ChargeResult{Status: "success", ProviderReference: reference}, nil
|
||||||
|
}
|
||||||
Reference in new issue
Block a user