diff --git a/src/payment/agreement_payment_process.ts b/src/payment/agreement_payment_process.ts index b0d1b8232..8aeef8b30 100644 --- a/src/payment/agreement_payment_process.ts +++ b/src/payment/agreement_payment_process.ts @@ -185,19 +185,15 @@ export class AgreementPaymentProcess { private async rejectDebitNote(debitNote: DebitNote, rejectionReason: RejectionReason, rejectMessage: string) { try { await this.paymentModule.rejectDebitNote(debitNote, rejectMessage); - this.logger.warn(`DebitNote rejected`, { reason: rejectMessage }); } catch (error) { - this.logger.warn(`DebitNote rejected`, { reason: rejectMessage }); - // TODO: this endpoint is not implemented in Yagna, it always responds 501:NotImplemented. - // Until it is implemented by Yagna, it only logs as a warning - // const message = getMessageFromApiError(error); - // throw new GolemPaymentError( - // `Unable to reject debit note ${debitNote.id}. ${message}`, - // PaymentErrorCode.DebitNoteRejectionFailed, - // undefined, - // debitNote.provider, - // error, - // ); + const message = getMessageFromApiError(error); + throw new GolemPaymentError( + `Unable to reject debit note ${debitNote.id}. ${message}`, + PaymentErrorCode.DebitNoteRejectionFailed, + undefined, + debitNote.provider, + error, + ); } } @@ -285,17 +281,14 @@ export class AgreementPaymentProcess { await this.paymentModule.rejectInvoice(invoice, message); this.logger.warn(`Invoice rejected`, { reason: message }); } catch (error) { - this.logger.warn(`Invoice rejected`, { reason: message }); - // TODO: this endpoint is not implemented in Yagna, it always responds 501:NotImplemented. - // Until it is implemented by Yagna, it only logs as a warning - // const message = getMessageFromApiError(error); - // throw new GolemPaymentError( - // `Unable to reject invoice ${invoice.id} ${message}`, - // PaymentErrorCode.InvoiceRejectionFailed, - // undefined, - // invoice.provider, - // error, - // ); + const message = getMessageFromApiError(error); + throw new GolemPaymentError( + `Unable to reject invoice ${invoice.id} ${message}`, + PaymentErrorCode.InvoiceRejectionFailed, + undefined, + invoice.provider, + error, + ); } } diff --git a/src/payment/payment.module.ts b/src/payment/payment.module.ts index 0af322ae3..00ca5a7bf 100644 --- a/src/payment/payment.module.ts +++ b/src/payment/payment.module.ts @@ -15,6 +15,7 @@ import { PayerDetails } from "./PayerDetails"; import { AgreementPaymentProcess, PaymentProcessOptions } from "./agreement_payment_process"; import { Agreement } from "../market"; import * as EnvUtils from "../shared/utils/env"; +import { GolemInternalError } from "../shared/error/golem-error"; export interface PaymentModuleOptions { /** @@ -205,14 +206,20 @@ export class PaymentModuleImpl implements PaymentModule { async rejectDebitNote(debitNote: DebitNote, reason: string): Promise { this.logger.info("Rejecting debit note", { id: debitNote.id, reason }); - try { - const rejectedDebitNote = await this.paymentApi.rejectDebitNote(debitNote, reason); - this.events.emit("debitNoteRejected", rejectedDebitNote); - return rejectedDebitNote; - } catch (error) { - this.events.emit("errorRejectingDebitNote", debitNote, error); - throw error; - } + // TODO: this is not supported by PaymnetAdapter + const message = "Unable to send debitNote rejection to provider. This feature is not yet supported."; + this.logger.warn(message); + this.events.emit("errorRejectingDebitNote", debitNote, new GolemInternalError(message)); + return debitNote; + // this.logger.debug("Rejecting debit note", { id: debitNote.id, reason }); + // try { + // const rejectedDebitNote = await this.paymentApi.rejectDebitNote(debitNote, reason); + // this.events.emit("debitNoteRejected", rejectedDebitNote); + // return rejectedDebitNote; + // } catch (error) { + // this.events.emit("errorRejectingDebitNote", debitNote, error); + // throw error; + // } } /** diff --git a/src/shared/yagna/adapters/payment-api-adapter.ts b/src/shared/yagna/adapters/payment-api-adapter.ts index 69593bc27..869697ed3 100644 --- a/src/shared/yagna/adapters/payment-api-adapter.ts +++ b/src/shared/yagna/adapters/payment-api-adapter.ts @@ -134,13 +134,15 @@ export class PaymentApiAdapter implements IPaymentApi { } } - async rejectDebitNote(debitNote: DebitNote, reason: string): Promise { + async rejectDebitNote(debitNote: DebitNote): Promise { try { - await this.yagna.payment.rejectDebitNote(debitNote.id, { - rejectionReason: "BAD_SERVICE", - totalAmountAccepted: "0.00", - message: reason, - }); + // TODO: this endpoint is not implemented in Yagna, it always responds 501:NotImplemented. + // Reported in https://github.com/golemfactory/yagna/issues/1249 + // await this.yagna.payment.rejectDebitNote(debitNote.id, { + // rejectionReason: "BAD_SERVICE", + // totalAmountAccepted: "0.00", + // message: reason, + // }); return this.debitNoteRepo.getById(debitNote.id); } catch (error) { @@ -150,6 +152,7 @@ export class PaymentApiAdapter implements IPaymentApi { PaymentErrorCode.DebitNoteRejectionFailed, undefined, debitNote.provider, + error, ); } }