Skip to content

PM-1078 - use finance api #81

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions src/domain/Challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import ChallengeScheduler from "../util/ChallengeScheduler";
import { BAValidation, lockConsumeAmount } from "../api/BillingAccount";
import { ChallengeEstimator } from "../util/ChallengeEstimator";
import { V5_TRACK_IDS_TO_NAMES, V5_TYPE_IDS_TO_NAMES } from "../common/ConversionMap";
import WalletApi, { PaymentDetail } from "../util/WalletApi";
import FinanceApi, { PaymentDetail } from "../util/FinanceApi";
import { getChallengeResources, loadInformixSubmissions } from "../api/v5Api";
import m2mToken from "../helpers/MachineToMachineToken";

Expand Down Expand Up @@ -926,7 +926,7 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
);

// Check if payment already exists
const existingPayments = await WalletApi.getPaymentsByChallengeId(challengeId, token);
const existingPayments = await FinanceApi.getPaymentsByChallengeId(challengeId, token);
if (existingPayments.length > 0) {
console.log(`Payments already exist for challenge ${challengeId}, skipping payment generation`);
return 0;
Expand Down Expand Up @@ -992,7 +992,7 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
}

console.log("Generate payment with payload", payload);
await WalletApi.createPayment(payload, token);
await FinanceApi.createPayment(payload, token);
}

return totalAmount;
Expand Down
10 changes: 5 additions & 5 deletions src/util/WalletApi.ts → src/util/FinanceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export interface PaymentPayload {
}

// TODO: Move this to a processor that handles challenge completion events from Harmony
class WalletApi {
class FinanceApi {
private static readonly BASE_URL =
(process.env.TOPCODER_API_ENDPOINT ?? "https://api.topcoder-dev.com/v5") + "/payments";
(process.env.TOPCODER_API_ENDPOINT ?? "https://api.topcoder-dev.com/v5") + "/finance";

async createPayment(
payload: PaymentPayload,
Expand All @@ -40,7 +40,7 @@ class WalletApi {

try {
console.log(payload.externalId, "Creating payment. Attempt", attempts, payload);
const response = await axios.post(WalletApi.BASE_URL + "/winnings", payload, config);
const response = await axios.post(FinanceApi.BASE_URL + "/winnings", payload, config);
console.log("Payment created", response.data);
return response;
} catch (error) {
Expand Down Expand Up @@ -69,7 +69,7 @@ class WalletApi {
};

try {
const response = await axios.post(WalletApi.BASE_URL + "/winnings/list", payload, config);
const response = await axios.post(FinanceApi.BASE_URL + "/winnings/list", payload, config);
return response.data.data;
} catch (err) {
return [];
Expand All @@ -78,4 +78,4 @@ class WalletApi {

}

export default new WalletApi();
export default new FinanceApi();