-
Notifications
You must be signed in to change notification settings - Fork 18
[DEV-3957] partner fee #2491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
[DEV-3957] partner fee #2491
Changes from all commits
8d04a5e
f194fe1
a420c4c
bd5c211
0850d08
0920502
8a6fbe9
03039fc
ebefd9a
8032502
45f7893
1de9c62
7938283
4d5028c
7529dbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @typedef {import('typeorm').MigrationInterface} MigrationInterface | ||
| */ | ||
|
|
||
| /** | ||
| * @class | ||
| * @implements {MigrationInterface} | ||
| */ | ||
| module.exports = class AddBuyCryptoBuyFiatPlatformFeeAmount1761754328324 { | ||
| name = 'AddBuyCryptoBuyFiatPlatformFeeAmount1761754328324' | ||
|
|
||
| async up(queryRunner) { | ||
| await queryRunner.query(`ALTER TABLE "buy_fiat" ADD "partnerFeeAmount" float`); | ||
| await queryRunner.query(`ALTER TABLE "buy_crypto" ADD "partnerFeeAmount" float`); | ||
| } | ||
|
|
||
| async down(queryRunner) { | ||
| await queryRunner.query(`ALTER TABLE "buy_crypto" DROP COLUMN "partnerFeeAmount"`); | ||
| await queryRunner.query(`ALTER TABLE "buy_fiat" DROP COLUMN "partnerFeeAmount"`); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -922,13 +922,18 @@ export class BuyCryptoService { | |
|
|
||
| for (const ref of refs) { | ||
| const { volume: buyCryptoVolume, credit: buyCryptoCredit } = await this.getRefVolume(ref); | ||
| const { volume: buyCryptoPartnerVolume, credit: buyCryptoPartnerCredit } = await this.getPartnerFeeRefVolume(ref); | ||
| const { volume: buyFiatVolume, credit: buyFiatCredit } = await this.buyFiatService.getRefVolume(ref); | ||
| const { volume: buyFiatPartnerVolume, credit: buyFiatPartnerCredit } = | ||
| await this.buyFiatService.getPartnerFeeRefVolume(ref); | ||
| const { volume: manualVolume, credit: manualCredit } = await this.transactionService.getManualRefVolume(ref); | ||
|
|
||
| await this.userService.updateRefVolume( | ||
| ref, | ||
| buyCryptoVolume + buyFiatVolume + manualVolume, | ||
| buyCryptoCredit + buyFiatCredit + manualCredit, | ||
| buyCryptoPartnerVolume + buyFiatPartnerVolume, | ||
| buyCryptoPartnerCredit + buyFiatPartnerCredit, | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -945,6 +950,18 @@ export class BuyCryptoService { | |
| return { volume: volume ?? 0, credit: credit ?? 0 }; | ||
| } | ||
|
|
||
| async getPartnerFeeRefVolume(ref: string): Promise<{ volume: number; credit: number }> { | ||
| const { volume, credit } = await this.buyCryptoRepo | ||
| .createQueryBuilder('buyCrypto') | ||
| .select('SUM(amountInEur)', 'volume') | ||
| .addSelect('SUM(partnerFeeAmount * (amountInEur/amountInChf ))', 'credit') | ||
| .where('usedPartnerFeeRef = :ref', { ref }) | ||
|
Comment on lines
+956
to
+958
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .andWhere('amlCheck = :check', { check: CheckStatus.PASS }) | ||
| .getRawOne<{ volume: number; credit: number }>(); | ||
|
|
||
| return { volume: volume ?? 0, credit: credit ?? 0 }; | ||
| } | ||
|
|
||
| // Admin Support Tool methods | ||
|
|
||
| async getAllRefTransactions(refCodes: string[]): Promise<BuyCrypto[]> { | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need to update |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,13 @@ import { BankTx } from 'src/subdomains/supporting/bank-tx/bank-tx/entities/bank- | |
| import { IbanBankName } from 'src/subdomains/supporting/bank/bank/dto/bank.dto'; | ||
| import { MailTranslationKey } from 'src/subdomains/supporting/notification/factories/mail.factory'; | ||
| import { CryptoInput } from 'src/subdomains/supporting/payin/entities/crypto-input.entity'; | ||
| import { FeeDto, InternalFeeDto } from 'src/subdomains/supporting/payment/dto/fee.dto'; | ||
| import { InternalFeeDto } from 'src/subdomains/supporting/payment/dto/fee.dto'; | ||
| import { | ||
| CryptoPaymentMethod, | ||
| FiatPaymentMethod, | ||
| PaymentMethod, | ||
| } from 'src/subdomains/supporting/payment/dto/payment-method.enum'; | ||
| import { FeeType } from 'src/subdomains/supporting/payment/entities/fee.entity'; | ||
| import { SpecialExternalAccount } from 'src/subdomains/supporting/payment/entities/special-external-account.entity'; | ||
| import { Price, PriceStep } from 'src/subdomains/supporting/pricing/domain/entities/price'; | ||
| import { PriceCurrency } from 'src/subdomains/supporting/pricing/services/pricing.service'; | ||
|
|
@@ -87,6 +88,9 @@ export class BuyFiat extends IEntity { | |
| @Column({ length: 256, nullable: true }) | ||
| usedRef?: string; | ||
|
|
||
| @Column({ length: 256, nullable: true }) | ||
| usedPartnerFeeRef?: string; | ||
|
Comment on lines
+91
to
+92
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here? |
||
|
|
||
| @Column({ type: 'float', nullable: true }) | ||
| refProvision?: number; | ||
|
|
||
|
|
@@ -116,6 +120,9 @@ export class BuyFiat extends IEntity { | |
| @Column({ type: 'float', nullable: true }) | ||
| bankFeeAmount?: number; //inputAsset | ||
|
|
||
| @Column({ type: 'float', nullable: true }) | ||
| partnerFeeAmount?: number; //inputAsset | ||
|
|
||
| @Column({ type: 'float', nullable: true }) | ||
| percentFeeAmount?: number; //inputAsset | ||
|
|
||
|
|
@@ -283,11 +290,11 @@ export class BuyFiat extends IEntity { | |
| } | ||
|
|
||
| setFeeAndFiatReference( | ||
| fee: InternalFeeDto & FeeDto, | ||
| fee: InternalFeeDto, | ||
| minFeeAmountFiat: number, | ||
| totalFeeAmountChf: number, | ||
| ): UpdateResult<BuyFiat> { | ||
| const { usedRef, refProvision } = this.user.specifiedRef; | ||
| const partnerFee = fee.partner ? fee.fees.find((f) => f.type === FeeType.PARTNER) : undefined; | ||
| const inputReferenceAmountMinusFee = this.inputReferenceAmount - fee.total; | ||
|
|
||
| const update: Partial<BuyFiat> = | ||
|
|
@@ -303,10 +310,12 @@ export class BuyFiat extends IEntity { | |
| totalFeeAmountChf, | ||
| blockchainFee: fee.network, | ||
| bankFeeAmount: fee.bank, | ||
| partnerFeeAmount: fee.partner, | ||
| usedPartnerFeeRef: fee.partner ? partnerFee.wallet.owner.ref : undefined, | ||
| inputReferenceAmountMinusFee, | ||
| usedRef, | ||
| refProvision, | ||
| refFactor: !fee.payoutRefBonus || usedRef === Config.defaultRef ? 0 : 1, | ||
| usedRef: this.user.usedRef, | ||
| refProvision: this.user.refFeePercent, | ||
| refFactor: !fee.payoutRefBonus || this.user.usedRef === Config.defaultRef ? 0 : 1, | ||
| usedFees: fee.fees?.map((fee) => fee.id).join(';'), | ||
| }; | ||
|
|
||
|
|
@@ -469,6 +478,8 @@ export class BuyFiat extends IEntity { | |
| chargebackAllowedDateUser: null, | ||
| chargebackAmount: null, | ||
| chargebackAllowedBy: null, | ||
| partnerFeeAmount: null, | ||
| usedPartnerFeeRef: null, | ||
| priceSteps: null, | ||
| priceDefinitionAllowedDate: null, | ||
| usedFees: null, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -553,13 +553,18 @@ export class BuyFiatService { | |
|
|
||
| for (const ref of refs) { | ||
| const { volume: buyFiatVolume, credit: buyFiatCredit } = await this.getRefVolume(ref); | ||
| const { volume: buyFiatPartnerVolume, credit: buyFiatPartnerCredit } = await this.getPartnerFeeRefVolume(ref); | ||
| const { volume: buyCryptoVolume, credit: buyCryptoCredit } = await this.buyCryptoService.getRefVolume(ref); | ||
| const { volume: buyCryptoPartnerVolume, credit: buyCryptoPartnerCredit } = | ||
| await this.buyCryptoService.getPartnerFeeRefVolume(ref); | ||
| const { volume: manualVolume, credit: manualCredit } = await this.transactionService.getManualRefVolume(ref); | ||
|
|
||
| await this.userService.updateRefVolume( | ||
| ref, | ||
| buyFiatVolume + buyCryptoVolume + manualVolume, | ||
| buyFiatCredit + buyCryptoCredit + manualCredit, | ||
| buyFiatPartnerVolume + buyCryptoPartnerVolume, | ||
| buyFiatPartnerCredit + buyCryptoPartnerCredit, | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -576,6 +581,18 @@ export class BuyFiatService { | |
| return { volume: volume ?? 0, credit: credit ?? 0 }; | ||
| } | ||
|
|
||
| async getPartnerFeeRefVolume(ref: string): Promise<{ volume: number; credit: number }> { | ||
| const { volume, credit } = await this.buyFiatRepo | ||
| .createQueryBuilder('buyFiat') | ||
| .select('SUM(amountInEur)', 'volume') | ||
| .addSelect('SUM(partnerFeeAmount * (amountInEur/amountInChf ))', 'credit') | ||
| .where('usedPartnerFeeRef = :ref', { ref }) | ||
|
Comment on lines
+587
to
+589
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .andWhere('amlCheck = :check', { check: CheckStatus.PASS }) | ||
| .getRawOne<{ volume: number; credit: number }>(); | ||
|
|
||
| return { volume: volume ?? 0, credit: credit ?? 0 }; | ||
| } | ||
|
|
||
| // Statistics | ||
|
|
||
| async getTransactions(dateFrom: Date = new Date(0), dateTo: Date = new Date()): Promise<TransactionDetailsDto[]> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usedPartnerRef?