flutter_snapmint_sdk 0.0.1 flutter_snapmint_sdk: ^0.0.1 copied to clipboard
Snapmint Sdk
example/lib/main.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_snapmint_sdk/src/SnapmintButtonGoldWidget.dart';
import 'package:flutter_snapmint_sdk/src/SnapmintButtonWidget.dart';
import 'package:flutter_snapmint_sdk/flutter_snapmint_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
late Map<String, dynamic> _response;
final _flutterSnapmintSdkPlugin = FlutterSnapmintSdk();
@override
void initState() {
super.initState();
//initPlatformState();
}
Future<void> openSnapMintModule() async {
Map<String, dynamic> responseData;
try {
String jsonString = getJsonString();
String nativeData =
await _flutterSnapmintSdkPlugin.openSnapmintModule(jsonString) ??
{}.toString();
print("TEST! $nativeData");
responseData = jsonDecode(nativeData);
print(
"TEST! data is code => ${responseData["statusCode"]} message is => ${responseData["responseMsg"]}");
} on Exception {
responseData = <String, dynamic>{};
print("TEST! Exception handled");
}
if (!mounted) return;
setState(() {
_response = responseData;
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _flutterSnapmintSdkPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.only(left: 20, right: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//Text('Running on: $_platformVersion\n'),
ElevatedButton(
onPressed: () {
openSnapMintModule();
},
child: const Text(
"Open SDK",
style: TextStyle(
fontSize: 14,
color: Colors.blue,
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
)),
const SizedBox(
height: 10,
),
SnapmintButtonWidget(
amount: 100.0.toString(),
jsonUrl:
'https://preemi.snapmint.com/assets/merchant/1616/snap_ketch.json',
fontFamily: const TextStyle(fontFamily: 'Roboto'),
disablePopup: false,
),
const SizedBox(
height: 10,
),
SnapmintButtonGoldWidget(
amount: 8355,
goldAmount: 2997,
jsonUrl:
'https://preemi.snapmint.com/assets/merchant/1616/snap_ketch.json',
fontFamilyStyle: const TextStyle(fontFamily: 'Roboto'),
disablePopup: false,
disableSecondLine: false,
)
],
),
),
],
)),
),
);
}
String getJsonString() {
Map<String, dynamic> finalData = {
"merchant_key": "cQ_kvgB0",
"merchant_token": "UOYY0R_n",
"merchant_id": 1456,
"merchant_confirmation_url":
"https://services-pp-customer.melorralabsinfra.com/api/snapmint/snapmint_order/order_success/",
"merchant_failure_url":
"https://services-pp-customer.melorralabsinfra.com/api/snapmint/snapmint_order/order_failure/",
"mobile": "9004559365",
"store_id": 1,
"order_id":
"MELORRA-${DateTime.now().millisecondsSinceEpoch}", // Random can be DateTime
"order_value": 75163,
"udf1": 1.91,
"udf2": 7147,
"full_name": "test",
"email": "khem.raj@snapmint.com",
"billing_address_line1": "test",
"billing_zip": "560037",
"shipping_address_line1": "test",
"shipping_zip": "560037",
"deviceType": "android",
"products": [
{
"sku": "227285",
"name": "Bold Show Diamond Earrings",
"quantity": 1,
"unit_price": 75163,
"udf2": 7147,
"udf1": "1.910 g"
}
]
};
// Create the full JSON structure
Map<String, dynamic> jsonData = {
"finalData": finalData,
"base_url": "https://qaapi.snapmint.com/v1/public/s2s_online_checkout",
"suc_url":
"https://services-pp-customer.melorralabsinfra.com/api/snapmint/snapmint_order/order_success/",
"fail_url":
"https://services-pp-customer.melorralabsinfra.com/api/snapmint/snapmint_order/order_failure/",
};
// Convert the Map to a JSON string
String jsonString = jsonEncode(jsonData);
print(jsonString);
return jsonString; // Output the JSON string
}
}