Skip to content

Commit

Permalink
refactor: disabled rejection debit note in adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Jun 11, 2024
1 parent 2f53853 commit 5983a9e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
39 changes: 16 additions & 23 deletions src/payment/agreement_payment_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

Expand Down Expand Up @@ -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,
);
}
}

Expand Down
23 changes: 15 additions & 8 deletions src/payment/payment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -205,14 +206,20 @@ export class PaymentModuleImpl implements PaymentModule {

async rejectDebitNote(debitNote: DebitNote, reason: string): Promise<DebitNote> {
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;
// }
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/shared/yagna/adapters/payment-api-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ export class PaymentApiAdapter implements IPaymentApi {
}
}

async rejectDebitNote(debitNote: DebitNote, reason: string): Promise<DebitNote> {
async rejectDebitNote(debitNote: DebitNote): Promise<DebitNote> {
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) {
Expand All @@ -150,6 +152,7 @@ export class PaymentApiAdapter implements IPaymentApi {
PaymentErrorCode.DebitNoteRejectionFailed,
undefined,
debitNote.provider,
error,
);
}
}
Expand Down

0 comments on commit 5983a9e

Please sign in to comment.