Skip to content
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
196 changes: 98 additions & 98 deletions example/lib/donut_counter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ class _DonutCounterScreenState extends State<DonutCounterScreen> {

Payment payment = await _squareMobilePaymentsSdkPlugin.paymentManager
.startPayment(
PaymentParameters(
processingMode: 2,
amountMoney:
Money(amount: amount, currencyCode: CurrencyCode.eur),
idempotencyKey: idempotencyKey),
PromptParameters(
additionalPaymentMethods: List.empty(),
mode: PromptMode.defaultMode));
PaymentParameters(
processingMode: 2,
amountMoney: Money(
amount: amount,
currencyCode: CurrencyCode.eur,
),
idempotencyKey: idempotencyKey,
),
PromptParameters(
additionalPaymentMethods: List.empty(),
mode: PromptMode.defaultMode,
),
);
if (context.mounted) {
showPaymentDialog(context, payment);
}
Expand Down Expand Up @@ -142,108 +147,103 @@ class _DonutCounterScreenState extends State<DonutCounterScreen> {
showReader();
}
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
toolbarHeight: 50,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
showSettings();
},
style: TextButton.styleFrom(
backgroundColor: Colors.grey.shade200,
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
toolbarHeight: 50,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
showSettings();
},
style: TextButton.styleFrom(
backgroundColor: Colors.grey.shade200,
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: const Text(
'Settings',
style: TextStyle(
color: Colors.blue,
fontSize: 16,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text(
'Settings',
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/permissions');
},
style: TextButton.styleFrom(
backgroundColor: Colors.grey.shade200,
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/permissions');
},
style: TextButton.styleFrom(
backgroundColor: Colors.grey.shade200,
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: const Text(
'Permissions',
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
],
),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SvgPicture.asset(
'assets/donut.svg',
width: 250.0, // Adjust size as needed
height: 250.0,
),
),
const SizedBox(height: 40),
const Text(
'Donut Counter',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: isAuthorized ? () => _onBuy(context, amount) : null,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple.shade200,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text(
'Permissions',
child: Text(
"Buy for \$${(amount / 100).toStringAsFixed(2)}",
style: TextStyle(
color: Colors.blue,
fontSize: 16,
color: isAuthorized ? Colors.black : Colors.grey,
fontSize: 18,
),
),
),
],
),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SvgPicture.asset(
'assets/donut.svg',
width: 250.0, // Adjust size as needed
height: 250.0,
),
),
const SizedBox(height: 40),
),
const SizedBox(height: 20),
const SizedBox(height: 20),
if (!isAuthorized)
const Text(
'Donut Counter',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
"Device not authorized. Open permissions to authorize.",
style: TextStyle(color: Color.fromARGB(255, 187, 122, 24)),
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed:
isAuthorized ? () => _onBuy(context, amount) : null,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple.shade200,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: Text(
"Buy for \$${(amount / 100).toStringAsFixed(2)}",
style: TextStyle(
color: isAuthorized ? Colors.black : Colors.grey,
fontSize: 18,
),
),
),
),
const SizedBox(height: 20),
const SizedBox(height: 20),
if (!isAuthorized)
const Text(
"Device not authorized. Open permissions to authorize.",
style: TextStyle(color: Color.fromARGB(255, 187, 122, 24)),
)
],
),
));
],
),
),
);
}
}
34 changes: 17 additions & 17 deletions ios/Classes/Mappers/PaymentMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,63 @@ public class PaymentMapper {
else {
fatalError("Error: Missing or invalid required payment parameters")
}

// Convert the currency string to the appropriate type
let currency = getCurrency(from: currencyCode)

// Create the amountMoney object
let money = Money(amount: amount, currency: currency)

// Initialize PaymentParameters with required fields
var paymentParams = PaymentParameters(
idempotencyKey: idempotencyKey,
amountMoney: money,
processingMode: ProcessingMode(rawValue: processingMode)!
)

// Optional: appFeeMoney
if let appFeeMoney = paymentParameters["appFeeMoney"] as? [String: Any],
let appFeeAmount = appFeeMoney["amount"] as? UInt,
let appFeeCurrencyCode = appFeeMoney["currencyCode"] as? String {
let appFeeAmount = appFeeMoney["amount"] as? UInt,
let appFeeCurrencyCode = appFeeMoney["currencyCode"] as? String {

let appFeeCurrency = getCurrency(from: appFeeCurrencyCode)
let appFee = Money(amount: appFeeAmount, currency: appFeeCurrency)
paymentParams.appFeeMoney = appFee
}

// Optional: tipMoney
if let tipMoney = paymentParameters["tipMoney"] as? [String: Any],
let tipAmount = tipMoney["amount"] as? UInt,
let tipCurrencyCode = tipMoney["currencyCode"] as? String {
let tipAmount = tipMoney["amount"] as? UInt,
let tipCurrencyCode = tipMoney["currencyCode"] as? String {

let tipCurrency = getCurrency(from: tipCurrencyCode)
let tip = Money(amount: tipAmount, currency: tipCurrency)
paymentParams.tipMoney = tip
}

// Optional: referenceId
if let referenceId = paymentParameters["referenceId"] as? String {
paymentParams.referenceID = referenceId
}

// Optional: note
if let note = paymentParameters["note"] as? String {
paymentParams.note = note
}

// Optional: orderId
if let orderId = paymentParameters["orderId"] as? String {
paymentParams.orderID = orderId
}

// Optional: autocomplete
if let autocomplete = paymentParameters["autocomplete"] as? Bool {
paymentParams.autocomplete = autocomplete
}

return paymentParams
}


static func getPromptParameters(promptParameters: [String: Any]) -> PromptParameters {
return PromptParameters(mode: .default, additionalMethods: .all)
Expand Down
Loading