Skip to content

Commit

Permalink
Merge branch 'main' into testnet-rafiki-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymmmy committed Mar 24, 2023
2 parents c974e74 + c1cacb6 commit c92dfed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 19 additions & 10 deletions packages/backend/src/incoming-payment/incoming-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createIncomingPayment } from '../rafiki/request/incoming-payment.reques
import { TransactionModel } from '../transaction/transaction.model'
import { getUserIdFromRequest } from '../utils/getUserId'
import { findAccountById } from '../account/account.service'
import { Asset } from '../rafiki/generated/graphql'

export const createPayment = async (
req: Request,
Expand Down Expand Up @@ -38,21 +39,12 @@ export const createPayment = async (
throw new NotFoundException()
}

const response = await createIncomingPayment(
const transaction = await createIncomingPaymentTransactions(
paymentPointerId,
amount * 10 ** asset.scale,
asset
)

const transaction = await TransactionModel.query().insert({
paymentPointerId: existingPaymentPointer.id,
paymentId: response.id,
assetCode: asset.code,
value: amount * 10 ** asset.scale,
type: 'INCOMING',
status: 'PENDING'
})

return res.json({
success: true,
message: 'Incoming payment created',
Expand All @@ -62,3 +54,20 @@ export const createPayment = async (
next(e)
}
}

export async function createIncomingPaymentTransactions(
paymentPointerId: string,
amount: number,
asset: Asset
): Promise<TransactionModel> {
const response = await createIncomingPayment(paymentPointerId, amount, asset)

return TransactionModel.query().insert({
paymentPointerId: paymentPointerId,
paymentId: response.id,
assetCode: asset.code,
value: amount,
type: 'INCOMING',
status: 'PENDING'
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { findAccountById, getAccountBalance } from '../account/account.service'
import { createOutgoingPayment } from '../rafiki/request/outgoing-payment.request'
import { createQuote } from '../rafiki/request/quote.request'
import { Asset } from '../rafiki/generated/graphql'
import { createIncomingPayment } from '../rafiki/request/incoming-payment.request'
import { createIncomingPaymentTransactions } from '../incoming-payment/incoming-payment.service'

export const createPayment = async (
req: Request,
Expand Down Expand Up @@ -105,11 +105,11 @@ async function createReceiver(
throw new BadRequestException('Invalid payment pointer')
}

const response = await createIncomingPayment(
const response = await createIncomingPaymentTransactions(
existingPaymentPointer.id,
amount,
asset
)

return `${existingPaymentPointer.url}/incoming-payments/${response.id}`
return `${existingPaymentPointer.url}/incoming-payments/${response.paymentId}`
}

0 comments on commit c92dfed

Please sign in to comment.