create invoice as app user
This commit is contained in:
parent
03b35e0bb8
commit
29f2493d6e
7 changed files with 2460 additions and 2421 deletions
|
|
@ -85,6 +85,8 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
|
|
||||||
- __User__:
|
- __User__:
|
||||||
- expected context content
|
- expected context content
|
||||||
|
- __app_id__: _string_
|
||||||
|
- __app_user_id__: _string_
|
||||||
- __user_id__: _string_
|
- __user_id__: _string_
|
||||||
|
|
||||||
- __Admin__:
|
- __Admin__:
|
||||||
|
|
@ -360,30 +362,91 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
## Messages
|
## Messages
|
||||||
### The content of requests and response from the methods
|
### The content of requests and response from the methods
|
||||||
|
|
||||||
|
### NewAddressRequest
|
||||||
|
- __addressType__: _[AddressType](#AddressType)_
|
||||||
|
|
||||||
|
### NewAddressResponse
|
||||||
|
- __address__: _string_
|
||||||
|
|
||||||
|
### LnurlPayInfoResponse
|
||||||
|
- __tag__: _string_
|
||||||
|
- __callback__: _string_
|
||||||
|
- __maxSendable__: _number_
|
||||||
|
- __minSendable__: _number_
|
||||||
|
- __metadata__: _string_
|
||||||
|
|
||||||
|
### AddAppUserRequest
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __fail_if_exists__: _boolean_
|
||||||
|
- __balance__: _number_
|
||||||
|
|
||||||
|
### PayAppUserInvoiceRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### SetMockAppUserBalanceRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### AuthUserResponse
|
||||||
|
- __userId__: _string_
|
||||||
|
- __authToken__: _string_
|
||||||
|
|
||||||
|
### AuthApp
|
||||||
|
- __app__: _[Application](#Application)_
|
||||||
|
- __auth_token__: _string_
|
||||||
|
|
||||||
|
### GetAppUserRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
|
### SendAppUserToAppPaymentRequest
|
||||||
|
- __from_user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### GetAppUserLNURLInfoRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __base_url_override__: _string_
|
||||||
|
|
||||||
|
### NewInvoiceRequest
|
||||||
|
- __amountSats__: _number_
|
||||||
|
- __memo__: _string_
|
||||||
|
|
||||||
### AddUserRequest
|
### AddUserRequest
|
||||||
- __callbackUrl__: _string_
|
- __callbackUrl__: _string_
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __secret__: _string_
|
- __secret__: _string_
|
||||||
|
|
||||||
|
### UserInfo
|
||||||
|
- __userId__: _string_
|
||||||
|
- __balance__: _number_
|
||||||
|
|
||||||
### UserOperation
|
### UserOperation
|
||||||
- __paidAtUnix__: _number_
|
- __paidAtUnix__: _number_
|
||||||
- __type__: _[UserOperationType](#UserOperationType)_
|
- __type__: _[UserOperationType](#UserOperationType)_
|
||||||
- __inbound__: _boolean_
|
- __inbound__: _boolean_
|
||||||
- __amount__: _number_
|
- __amount__: _number_
|
||||||
|
|
||||||
### LndGetInfoRequest
|
### AddAppUserInvoiceRequest
|
||||||
- __nodeId__: _number_
|
- __receiver_identifier__: _string_
|
||||||
|
- __payer_identifier__: _string_
|
||||||
|
- __http_callback_url__: _string_
|
||||||
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
|
|
||||||
### NewInvoiceRequest
|
### GetProductBuyLinkResponse
|
||||||
- __amountSats__: _number_
|
- __link__: _string_
|
||||||
- __memo__: _string_
|
|
||||||
|
|
||||||
### PayInvoiceResponse
|
### SetMockInvoiceAsPaidRequest
|
||||||
- __preimage__: _string_
|
- __invoice__: _string_
|
||||||
- __amount_paid__: _number_
|
- __amount__: _number_
|
||||||
|
|
||||||
### OpenChannelResponse
|
### PayInvoiceRequest
|
||||||
- __channelId__: _string_
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### LnurlLinkResponse
|
||||||
|
- __lnurl__: _string_
|
||||||
|
- __k1__: _string_
|
||||||
|
|
||||||
### LnurlWithdrawInfoResponse
|
### LnurlWithdrawInfoResponse
|
||||||
- __tag__: _string_
|
- __tag__: _string_
|
||||||
|
|
@ -395,104 +458,6 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __balanceCheck__: _string_
|
- __balanceCheck__: _string_
|
||||||
- __payLink__: _string_
|
- __payLink__: _string_
|
||||||
|
|
||||||
### HandleLnurlPayResponse
|
|
||||||
- __pr__: _string_
|
|
||||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
|
||||||
|
|
||||||
### UserOperations
|
|
||||||
- __fromIndex__: _number_
|
|
||||||
- __toIndex__: _number_
|
|
||||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
|
||||||
|
|
||||||
### PayInvoiceRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### AddUserResponse
|
|
||||||
- __userId__: _string_
|
|
||||||
- __authToken__: _string_
|
|
||||||
|
|
||||||
### AddAppUserRequest
|
|
||||||
- __identifier__: _string_
|
|
||||||
- __fail_if_exists__: _boolean_
|
|
||||||
- __balance__: _number_
|
|
||||||
|
|
||||||
### AddAppInvoiceRequest
|
|
||||||
- __payer_identifier__: _string_
|
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### AddAppUserInvoiceRequest
|
|
||||||
- __receiver_identifier__: _string_
|
|
||||||
- __payer_identifier__: _string_
|
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### PayAppUserInvoiceResponse
|
|
||||||
- __preimage__: _string_
|
|
||||||
- __amount_paid__: _number_
|
|
||||||
|
|
||||||
### SendAppUserToAppPaymentRequest
|
|
||||||
- __from_user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### NewAddressRequest
|
|
||||||
- __addressType__: _[AddressType](#AddressType)_
|
|
||||||
|
|
||||||
### UserInfo
|
|
||||||
- __userId__: _string_
|
|
||||||
- __balance__: _number_
|
|
||||||
|
|
||||||
### SetMockInvoiceAsPaidRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### SetMockAppBalanceRequest
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### AuthUserRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __secret__: _string_
|
|
||||||
|
|
||||||
### AuthUserResponse
|
|
||||||
- __userId__: _string_
|
|
||||||
- __authToken__: _string_
|
|
||||||
|
|
||||||
### Empty
|
|
||||||
|
|
||||||
### EncryptionExchangeRequest
|
|
||||||
- __publicKey__: _string_
|
|
||||||
- __deviceId__: _string_
|
|
||||||
|
|
||||||
### Application
|
|
||||||
- __name__: _string_
|
|
||||||
- __id__: _string_
|
|
||||||
- __balance__: _number_
|
|
||||||
- __npub__: _string_
|
|
||||||
|
|
||||||
### GetAppUserRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
|
|
||||||
### GetAppUserLNURLInfoRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __base_url_override__: _string_
|
|
||||||
|
|
||||||
### DecodeInvoiceRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
|
|
||||||
### AddAppRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __allow_user_creation__: _boolean_
|
|
||||||
|
|
||||||
### PayAddressResponse
|
|
||||||
- __txId__: _string_
|
|
||||||
|
|
||||||
### OpenChannelRequest
|
|
||||||
- __destination__: _string_
|
|
||||||
- __fundingAmount__: _number_
|
|
||||||
- __pushAmount__: _number_
|
|
||||||
- __closeAddress__: _string_
|
|
||||||
|
|
||||||
### GetUserOperationsRequest
|
### GetUserOperationsRequest
|
||||||
- __latestIncomingInvoice__: _number_
|
- __latestIncomingInvoice__: _number_
|
||||||
- __latestOutgoingInvoice__: _number_
|
- __latestOutgoingInvoice__: _number_
|
||||||
|
|
@ -501,32 +466,37 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __latestIncomingUserToUserPayment__: _number_
|
- __latestIncomingUserToUserPayment__: _number_
|
||||||
- __latestOutgoingUserToUserPayment__: _number_
|
- __latestOutgoingUserToUserPayment__: _number_
|
||||||
|
|
||||||
### GetProductBuyLinkResponse
|
### GetUserOperationsResponse
|
||||||
- __link__: _string_
|
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
|
|
||||||
### AuthAppRequest
|
### LndGetInfoRequest
|
||||||
|
- __nodeId__: _number_
|
||||||
|
|
||||||
|
### Application
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __allow_user_creation__: _boolean_ *this field is optional
|
- __id__: _string_
|
||||||
|
- __balance__: _number_
|
||||||
|
- __npub__: _string_
|
||||||
|
|
||||||
### AppUser
|
### PayAppUserInvoiceResponse
|
||||||
- __identifier__: _string_
|
- __preimage__: _string_
|
||||||
- __info__: _[UserInfo](#UserInfo)_
|
- __amount_paid__: _number_
|
||||||
- __max_withdrawable__: _number_
|
|
||||||
|
|
||||||
### SetMockAppUserBalanceRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### DecodeInvoiceResponse
|
### DecodeInvoiceResponse
|
||||||
- __amount__: _number_
|
- __amount__: _number_
|
||||||
|
|
||||||
### Product
|
### AuthUserRequest
|
||||||
- __id__: _string_
|
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __price_sats__: _number_
|
- __secret__: _string_
|
||||||
|
|
||||||
### LndGetInfoResponse
|
### EncryptionExchangeRequest
|
||||||
- __alias__: _string_
|
- __publicKey__: _string_
|
||||||
|
- __deviceId__: _string_
|
||||||
|
|
||||||
### SendAppUserToAppUserPaymentRequest
|
### SendAppUserToAppUserPaymentRequest
|
||||||
- __from_user_identifier__: _string_
|
- __from_user_identifier__: _string_
|
||||||
|
|
@ -541,40 +511,72 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
### NewInvoiceResponse
|
### NewInvoiceResponse
|
||||||
- __invoice__: _string_
|
- __invoice__: _string_
|
||||||
|
|
||||||
### LnurlLinkResponse
|
### PayInvoiceResponse
|
||||||
- __lnurl__: _string_
|
- __preimage__: _string_
|
||||||
- __k1__: _string_
|
- __amount_paid__: _number_
|
||||||
|
|
||||||
### AuthApp
|
### OpenChannelRequest
|
||||||
- __app__: _[Application](#Application)_
|
- __destination__: _string_
|
||||||
- __auth_token__: _string_
|
- __fundingAmount__: _number_
|
||||||
|
- __pushAmount__: _number_
|
||||||
|
- __closeAddress__: _string_
|
||||||
|
|
||||||
### PayAppUserInvoiceRequest
|
### UserOperations
|
||||||
- __user_identifier__: _string_
|
- __fromIndex__: _number_
|
||||||
- __invoice__: _string_
|
- __toIndex__: _number_
|
||||||
- __amount__: _number_
|
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||||
|
|
||||||
### NewAddressResponse
|
|
||||||
- __address__: _string_
|
|
||||||
|
|
||||||
### LnurlPayInfoResponse
|
|
||||||
- __tag__: _string_
|
|
||||||
- __callback__: _string_
|
|
||||||
- __maxSendable__: _number_
|
|
||||||
- __minSendable__: _number_
|
|
||||||
- __metadata__: _string_
|
|
||||||
|
|
||||||
### GetUserOperationsResponse
|
|
||||||
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
|
||||||
|
|
||||||
### AddProductRequest
|
### AddProductRequest
|
||||||
- __name__: _string_
|
- __name__: _string_
|
||||||
- __price_sats__: _number_
|
- __price_sats__: _number_
|
||||||
|
|
||||||
|
### AddAppRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __allow_user_creation__: _boolean_
|
||||||
|
|
||||||
|
### Product
|
||||||
|
- __id__: _string_
|
||||||
|
- __name__: _string_
|
||||||
|
- __price_sats__: _number_
|
||||||
|
|
||||||
|
### AppUser
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __info__: _[UserInfo](#UserInfo)_
|
||||||
|
- __max_withdrawable__: _number_
|
||||||
|
|
||||||
|
### AddAppInvoiceRequest
|
||||||
|
- __payer_identifier__: _string_
|
||||||
|
- __http_callback_url__: _string_
|
||||||
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
|
|
||||||
|
### PayAddressResponse
|
||||||
|
- __txId__: _string_
|
||||||
|
|
||||||
|
### OpenChannelResponse
|
||||||
|
- __channelId__: _string_
|
||||||
|
|
||||||
|
### HandleLnurlPayResponse
|
||||||
|
- __pr__: _string_
|
||||||
|
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||||
|
|
||||||
|
### AddUserResponse
|
||||||
|
- __userId__: _string_
|
||||||
|
- __authToken__: _string_
|
||||||
|
|
||||||
|
### AuthAppRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __allow_user_creation__: _boolean_ *this field is optional
|
||||||
|
|
||||||
|
### LndGetInfoResponse
|
||||||
|
- __alias__: _string_
|
||||||
|
|
||||||
|
### SetMockAppBalanceRequest
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### DecodeInvoiceRequest
|
||||||
|
- __invoice__: _string_
|
||||||
|
|
||||||
|
### Empty
|
||||||
## Enums
|
## Enums
|
||||||
### The enumerators used in the messages
|
### The enumerators used in the messages
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -17,10 +17,16 @@ option (file_options) = {
|
||||||
{
|
{
|
||||||
id: "user"
|
id: "user"
|
||||||
name: "User",
|
name: "User",
|
||||||
context:{
|
context:[{
|
||||||
key:"user_id",
|
key:"user_id",
|
||||||
value:"string"
|
value:"string"
|
||||||
}
|
},{
|
||||||
|
key:"app_id",
|
||||||
|
value:"string"
|
||||||
|
},{
|
||||||
|
key:"app_user_id",
|
||||||
|
value:"string"
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "admin",
|
id: "admin",
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const serverOptions = (mainHandler: Main): ServerOptions => {
|
||||||
logger: { log, error: err => log("ERROR", err) },
|
logger: { log, error: err => log("ERROR", err) },
|
||||||
AdminAuthGuard: adminAuth,
|
AdminAuthGuard: adminAuth,
|
||||||
AppAuthGuard: async (authHeader) => { return { app_id: mainHandler.applicationManager.DecodeAppToken(stripBearer(authHeader)) } },
|
AppAuthGuard: async (authHeader) => { return { app_id: mainHandler.applicationManager.DecodeAppToken(stripBearer(authHeader)) } },
|
||||||
UserAuthGuard: async (authHeader) => { return { user_id: mainHandler.userManager.DecodeUserToken(stripBearer(authHeader)) } },
|
UserAuthGuard: async (authHeader) => { return { user_id: mainHandler.userManager.DecodeUserToken(stripBearer(authHeader)), app_id: "", app_user_id: "" } },
|
||||||
GuestAuthGuard: async (_) => ({}),
|
GuestAuthGuard: async (_) => ({}),
|
||||||
encryptCallback: async (_, b) => b,
|
encryptCallback: async (_, b) => b,
|
||||||
decryptCallback: async (_, b) => b,
|
decryptCallback: async (_, b) => b,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
|
||||||
console.log({ appId })
|
console.log({ appId })
|
||||||
const app = await mainHandler.storage.applicationStorage.GetApplication(appId || "")
|
const app = await mainHandler.storage.applicationStorage.GetApplication(appId || "")
|
||||||
let nostrUser = await mainHandler.storage.applicationStorage.GetOrCreateNostrAppUser(app, pub || "")
|
let nostrUser = await mainHandler.storage.applicationStorage.GetOrCreateNostrAppUser(app, pub || "")
|
||||||
return { user_id: nostrUser.user.user_id }
|
return { user_id: nostrUser.user.user_id, app_user_id: nostrUser.identifier, app_id: appId || "" }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const nostr = new Nostr(nostrSettings, event => {
|
const nostr = new Nostr(nostrSettings, event => {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,12 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
return mainHandler.paymentManager.PayAddress(ctx.user_id, req)
|
return mainHandler.paymentManager.PayAddress(ctx.user_id, req)
|
||||||
},
|
},
|
||||||
NewInvoice: async (ctx, req) => {
|
NewInvoice: async (ctx, req) => {
|
||||||
return mainHandler.paymentManager.NewInvoice(ctx.user_id, req)
|
return mainHandler.applicationManager.AddAppUserInvoice(ctx.app_id, {
|
||||||
|
http_callback_url: "",
|
||||||
|
invoice_req: req,
|
||||||
|
payer_identifier: ctx.app_user_id,
|
||||||
|
receiver_identifier: ctx.app_user_id
|
||||||
|
})
|
||||||
},
|
},
|
||||||
DecodeInvoice: async (ctx, req) => {
|
DecodeInvoice: async (ctx, req) => {
|
||||||
return mainHandler.paymentManager.DecodeInvoice(req)
|
return mainHandler.paymentManager.DecodeInvoice(req)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue