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 : Product Purchase Widget #41

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
102 changes: 102 additions & 0 deletions lib/screens/purchase/payment_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import 'package:flutter/material.dart';
import 'package:tosspayments_widget_sdk_flutter/model/payment_info.dart';
import 'package:tosspayments_widget_sdk_flutter/model/payment_widget_options.dart';
import 'package:tosspayments_widget_sdk_flutter/payment_widget.dart';
import 'package:tosspayments_widget_sdk_flutter/widgets/agreement.dart';
import 'package:tosspayments_widget_sdk_flutter/widgets/payment_method.dart';

class PaymentPage extends StatefulWidget {
const PaymentPage({super.key});
@override
State<PaymentPage> createState() {
return _PaymentPageState();
}
}

class _PaymentPageState extends State<PaymentPage> {
late PaymentWidget _paymentWidget;
PaymentMethodWidgetControl? _paymentMethodWidgetControl;
AgreementWidgetControl? _agreementWidgetControl;
@override
void initState() {
super.initState();
_paymentWidget = PaymentWidget(
clientKey: "test_gck_docs_Ovk5rk1EwkEbP0W43n07xlzm",
customerKey: "ynygwDdyclboRnSIgyNqw",
// 결제위젯에 브랜드페이 추가하기
// paymentWidgetOptions: PaymentWidgetOptions(brandPayOption: BrandPayOption("리다이렉트 URL")) // Access Token 발급에 사용되는 리다이렉트 URL
);
_paymentWidget
.renderPaymentMethods(
selector: 'methods',
amount: Amount(value: 300, currency: Currency.KRW, country: "KR"),
options: RenderPaymentMethodsOptions(variantKey: "DEFAULT"))
.then((control) {
_paymentMethodWidgetControl = control;
});
_paymentWidget.renderAgreement(selector: 'agreement').then((control) {
_agreementWidgetControl = control;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Expanded(
child: ListView(
children: [
PaymentMethodWidget(
paymentWidget: _paymentWidget,
selector: 'methods',
),
AgreementWidget(
paymentWidget: _paymentWidget, selector: 'agreement'),
ElevatedButton(
onPressed: () async {
final paymentResult =
await _paymentWidget.requestPayment(
paymentInfo: const PaymentInfo(
orderId: '_t1fPAFA2Lm84f08Gkw2x',
orderName: '토스 티셔츠 외 2건'));
if (paymentResult.success != null) {
// 결제 성공 처리
} else if (paymentResult.fail != null) {
// 결제 실패 처리
}
},
child: const Text('결제하기')),
// ElevatedButton(
// onPressed: () async {
// final selectedPaymentMethod =
// await _paymentMethodWidgetControl
// ?.getSelectedPaymentMethod();
// print(
// '${selectedPaymentMethod?.method} ${selectedPaymentMethod?.easyPay?.provider ?? ''}');
// },
// child: const Text('선택한 결제수단 출력')),
// ElevatedButton(
// onPressed: () async {
// final agreementStatus =
// await _agreementWidgetControl?.getAgreementStatus();
// print('${agreementStatus?.agreedRequiredTerms}');
// },
// child: const Text('약관 동의 상태 출력')),
// ElevatedButton(
// onPressed: () async {
// await _paymentMethodWidgetControl?.updateAmount(
// amount: 300);
// print('결제 금액이 300원으로 변경되었습니다.');
// },
// child: const Text('결제 금액 변경'))
],
),
)
],
),
),
);
}
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import Foundation

import firebase_auth
import firebase_core
import flutter_inappwebview_macos
import flutter_secure_storage_macos
import google_sign_in_ios
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies:
simple_shadow: ^0.3.1
toggle_list: ^0.3.1
carousel_slider: ^5.0.0
tosspayments_widget_sdk_flutter: ^2.0.6

dev_dependencies:
flutter_lints: ^4.0.0
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <firebase_auth/firebase_auth_plugin_c_api.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FirebaseAuthPluginCApiRegisterWithRegistrar(
Expand All @@ -17,4 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
firebase_auth
firebase_core
flutter_secure_storage_windows
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
Loading