Skip to content
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

feat: 1차 payple 연동 #128

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 5 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
VITE_KAKAO_JAVASCRIPT_KEY=02e0caae3e4116da61d734a06528cd86
VITE_KAKAO_RESTAPI_KEY=09bebf5106adf50d6a204a7ac2c22779
VITE_KAKAO_OPEN_URL=https://kauth.kakao.com/oauth/authorize?client_id={clientId}&redirect_uri={redirectUri}&response_type=code&prompt=login
VITE_SERVER_URL=//49.50.175.112:8080

VITE_SERVER_URL=http://49.50.175.112:8080

VITE_TEST_PATMENT_URL=https://democpay.payple.kr/php/auth.php
VITE_TEST_PAYMENT_REFERER=http://localhost:3000
Comment on lines +7 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 아마 .env.production에도 추가해야 리얼에서 환경변수 에러 안날것 같아요!

3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<body>
<div id="root"></div>
<div id="modal-root"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제이쿼리 슬프네요 ㅜㅜ

<script src="https://democpay.payple.kr/js/cpay.payple.1.0.1.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
75 changes: 69 additions & 6 deletions src/components/domain/matching/buttons/SuccessButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,77 @@
import React, { useState } from 'react';
import { Button } from '@/components/base';
import React from 'react';
import { getPartnerAuth } from '@/lib/api/payment';

declare global {
interface Window {
PaypleCpayAuthCheck: (params: any) => any;
MainBodyAction: (params: string) => void;
}
}

function SuccessButton() {
const handleClick = () => {
console.log('asd');
const [payResult, setPayResult] = useState({});

window.onpopstate = (e) => {
if (e) {
window.MainBodyAction('close');
}
};

const getPaymentResult = (res: any) => {
console.log(res, 'res');
if (res.PCD_PAY_RST === 'success') {
setPayResult({ ...res });
// 전달받은 데이터를 서버에 보내기
}
};

const handleClick = async () => {
const data = await getPartnerAuth();
if (data?.result !== 'success') {
console.error(data?.result_msg);
return;
}
const { AuthKey, return_url } = data;
console.log(data, 'res');
const payload = {
PCD_PAY_TYPE: 'card',
PCD_PAY_WORK: 'PAY',
/* 01 : 빌링키결제 */
PCD_CARD_VER: '01',

PCD_PAY_OID: 'test099942200156938',
PCD_PAYER_NO: 1234,
PCD_PAYER_NAME: '홍길동',
PCD_PAYER_HP: '01012345678',
PCD_PAYER_EMAIL: '[email protected]',
PCD_PAY_GOODS: '티셔츠',
PCD_PAY_TOTAL: 10000,
PCD_PAY_ISTAX: 'Y',
PCD_PAY_TAXTOTAL: 10,

/* 파트너 인증시 받은 값 입력 */
PCD_AUTH_KEY: AuthKey,
PCD_PAY_URL: return_url,
PCD_RST_URL: 'matching/meeting',
callbackFunction: getPaymentResult,
};

try {
// 가맹점 인증 api 응답 결과 success 시
const res = await window.PaypleCpayAuthCheck(payload);
return res;
} catch (e) {
console.error(e, 'requestPatmentAPI error');
}
};

return (
<Button onClick={handleClick} size="medium" variant={'kakao'}>
<strong>카카오페이</strong>로 간편하고 안전하게 결제
</Button>
<>
<Button id="payAction" onClick={handleClick} size="medium" variant={'kakao'}>
<strong>카카오페이</strong>로 간편하고 안전하게 결제
</Button>
</>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const apiClient = axios.create({
// baseURL: host,
withCredentials: true,
headers: {
Authorization: Cookies.get('AccessToken'),
Authorization: Cookies.get('AccessToken') ?? '',
},
});
export default apiClient;
12 changes: 12 additions & 0 deletions src/lib/api/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import apiClient from './index';
import { SERVER_URL } from '../constants';
import { PartnerAuth } from '@/types/payment';

export const getPartnerAuth = async (): Promise<PartnerAuth | undefined> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저번에 급하게 하느라 그냥 넣었는데 저희 api 다 이런식으로 묶어서 쓰는거로 바꿔야겠네요..!

try {
const res = await apiClient.post('/api/payment');
return res.data;
} catch (e) {
console.error(e);
}
};
2 changes: 2 additions & 0 deletions src/lib/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SERVER_URL = import.meta.env.VITE_SERVER_URL;
export const PAYMENT_URL = import.meta.env.VITE_TEST_PATMENT_URL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

2 changes: 1 addition & 1 deletion src/pages/MatchingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import styled from 'styled-components';

const MatchingPage = () => {
const TempData = { state: 'pay' };
const TempData = { state: 'success' };
return (
<>
<MatchingTemplete btnName={TempData.state} title={MatchingStateTitle(TempData.state)}>
Expand Down
11 changes: 11 additions & 0 deletions src/types/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface PartnerAuth {
server_name: string;
result: string;
result_msg: string;
cst_id: string;
custKey: string;
AuthKey: string;
PCD_PAY_HOST: string;
PCD_PAY_URL: string;
return_url: string;
}