Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
GRAPHQL_URL: http://happy-life-bank-backend:3001/graphql
WEBHOOK_SIGNATURE_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
WEBHOOK_SIGNATURE_VERSION: 1
USE_HTTP: true
depends_on:
- shared-database
healthcheck:
Expand Down
3 changes: 2 additions & 1 deletion packages/point-of-sale/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export const Config = {
webhookSignatureVersion: envInt('WEBHOOK_SIGNATURE_VERSION', 1),
webhookSignatureSecret: envString('WEBHOOK_SIGNATURE_SECRET'),
webhookTimeoutMs: envInt('WEBHOOK_TIMEOUT_MS', 30000),
incomingPaymentExpiryMs: envInt('INCOMING_PAYMENT_EXPIRY_MS', 10000)
incomingPaymentExpiryMs: envInt('INCOMING_PAYMENT_EXPIRY_MS', 10000),
useHttp: envBool('USE_HTTP', false)
}
22 changes: 15 additions & 7 deletions packages/point-of-sale/src/payments/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,30 @@ async function payment(
const body = ctx.request.body
let incomingPaymentId: string | undefined
try {
const senderWalletAddressUrl = new URL(body.senderWalletAddress)

if (deps.config.useHttp) {
senderWalletAddressUrl.protocol = 'http:'
}

const senderWalletAddress = await deps.paymentService.getWalletAddress(
body.senderWalletAddress.replace(/^https:/, 'http:')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had this for the local environment, putting this behind a flag

senderWalletAddressUrl.href
)

const receiverWalletAddressId =
await deps.paymentService.getWalletAddressIdByUrl(
body.receiverWalletAddress
)

const incomingPayment = await deps.paymentService.createIncomingPayment(
receiverWalletAddressId,
{
...body.amount,
const incomingPayment = await deps.paymentService.createIncomingPayment({
walletAddressId: receiverWalletAddressId,
incomingAmount: {
assetCode: body.amount.assetCode,
assetScale: body.amount.assetScale,
value: BigInt(body.amount.value)
}
)
},
senderWalletAddress: body.senderWalletAddress
})
const deferred = new Deferred<WebhookBody>()
webhookWaitMap.setWithExpiry(
incomingPayment.id,
Expand Down
28 changes: 16 additions & 12 deletions packages/point-of-sale/src/payments/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
GetWalletAddress,
GetWalletAddressVariables
} from '../graphql/generated/graphql'
import { FnWithDeps } from '../shared/types'
import { v4 } from 'uuid'
import { AxiosInstance, AxiosRequestConfig } from 'axios'
import { GET_WALLET_ADDRESS_BY_URL } from '../graphql/queries/getWalletAddress'
Expand Down Expand Up @@ -44,6 +43,12 @@ export type CreatedIncomingPayment = {
url: string
}

interface CreateIncomingPaymentArgs {
walletAddressId: string
incomingAmount: AmountInput
senderWalletAddress: string
}

type IncomingPaymentPage = Exclude<
Exclude<GetWalletAddress['walletAddressByUrl'], null>,
undefined
Expand All @@ -54,8 +59,7 @@ export type PaymentService = {
options: GetPaymentsQuery
) => Promise<IncomingPaymentPage>
createIncomingPayment: (
walletAddressId: string,
incomingAmount: AmountInput
args: CreateIncomingPaymentArgs
) => Promise<CreatedIncomingPayment>
getWalletAddress: (walletAddressUrl: string) => Promise<WalletAddress>
getWalletAddressIdByUrl: (walletAddressUrl: string) => Promise<string>
Expand All @@ -75,10 +79,8 @@ export function createPaymentService(
return {
getIncomingPayments: (options: GetPaymentsQuery) =>
getIncomingPayments(deps, options),
createIncomingPayment: (
walletAddressId: string,
incomingAmount: AmountInput
) => createIncomingPayment(deps, walletAddressId, incomingAmount),
createIncomingPayment: (args: CreateIncomingPaymentArgs) =>
createIncomingPayment(deps, args),
getWalletAddress: (walletAddressUrl: string) =>
getWalletAddress(deps, walletAddressUrl),
getWalletAddressIdByUrl: (walletAddressUrl: string) =>
Expand Down Expand Up @@ -107,10 +109,11 @@ async function getIncomingPayments(
return data?.walletAddressByUrl?.incomingPayments
}

const createIncomingPayment: FnWithDeps<
ServiceDependencies,
PaymentService['createIncomingPayment']
> = async (deps, walletAddressId, incomingAmount) => {
async function createIncomingPayment(
deps: ServiceDependencies,
args: CreateIncomingPaymentArgs
): Promise<CreatedIncomingPayment> {
const { walletAddressId, incomingAmount, senderWalletAddress } = args
const client = deps.apolloClient
const expiresAt = new Date(
Date.now() + deps.config.incomingPaymentExpiryMs
Expand All @@ -126,7 +129,8 @@ const createIncomingPayment: FnWithDeps<
incomingAmount,
idempotencyKey: v4(),
isCardPayment: true,
expiresAt
expiresAt,
senderWalletAddress
}
}
})
Expand Down
1 change: 1 addition & 0 deletions test/testenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ services:
WEBHOOK_SIGNATURE_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
WEBHOOK_SIGNATURE_VERSION: 1
WEBHOOK_TIMEOUT_MS: 10_000
USE_HTTP: true
depends_on:
- shared-database
Loading