Skip to content

Commit

Permalink
Switch to changed endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed May 21, 2024
1 parent a054f32 commit 1b42679
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/server/env/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RELAY_ENDPOINT=http://localhost:7070
RELAY_ACCESS_KEY=0x2c93e943c0d7f6f1a42f53e116c52c40fe5c1b428506dc04b290f2a77580a342

SMS_ENDPOINT=http://127.0.0.1:3300
SMS_ACCESS_KEY=16353ae904e96ac98e02ca5902a1f543e3d3f4a394cd94bd504d2d4a2117b065
SMS_ACCESS_KEY=0x16353ae904e96ac98e02ca5902a1f543e3d3f4a394cd94bd504d2d4a2117b065
SMS_SENDER=01098351803
TOKEN_SYMBOL=the9
TOKEN_SYMBOL=LYT
MESSAGE_ENABLE=false
32 changes: 16 additions & 16 deletions packages/server/src/service/relay/RelayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export class RelayClient {

public async getBalanceOfAccount(account: string): Promise<IRelayBalance | undefined> {
const url = URI(this.config.setting.relayEndpoint)
.directory("/v1/payment/user")
.filename("balance")
.addQuery("account", account)
.directory("/v1/ledger/balance/account")
.filename(account)
.toString();
try {
const response = await this.client.get(url);
Expand All @@ -56,19 +55,21 @@ export class RelayClient {
return {
account: response.data.data.account,
loyaltyType: response.data.data.loyaltyType,
balance: BigNumber.from(response.data.data.balance),
balance:
response.data.data.loyaltyType === 0
? BigNumber.from(response.data.data.point.balance)
: BigNumber.from(response.data.data.token.balance),
};
} catch (error) {
logger.error(`릴레이서버에서 지갑주소의 잔고를 조회하는데 실패했습니다.-[${error}]`);
return undefined;
}
}

public async getBalanceOfPhone(phone: string): Promise<IRelayBalance | undefined> {
public async getBalanceOfPhoneHash(phoneHash: string): Promise<IRelayBalance | undefined> {
const url = URI(this.config.setting.relayEndpoint)
.directory("/v1/payment/phone")
.filename("balance")
.addQuery("phone", phone)
.directory("/v1/ledger/balance/phoneHash")
.filename(phoneHash)
.toString();
try {
const response = await this.client.get(url);
Expand All @@ -81,7 +82,10 @@ export class RelayClient {
return {
account: response.data.data.account,
loyaltyType: response.data.data.loyaltyType,
balance: BigNumber.from(response.data.data.balance),
balance:
response.data.data.loyaltyType === 0
? BigNumber.from(response.data.data.point.balance)
: BigNumber.from(response.data.data.token.balance),
};
} catch (error) {
logger.error(`릴레이서버에서 잔고를 조회하는데 실패했습니다.-[${error}]`);
Expand All @@ -90,8 +94,8 @@ export class RelayClient {

public async convertCurrency(amount: BigNumber, from: string, to: string): Promise<BigNumber | undefined> {
const url = URI(this.config.setting.relayEndpoint)
.directory("/v1/payment/convert")
.filename("currency")
.directory("/v1/currency")
.filename("convert")
.addQuery("amount", amount.toString())
.addQuery("from", from)
.addQuery("to", to)
Expand All @@ -111,11 +115,7 @@ export class RelayClient {
}

public async getShopInfo(shopId: string): Promise<IShopInfo | undefined> {
const url = URI(this.config.setting.relayEndpoint)
.directory("/v1/payment/shop")
.filename("info")
.addQuery("shopId", shopId)
.toString();
const url = URI(this.config.setting.relayEndpoint).directory("/v1/shop/info").filename(shopId).toString();
try {
const response = await this.client.get(url);
if (response.data.code !== 0) {
Expand Down
34 changes: 19 additions & 15 deletions packages/server/src/service/routers/StorePurchaseRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ export class StorePurchaseRouter {
if (loyaltyPoint !== undefined) {
if (userAccount !== AddressZero) {
const result = await client.getBalanceOfAccount(userAccount);
console.log("client.getBalanceOfAccount(userAccount)", result);

if (result !== undefined) {
let loyalty: BigNumber = loyaltyPoint;
if (result.loyaltyType === 1) {
Expand Down Expand Up @@ -334,7 +336,9 @@ export class StorePurchaseRouter {
};
}
} else if (userPhone !== "") {
const result = await client.getBalanceOfPhone(userPhoneHash);
const result = await client.getBalanceOfPhoneHash(userPhoneHash);
console.log("client.getBalanceOfPhoneHash(userPhoneHash)", result);

if (result !== undefined) {
if (result.account !== undefined) {
userAccount = result.account;
Expand Down Expand Up @@ -393,17 +397,14 @@ export class StorePurchaseRouter {
);
const currentBalance = new BOACoin(BigNumber.from(loyaltyResponse.account.currentBalance));
const contents =
`결제가 완료되는 8일 뒤에 ${loyaltyAmount.toDisplayString(
true,
precision
)} ${unit} 적립됩니다.` +
`현재 잔액은 ${currentBalance.toDisplayString(
true,
precision
)} ${unit} 입니다. 토큰은 시세에 따라서 다소 차이가 생길 수 있습니다.`;
`Time to be provided: ${new Date(
new Date().getTime() + waiting * 1000
).toUTCString()}\n` +
`Amount to be provided: ${loyaltyAmount.toDisplayString(true, precision)} ${unit}\n` +
`Current balance: ${currentBalance.toDisplayString(true, precision)} ${unit}`;
if (this._config.setting.messageEnable)
await client.sendPushMessage(userAccount, 0, "로열티 적립", contents, "provide");
logger.info("[NOTIFICATION]" + contents);
await client.sendPushMessage(userAccount, 0, "Loyalty provided", contents, "provide");
logger.info(`[NOTIFICATION] ${userAccount} ${contents}`);
} else {
const unit = "POINT";
const precision = 0;
Expand All @@ -412,13 +413,16 @@ export class StorePurchaseRouter {
);
const currentBalance = new BOACoin(BigNumber.from(loyaltyResponse.account.currentBalance));
const contents =
`결제가 완료되는 8일 뒤에 ${loyaltyToBeProvided.toDisplayString(
`Time to be provided: ${new Date(
new Date().getTime() + waiting * 1000
).toUTCString()}\n` +
`Amount to be provided: ${loyaltyToBeProvided.toDisplayString(
true,
precision
)} ${unit}가 적립됩니다.\n` +
`현재 잔액은 ${currentBalance.toDisplayString(true, precision)} ${unit} 입니다.`;
)} ${unit}\n` +
`Current balance: ${currentBalance.toDisplayString(true, precision)} ${unit}`;
if (this._config.setting.messageEnable) await client.sendSMSMessage(contents, userPhone);
logger.info("[SMS]" + contents);
logger.info(`[SMS] ${userPhone} ${contents}`);
}
}

Expand Down

0 comments on commit 1b42679

Please sign in to comment.