Skip to content

Commit

Permalink
Merge pull request #3 from tosspayments/fix/regenerator-runtime
Browse files Browse the repository at this point in the history
fix: regenerator-runtime 을 사용하지 않도록 변경
  • Loading branch information
HyunSeob authored Mar 3, 2021
2 parents 70c54a4 + fc56da4 commit 8fec6dc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { TossPaymentsInstance } from '@tosspayments/sdk-types';

const SCRIPT_URL = 'https://js.tosspayments.com/v1';

let cachedPromise: Promise<any> | undefined;
let cachedPromise: Promise<TossPaymentsInstance> | undefined;

export async function loadTossPayments(clientKey: string): Promise<TossPaymentsInstance> {
export function loadTossPayments(clientKey: string): Promise<TossPaymentsInstance> {
// SSR 지원
if (typeof window === 'undefined') {
return {
return Promise.resolve({
requestPayment() {
throw new Error('[TossPayments.js] 서버에서는 실행할 수 없습니다.');
},
requestBillingAuth() {
throw new Error('[TossPayments.js] 서버에서는 실행할 수 없습니다.');
},
};
});
}

const selectedScript = document.querySelector(`script[src="${SCRIPT_URL}"]`);
Expand All @@ -24,7 +24,7 @@ export async function loadTossPayments(clientKey: string): Promise<TossPaymentsI
}

if (selectedScript != null && window.TossPayments !== undefined) {
return window.TossPayments(clientKey);
return Promise.resolve(window.TossPayments(clientKey));
}

const script = document.createElement('script');
Expand Down

0 comments on commit 8fec6dc

Please sign in to comment.