-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from 2024-Saphy/feat/SAPHY-33-product-favlist
[FEAT] : 구매 기능 추가, 상품 모델 수정
- Loading branch information
Showing
10 changed files
with
192 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,81 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/material.dart'; | ||
/* 아임포트 결제 모듈을 불러옵니다. */ | ||
import 'package:iamport_flutter/iamport_payment.dart'; | ||
/* 아임포트 결제 데이터 모델을 불러옵니다. */ | ||
import 'package:iamport_flutter/model/payment_data.dart'; | ||
import 'package:saphy/models/product.dart'; | ||
|
||
class Payment extends StatelessWidget { | ||
const Payment({super.key}); | ||
final Product product; | ||
const Payment({super.key, required this.product}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return IamportPayment( | ||
appBar: AppBar( | ||
title: const Text('아임포트 결제'), | ||
), | ||
/* 웹뷰 로딩 컴포넌트 */ | ||
initialChild: Container( | ||
child: Center( | ||
color: Colors.white, | ||
child: const Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Image.asset('assets/images/iamport-logo.png'), | ||
const Padding(padding: EdgeInsets.symmetric(vertical: 15)), | ||
const Text('잠시만 기다려주세요...', style: TextStyle(fontSize: 20)), | ||
Text('잠시만 기다려주세요...', style: TextStyle(fontSize: 20)), | ||
], | ||
), | ||
), | ||
), | ||
/* [필수입력] 가맹점 식별코드 */ | ||
userCode: 'iamport', | ||
/* [필수입력] 결제 데이터 */ | ||
userCode: 'imp16147707', | ||
data: PaymentData( | ||
pg: 'html5_inicis', // PG사 | ||
payMethod: 'card', // 결제수단 | ||
name: '아임포트 결제데이터 분석', // 주문명 | ||
merchantUid: 'mid_${DateTime.now().millisecondsSinceEpoch}', // 주문번호 | ||
amount: 39000, // 결제금액 | ||
buyerName: '홍길동', // 구매자 이름 | ||
buyerTel: '01012345678', // 구매자 연락처 | ||
buyerEmail: '[email protected]', // 구매자 이메일 | ||
buyerAddr: '서울시 강남구 신사동 661-16', // 구매자 주소 | ||
buyerPostcode: '06018', // 구매자 우편번호 | ||
appScheme: 'example', // 앱 URL scheme | ||
cardQuota: [2, 3] //결제창 UI 내 할부개월수 제한 | ||
), | ||
/* [필수입력] 콜백 함수 */ | ||
callback: (Map<String, String> result) { | ||
Navigator.pushReplacementNamed( | ||
context, | ||
'/result', | ||
arguments: result, | ||
); | ||
pg: 'tosspayments', | ||
payMethod: 'card', | ||
name: product.name, | ||
merchantUid: 'mid_${DateTime.now().millisecondsSinceEpoch}', | ||
amount: product.price, | ||
buyerName: '홍길동', | ||
buyerTel: '01012345678', | ||
buyerEmail: '[email protected]', | ||
buyerAddr: '서울시 강남구 신사동 661-16', | ||
buyerPostcode: '06018', | ||
appScheme: 'example', | ||
cardQuota: [2, 3]), | ||
callback: (Map<String, String> result) async { | ||
if (result['success'] == 'true') { | ||
String? impUid = result['imp_uid']; | ||
String? merchantUid = result['merchant_uid']; | ||
await verifyIamport(impUid, merchantUid, context); | ||
} else { | ||
String? errorMsg = result['error_msg']; | ||
print('결제 실패: $errorMsg'); | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('결제 실패: $errorMsg')), | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
Future<void> verifyIamport( | ||
String? impUid, String? itemId, BuildContext context) async { | ||
final dio = Dio(); | ||
|
||
if (impUid == null || itemId == null) return; | ||
|
||
final data = { | ||
'itemId': itemId, | ||
'impUid': impUid, | ||
}; | ||
|
||
try { | ||
final response = await dio.post( | ||
'https://saphy.site/payments', | ||
data: data, // 수정된 부분 | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
} else {} | ||
} catch (e) { | ||
print('Error: $e'); | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('서버와 연결할 수 없습니다.')), | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.