3. 배송 및 결제 정보 전달
const PG_CODE = process.env.PORTONE_PG_CODE || "";
export default class PaymentService {
instance = Reflect.get(window, "IMP");
async requestPayment({
//
merchantId,
product,
buyer,
}: {
merchantId: string,
product: Product,
buyer?: Buyer,
}): Promise<{
merchantId: string,
transactionId: string,
}> {
return new Promise((resolve, reject) => {
// 콜백이다. await이 아닌 Promsie가 쓰임. 패턴처럼 외우면 된다함.
this.instance.request_pay(
{
pg: PG_CODE,
pay_method: "card",
merchant_uid: merchantId,
name: product.name,
amount: product.price,
buyer_email: buyer?.email,
buyer_name: buyer?.name,
buyer_tel: buyer?.phoneNumber,
buyer_addr: buyer?.address,
buyer_postcode: buyer?.postalCode,
},
(response: PaymentResponse) => {
if (response.success) {
resolve({
merchantId: response.merchant_uid,
transactionId: response.imp_uid ?? "",
});
} else {
reject(Error(response.error_msg));
}
}
);
});
}
}
export const paymentService = new PaymentService();정리를 좀 해보자면,..
프로세스
Last updated